Skip to content

Commit

Permalink
🎨 - refactor: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaohs committed Nov 27, 2024
1 parent d3c08db commit 122c24f
Showing 1 changed file with 8 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,15 @@ import {
destructionListAssigneesFactory,
destructionListFactory,
} from "../../../fixtures/destructionList";
import { paginatedDestructionListItemsFailedFactory } from "../../../fixtures/destructionListItem";
import { paginatedDestructionListItemsFactory } from "../../../fixtures/destructionListItem";
import { reviewFactory } from "../../../fixtures/review";
import {
beoordelaarFactory,
roleFactory,
userFactory,
usersFactory,
} from "../../../fixtures/user";
import {
getFilteredZaakSelection,
getZaakSelectionItems,
} from "../../../lib/zaakSelection";
import { Zaak } from "../../../types";
import {
DestructionListReviewPage,
getDestructionListReviewKey,
} from "./DestructionListReview";
import { DestructionListReviewPage } from "./DestructionListReview";
import { destructionListReviewAction } from "./DestructionListReview.action";
import { DestructionListReviewContext } from "./DestructionListReview.loader";

Expand Down Expand Up @@ -175,47 +167,14 @@ const FIXTURE: DestructionListReviewContext = {
logItems: [],
review: reviewFactory(),
reviewers: usersFactory(),
paginatedZaken: paginatedDestructionListItemsFailedFactory(),
paginatedZaken: paginatedDestructionListItemsFactory(),
};

export const ReviewerCanApproveZaak: Story = {
parameters: {
reactRouterDecorator: {
route: {
loader: async () => {
const storageKey = getDestructionListReviewKey(
FIXTURE.uuid,
FIXTURE.destructionList.status,
);
const zakenResults = FIXTURE.paginatedZaken.results
.map((zaak) => zaak.zaak)
.filter((zaak) => zaak !== null) as Zaak[];
const zakenOnPage = zakenResults.map((z) => z.url as string);

const approvedZaakUrlsOnPagePromise = await Promise.all(
zakenOnPage.map(async (url) => {
const selection = await getZaakSelectionItems<{
approved: boolean;
}>(storageKey, [url]);
const item = selection[url];
return { url, approved: item?.detail?.approved };
}),
);

const approvedZaakUrlsOnPage = approvedZaakUrlsOnPagePromise
.filter((result) => result.approved)
.map((result) => result.url);

const excludedZaakSelection = await getFilteredZaakSelection<{
approved: false;
}>(storageKey, { approved: false });

return {
...FIXTURE,
approvedZaakUrlsOnPage,
excludedZaakSelection,
};
},
loader: async () => FIXTURE,
action: destructionListReviewAction,
},
},
Expand All @@ -227,8 +186,10 @@ export const ReviewerCanApproveZaak: Story = {
});
const approve = approves[0];
await userEvent.click(approve);
const checkbox = await canvas.findByRole("checkbox", { checked: true });
await expect(checkbox).toBeInTheDocument();
// Find all checkboxes
const checkboxes = await canvas.findAllByRole("checkbox");
const checkbox = checkboxes[0];
await expect(checkbox).toBeChecked();
},
};

Expand Down

0 comments on commit 122c24f

Please sign in to comment.