Skip to content

Commit

Permalink
Storybook data fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Mar 27, 2024
1 parent c155c9b commit f8e5701
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/addons/browser/Browser.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
return data;
})
.catch((err) => {
error = err;
error = err.detail;
loading = false;
return {};
});
Expand Down
2 changes: 1 addition & 1 deletion src/addons/runs/Scheduled.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
$: next_url = res.next ? new URL(res.next) : null;
$: prev_url = res.previous ? new URL(res.previous) : null;
$: events = res.results ?? [];
$: empty = !loading && res.results?.length === 0;
$: empty = !loading && !Boolean(res.results?.length);
export async function load(url?: string | URL) {
try {
Expand Down
12 changes: 6 additions & 6 deletions src/manager/orgsAndUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ export async function inMyOrg(orgId, myId) {
if (!orgId) return [];
const users = await getUsers({ orgIds: [orgId] });
// Sort by admin status, then username
const adminUsers = users
.filter((u) => u.admin_organizations?.includes(orgId))
.sort(alphabetizeUsers);
const regularUsers = users
.filter((u) => !adminUsers.includes(u))
.sort(alphabetizeUsers);
const adminUsers =
users
?.filter((u) => u.admin_organizations?.includes(orgId))
.sort(alphabetizeUsers) ?? [];
const regularUsers =
users?.filter((u) => !adminUsers.includes(u)).sort(alphabetizeUsers) ?? [];
// Remove me from the user list
return [...adminUsers, ...regularUsers].filter((u) => u.id !== myId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import OrgMemberList from "../OrgMemberList.svelte";
import { mockInMyOrg } from "../../../../test/handlers/accounts";
const args = { orgId: 1, myId: 4 };
const args = { orgId: 1, myId: 100012 };
export const meta = {
title: "App / Accounts / Menus / Org / Member List",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/app/stories/Documents.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
users.me,
organizations.data,
projects.data,
runs.data,
runs.empty,
];
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/projects/Browser.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
}
// }
} catch (err) {
error = err;
error = err.errorData.detail;
projects = null;
}
loading = false;
Expand Down
2 changes: 1 addition & 1 deletion src/test/fixtures/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Org, Page, User } from "../../api/types";
import { GroupOrg, IndividualOrg } from "../../api/types/orgAndUser";

export const me: User = {
id: 1020,
id: 100012,
avatar_url: "https://cdn.muckrock.com/media/avatars/20140211-0O1A7147-2.jpg",
feature_level: 2,
is_staff: true,
Expand Down
1 change: 1 addition & 0 deletions src/test/fixtures/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const projectList: Page<Project> = {
title: "Add-on test",
updated_at: "2022-03-01T15:55:05.536919Z",
user: 100003,
pinned: true,
},
{
id: 200008,
Expand Down
7 changes: 5 additions & 2 deletions src/test/handlers/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ export const mockGetMe = {
ctx.json({
...meFixture,
organization: { ...(meFixture.organization as Org), plan: "Free" },
admin_organizations: [...meFixture.admin_organizations, 1],
admin_organizations: [
...meFixture.admin_organizations,
(meFixture.organization as Org).id,
],
}),
),
),
Expand All @@ -95,7 +98,7 @@ export const mockGetMe = {
};

/* Mock Request Handlers */
export const mockInMyOrg = generateGetHandler(`/users`, usersList);
export const mockInMyOrg = generateGetHandler(`users/*`, usersList);

const listOrgsUrl = new URL(`organizations/`, baseApiUrl).toString();
export const mockGetOrgsList = {
Expand Down
3 changes: 3 additions & 0 deletions src/test/handlers/addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import {
import {
createApiUrl,
dataHandler,
emptyHandler,
generateAllHandler,
generateGetHandler,
} from "./utils";
import { emptyList } from "../fixtures/common";

/* Mock Handlers */

Expand All @@ -38,4 +40,5 @@ export const progress = [

export const runs = {
data: rest.get(createApiUrl("addon_runs/"), dataHandler(runsList)),
empty: rest.get(createApiUrl("addon_runs/"), emptyHandler()),
};
18 changes: 16 additions & 2 deletions src/test/handlers/projects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import { generateGetHandler } from "./utils";
import { rest } from "msw";
import {
dataHandler,
emptyHandler,
errorHandler,
loadingHandler,
createApiUrl,
} from "./utils";
import { projectList } from "../fixtures/projects";
import { emptyList } from "../fixtures/common";

export const projects = generateGetHandler("projects/", projectList);
const projectsUrl = createApiUrl("projects/*");
export const projects = {
data: rest.get(projectsUrl, dataHandler(projectList)),
empty: rest.get(projectsUrl, emptyHandler(emptyList)),
loading: rest.get(projectsUrl, loadingHandler),
error: rest.get(projectsUrl, errorHandler),
};
2 changes: 1 addition & 1 deletion src/test/handlers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function createApiUrl(path: string): string {

export const dataHandler = (data) => (req, res, ctx) => res(ctx.json(data));
export const emptyHandler =
(emptyData = []) =>
(emptyData: any = []) =>
(req, res, ctx) =>
res(ctx.json(emptyData));
export const errorHandler = (req, res, ctx) =>
Expand Down

0 comments on commit f8e5701

Please sign in to comment.