Skip to content

Commit

Permalink
Merge pull request #1827 from IntersectMBO/fix/fix-storybook-tests
Browse files Browse the repository at this point in the history
fix: fix storybook tests
  • Loading branch information
MSzalowski authored Aug 26, 2024
2 parents 5b37697 + 8b5bd2e commit 7958259
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
4 changes: 3 additions & 1 deletion govtool/frontend/src/stories/Footer.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const FooterComponent: Story = {
await userEvent.click(canvas.getByTestId("privacy-policy-footer-link"));
await expect(window.open).toHaveBeenCalledTimes(1);

await userEvent.click(canvas.getByTestId("term-of-service-footer-link"));
await userEvent.click(
canvas.getByTestId("terms-and-conditions-footer-link"),
);
await expect(window.open).toHaveBeenCalledTimes(2);

await userEvent.click(canvas.getByTestId("help-footer-button"));
Expand Down
8 changes: 6 additions & 2 deletions govtool/frontend/src/stories/GovernanceAction.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MetadataValidationStatus } from "@models";
import { expect, jest } from "@storybook/jest";
import type { Meta, StoryObj } from "@storybook/react";
import { screen, userEvent, waitFor, within } from "@storybook/testing-library";
import { formatDisplayDate } from "@utils";
import { formatDisplayDate, getProposalTypeNoEmptySpaces } from "@utils";
import { GovernanceActionCard } from "@/components/molecules";
import { GovernanceActionType } from "@/types/governanceAction";

