Skip to content

Commit

Permalink
fixes in converting string/parse
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnath committed Mar 5, 2024
1 parent bd285a1 commit 6e094ac
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 43 deletions.
21 changes: 13 additions & 8 deletions src/github/user/user.shared-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ export const ensureElements = async (elements, args) => {
}
if (args?.repos) {
let reps = [];
try {
if (typeof args.repos === 'string') {
reps = parseify(args.repos);
await expect(elements.repos).toHaveLength(reps.length);
} catch (error) {
await expect(elements.repos).toHaveLength(0);
} else if (Array.isArray(args.repos)){
reps = args.repos;
}
await expect(elements.repos).toHaveLength(reps.length);
} else {
await expect(elements.repos).toHaveLength(0);
}
Expand Down Expand Up @@ -122,11 +122,16 @@ export const getExpectedScreenText = (args) => {
expected.push(`following: ${args.following}`);
}
}
if (args.repositories) {
const repos = args.repositories;
if (Array.isArray(repos)) {
if (args?.repos) {
let reps = [];
if (typeof args.repos === 'string') {
reps = parseify(args.repos);
} else if (Array.isArray(args.repos)){
reps = args.repos;
}
if (Array.isArray(reps)) {
expected.push('banner, Pinned repositories');
repos.forEach((repo) => {
reps.forEach((repo) => {
const repoExpected = getRepoScreenText(repo);
expected.push(...repoExpected);
});
Expand Down
62 changes: 27 additions & 35 deletions src/github/user/user.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default {
delete args.repos;
}
let attributes = attrGen({...args});
args.repos = repos;
if (repos) {
console.log('repos', repos)
if (typeof repos !== 'string') repos = stringify(repos);
Expand Down Expand Up @@ -51,8 +52,6 @@ export const UserRepos = {
play: async ({ args, canvasElement, step }) => {
console.log('UserRepos = canva', canvasElement.closest('body').innerHTML)
const elements = await getElements(canvasElement);
console.log('UserRepos = elms', elements.container.innerHTML)
args.repositories = [{ ...parseFetchedRepo(repoProfileComponents), user_login: userScottnath.login }, parseFetchedRepo(repoStorydocker)];
await ensureElements(elements, args);
await ensureScreenRead(elements, args);
}
Expand Down Expand Up @@ -96,39 +95,32 @@ export const Fetch = {
}
};

// export const FetchOverides = {
// args: {
// login: userScottnath.login,
// fetch: true,
// name: "Meowy McMeowerstein",
// bio: "Spending time purring and sleepin",
// avatar_url: 'cat-square.jpeg',
// followers: "500000",
// following: "2980",
// repos: stringify([{"full_name":"scottnath/profile-components","description":"Cool thing, does stuff","language":"HTML"}])
// },
// parameters: {
// fetchMock: {
// mocks: [
// {
// response: generateMockResponse(userScottnath, 'users'),
// }
// ]
// }
// // mockData: [
// // generateMockResponse(userScottnath, 'users'),
// // ]
// },
// play: async ({ args, canvasElement, step }) => {
// const elements = await getElements(canvasElement);
// const argsAfterFetch = {
// ...parseFetchedUser({...userScottnath}),
// ...args,
// };
// await ensureElements(elements, argsAfterFetch);
// await ensureScreenRead(elements, argsAfterFetch);
// }
// }
export const FetchOverides = {
args: {
login: userScottnath.login,
fetch: true,
name: "Meowy McMeowerstein",
bio: "Spending time purring and sleepin",
avatar_url: 'cat-square.jpeg',
followers: "500000",
following: "2980",
repos: stringify([{"full_name":"scottnath/profile-components","description":"Cool thing, does stuff","language":"HTML"}])
},
parameters: {
mockData: [
generateMockResponse(userScottnath, 'users'),
]
},
play: async ({ args, canvasElement, step }) => {
const elements = await getElements(canvasElement);
const argsAfterFetch = {
...parseFetchedUser({...userScottnath}),
...args,
};
await ensureElements(elements, argsAfterFetch);
await ensureScreenRead(elements, argsAfterFetch);
}
}

export const ReposFetch = {
args: {
Expand Down

0 comments on commit 6e094ac

Please sign in to comment.