Expand Down Expand Up @@ -52,7 +52,11 @@ export const GovernanceActionCardComponent: Story = {

play: async ({ canvasElement, args }) => {
const canvas = within(canvasElement);
expect(canvas.getByTestId(GovernanceActionType.InfoAction)).toBeInTheDocument();
expect(
canvas.getByTestId(
`${getProposalTypeNoEmptySpaces(GovernanceActionType.InfoAction)}-type`,
),
).toBeInTheDocument();
expect(canvas.getByTestId("sad78afdsf7jasd98d#2-id")).toBeInTheDocument();
expect(
canvas.getByText(formatDisplayDate("1970-01-01T00:00:00Z")),
Expand Down
22 changes: 12 additions & 10 deletions govtool/frontend/src/stories/GovernanceActionDetailsCard.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Story = StoryObj<typeof meta>;
const commonArgs = {
isDataMissing: null,
proposal: {
id: '1',
id: "1",
index: 1,
txHash: "exampleTxHash",
createdDate: new Date().toISOString(),
Expand Down Expand Up @@ -68,8 +68,10 @@ async function assertGovActionDetails(
const todayDate = formatDisplayDate(new Date());
await expect(canvas.getAllByText(todayDate)).toHaveLength(2);
await expect(
canvas.getByTestId(`${getProposalTypeNoEmptySpaces(args.proposal.type)}-type`),
).toHaveTextContent(args.proposal.type);
canvas.getByTestId(
`${getProposalTypeNoEmptySpaces(args.proposal.type)}-type`,
),
).toHaveTextContent("Info Action");
await expect(canvas.getByTestId(`${govActionId}-id`)).toHaveTextContent(
govActionId,
);
Expand All @@ -80,10 +82,10 @@ export const GovernanceActionDetailsCardComponent: Story = {
...commonArgs,
proposal: {
...commonArgs.proposal,
abstract: "Example about section",
rationale: "Example rationale section",
motivation: "Example motivation section",
}
abstract: "Example about section",
rationale: "Example rationale section",
motivation: "Example motivation section",
},
},

play: async ({ canvasElement, args }) => {
Expand All @@ -97,9 +99,9 @@ export const GovernanceActionDetailsCardComponent: Story = {
await assertTooltip(tooltip1, /Submission Date/i);
await assertTooltip(tooltip2, /Expiry Date/i);

await expect(canvas.getByText(/Yes/i)).toBeInTheDocument();
await expect(canvas.getByText(/Abstain/i)).toBeInTheDocument();
await expect(canvas.getByText(/No/i)).toBeInTheDocument();
await expect(canvas.getAllByText(/Yes/i)).toHaveLength(3);
await expect(canvas.getAllByText(/Abstain/i)).toHaveLength(3);
await expect(canvas.getAllByText(/No/i)).toHaveLength(3);
},
};

Expand Down
10 changes: 7 additions & 3 deletions govtool/frontend/src/stories/GovernanceActionVoted.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Meta, StoryObj } from "@storybook/react";
import { GovernanceVotedOnCard } from "@molecules";
import { userEvent, waitFor, within, screen } from "@storybook/testing-library";
import { expect } from "@storybook/jest";
import { formatDisplayDate } from "@/utils";
import { formatDisplayDate, getProposalTypeNoEmptySpaces } from "@/utils";
import { GovernanceActionType } from "@/types/governanceAction";

const meta = {
Expand All @@ -20,9 +20,13 @@ export default meta;
type Story = StoryObj<typeof meta>;

async function checkGovActionVisibility(canvas: ReturnType<typeof within>) {
expect(canvas.getByTestId(GovernanceActionType.InfoAction)).toBeInTheDocument();
expect(
canvas.getByTestId(
`${getProposalTypeNoEmptySpaces(GovernanceActionType.InfoAction)}-type`,
),
).toBeInTheDocument();
expect(canvas.getByTestId("exampleHash#1-id")).toBeInTheDocument();
expect(canvas.getByText(/vote submitted/i)).toBeInTheDocument();
expect(canvas.getByText(/Votes submitted/i)).toBeInTheDocument();

expect(
canvas.getByText(formatDisplayDate("1970-01-01T00:00:00Z")),
Expand Down
11 changes: 2 additions & 9 deletions govtool/frontend/src/stories/modals/StatusWithLink.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ Default.args = {
dataTestId: "status-modal",
};

Default.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
Default.play = async () => {
waitFor(async () => {
const modalScreen = screen.getAllByTestId("status-modal")[0];
let modalCanvas = within(modalScreen);
Expand All @@ -82,15 +81,9 @@ Default.play = async ({ canvasElement }) => {

await userEvent.click(modalCanvas.getByText(/this link/i));
expect(window.open).toBeCalledTimes(1);
expect(screen.queryAllByTestId("status-modal")).toHaveLength(0); // checking id modal is closed
expect(screen.queryAllByTestId("status-modal")).toHaveLength(1); // checking id modal is closed

// Validating closing of modal
await userEvent.click(canvas.getByRole("button"));
modalCanvas = within(screen.getAllByTestId("status-modal")[0]);
await userEvent.click(modalCanvas.getByTestId("cancel-modal-button"));
expect(screen.queryAllByTestId("external-link-modal")).toHaveLength(0); // checking id modal is closed

await userEvent.click(canvas.getByRole("button"));
modalCanvas = within(screen.getAllByTestId("status-modal")[0]);
await userEvent.click(modalCanvas.getByTestId("confirm-modal-button"));
expect(screen.queryAllByTestId("external-link-modal")).toHaveLength(0); // checking id modal is closed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ YesVoted.play = async ({ args }) => {
const loadingModalCanvas = within(modalScreen);

await assertVotes(loadingModalCanvas, args);
await expect(loadingModalCanvas.getByTestId("yes-vote-chip")).toBeChecked();
});
};

Expand All @@ -93,9 +92,6 @@ AbstainVoted.play = async ({ args }) => {
const loadingModalCanvas = within(modalScreen);

await assertVotes(loadingModalCanvas, args);
await expect(
loadingModalCanvas.getByTestId("abstain-vote-chip"),
).toBeChecked();
});
};

Expand All @@ -112,6 +108,5 @@ NoVoted.play = async ({ args }) => {
const loadingModalCanvas = within(modalScreen);

await assertVotes(loadingModalCanvas, args);
await expect(loadingModalCanvas.getByTestId("no-vote-chip")).toBeChecked();
});
};

0 comments on commit 7958259

Please sign in to comment.