Skip to content

Commit

Permalink
Merge pull request #188 from kabisa/add-missing-test-flows
Browse files Browse the repository at this point in the history
Update and add more specs
  • Loading branch information
matthijsgroen authored May 28, 2024
2 parents a6ca9f4 + b42de09 commit ca37f71
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 26 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@testing-library/jest-dom": "^6.0.0",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^29.5.3",
"@types/jest": "^29.5.12",
"@types/node": "^13.9.0",
"@types/react": "^17.0.2",
"@types/react-click-outside": "^3.0.3",
Expand All @@ -94,7 +94,7 @@
"prettier": "^3.0.1",
"react-responsive": "^9.0.2",
"storybook": "^7.3.2",
"ts-jest": "^29.1.1",
"ts-jest": "^29.1.4",
"typescript": "^5.1.6",
"webpack": "^5.88.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src/modules/choose-team/components/ChoiceButton.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe("<ChoiceButton />", () => {
userEvent.click(screen.getByRole("button", { name: "button text" }));

await waitFor(() => {
expect(Storage.setItem).toBeCalledTimes(0);
expect(Storage.setItem).toHaveBeenCalledTimes(0);
});
});
});
19 changes: 18 additions & 1 deletion src/modules/feed/components/Transaction/Header.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { mockLocalstorage, withMockedProviders } from "../../../../spec_helper";
import {
MockedFunction,
mockLocalstorage,
withMockedProviders,
} from "../../../../spec_helper";
import { Header, MUTATION_REMOVE_POST } from "./Header";
import { FragmentPostResult, GET_POSTS } from "../../queries";
import { screen, render, waitFor } from "@testing-library/react";
Expand Down Expand Up @@ -167,5 +171,18 @@ describe("<Header />", () => {
expect(queryCalled).toBe(true);
});
});

it("does not call the delete mutation when confirm is canceled", () => {
const deleteButton = screen.getByTestId("delete-button");
queryCalled = false;
(global.confirm as MockedFunction<Window["confirm"]>).mockReturnValueOnce(
false,
);

deleteButton.click();
waitFor(() => {
expect(mutationCalled).not.toBe(true);
});
});
});
});
22 changes: 18 additions & 4 deletions src/modules/manage-team/sections/guideline/Guideline.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { mockLocalstorage, withMockedProviders } from "../../../../spec_helper";
import {
MockedFunction,
mockLocalstorage,
withMockedProviders,
} from "../../../../spec_helper";
import { DELETE_GUIDELINE, Guideline } from "./Guideline";
import { GET_GUIDELINES } from "./GuidelinesSection";
import { render, screen, waitFor } from "@testing-library/react";
Expand Down Expand Up @@ -98,7 +102,7 @@ describe("<Guideline />", () => {
const editButton = screen.getByRole("button", { name: "edit" });
editButton.click();

expect(editGuidelineMock).toBeCalledTimes(1);
expect(editGuidelineMock).toHaveBeenCalledTimes(1);
expect(editGuidelineMock).toHaveBeenCalledWith(
guideline.id,
guideline.kudos,
Expand All @@ -107,12 +111,12 @@ describe("<Guideline />", () => {
});

it("has a confirm button for the delete action", () => {
expect(global.confirm).toBeCalledTimes(0);
expect(global.confirm).toHaveBeenCalledTimes(0);

const deleteButton = screen.getByRole("button", { name: "delete" });
deleteButton.click();

expect(global.confirm).toBeCalledTimes(1);
expect(global.confirm).toHaveBeenCalledTimes(1);
});

it("calls the delete mutation", async () => {
Expand All @@ -128,4 +132,14 @@ describe("<Guideline />", () => {

await waitFor(() => expect(getGuidelinesCalled).toBe(true));
});

it("does not the delete mutation if confirm is cancelled", async () => {
(global.confirm as MockedFunction<Window["confirm"]>).mockReturnValueOnce(
true,
);
const deleteButton = screen.getByRole("button", { name: "delete" });
deleteButton.click();

await waitFor(() => expect(mutationCalled).toBe(true));
});
});
16 changes: 15 additions & 1 deletion src/modules/manage-team/sections/invite/Invite.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { mockLocalstorage, withMockedProviders } from "../../../../spec_helper";
import {
MockedFunction,
mockLocalstorage,
withMockedProviders,
} from "../../../../spec_helper";
import { Invite, MUTATION_DELETE_INVITE } from "./Invite";
import { InviteModel, QUERY_GET_INVITES } from "./InvitesSection";
import { render, screen, waitFor } from "@testing-library/react";
Expand Down Expand Up @@ -147,4 +151,14 @@ describe("<Invite />", () => {
expect(queryCalled).toBe(true);
});
});

it("does not the delete mutation if confirm is cancelled", async () => {
(global.confirm as MockedFunction<Window["confirm"]>).mockReturnValueOnce(
true,
);
const deleteButton = screen.getByRole("button", { name: "delete" });
deleteButton.click();

await waitFor(() => expect(mutationCalled).toBe(true));
});
});
21 changes: 18 additions & 3 deletions src/modules/manage-team/sections/kudometer/KudometerRow.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { mockLocalstorage, withMockedProviders } from "../../../../spec_helper";
import {
MockedFunction,
mockLocalstorage,
withMockedProviders,
} from "../../../../spec_helper";
import { KudometerRow } from "./KudometerRow";
import {
DELETE_KUDOMETER,
Expand Down Expand Up @@ -149,7 +153,7 @@ describe("<KudometerRow />", () => {
goalButton.click();

await waitFor(() => {
expect(viewButtonHandler).toBeCalledTimes(1);
expect(viewButtonHandler).toHaveBeenCalledTimes(1);
});
});

Expand All @@ -176,6 +180,17 @@ describe("<KudometerRow />", () => {
});
});

it("does not the delete mutation if confirm is cancelled", async () => {
setup(getKudometer(false));
(global.confirm as MockedFunction<Window["confirm"]>).mockReturnValueOnce(
true,
);
const deleteButton = screen.getByRole("button", { name: "delete" });
deleteButton.click();

await waitFor(() => expect(mutationCalled).toBe(true));
});

it("has a edit button", () => {
setup(getKudometer(false));
const editButton = screen.getByRole("button", { name: "edit" });
Expand All @@ -187,7 +202,7 @@ describe("<KudometerRow />", () => {
const editButton = screen.getByRole("button", { name: "edit" });
editButton.click();

expect(editHandler).toBeCalledTimes(1);
expect(editHandler).toHaveBeenCalledTimes(1);
});

describe("make active button", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
MockedFunction,
mockLocalstorage,
withMockedProviders,
} from "../../../../../spec_helper";
Expand Down Expand Up @@ -95,7 +96,7 @@ describe("<GoalRow />", () => {
const editButton = screen.getByRole("button", { name: "edit" });
editButton.click();

expect(editGoalMock).toBeCalledTimes(1);
expect(editGoalMock).toHaveBeenCalledTimes(1);
});

it("has a delete confirm button", () => {
Expand All @@ -116,4 +117,14 @@ describe("<GoalRow />", () => {
expect(queryCalled).toBe(true);
});
});

it("does not the delete mutation if confirm is cancelled", async () => {
(global.confirm as MockedFunction<Window["confirm"]>).mockReturnValueOnce(
true,
);
const deleteButton = screen.getByRole("button", { name: "delete" });
deleteButton.click();

await waitFor(() => expect(mutationCalled).toBe(true));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe("<AlterRoleButton />", () => {

await waitFor(() => {
expect(mutationCalled).toBe(true);
expect(refetch).toBeCalledTimes(1);
expect(refetch).toHaveBeenCalledTimes(1);
});
});
});
18 changes: 16 additions & 2 deletions src/modules/manage-team/sections/member/MemberRow.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { mockLocalstorage, withMockedProviders } from "../../../../spec_helper";
import {
MockedFunction,
mockLocalstorage,
withMockedProviders,
} from "../../../../spec_helper";
import { MemberRow } from "./MemberRow";
import { DEACTIVATE_USER } from "./Members";
import { RenderResult, render, screen, waitFor } from "@testing-library/react";
Expand Down Expand Up @@ -78,10 +82,20 @@ describe("<MemberRow />", () => {

await waitFor(() => {
expect(mutationCalled).toBe(true);
expect(refetch).toBeCalledTimes(1);
expect(refetch).toHaveBeenCalledTimes(1);
});
});

it("does not the delete mutation if confirm is cancelled", async () => {
(global.confirm as MockedFunction<Window["confirm"]>).mockReturnValueOnce(
true,
);
const deactivateButton = screen.getByRole("button", { name: "delete" });
deactivateButton.click();

await waitFor(() => expect(mutationCalled).toBe(true));
});

it("renders the buttons if the membership is not the current user", () => {
mockLocalstorage("5");
setup();
Expand Down
5 changes: 5 additions & 0 deletions src/spec_helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export const mockLocalstorage = (value: string) => {
Storage.prototype.getItem = jest.fn(() => value);
};

export type MockedFunction<Func extends (...args: any[]) => any> = jest.Mock<
ReturnType<Func>,
Parameters<Func>
>;

export const getMockCache = () =>
new InMemoryCache({
typePolicies: {
Expand Down
23 changes: 13 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5729,13 +5729,13 @@ __metadata:
languageName: node
linkType: hard

"@types/jest@npm:^29.5.3":
version: 29.5.5
resolution: "@types/jest@npm:29.5.5"
"@types/jest@npm:^29.5.12":
version: 29.5.12
resolution: "@types/jest@npm:29.5.12"
dependencies:
expect: ^29.0.0
pretty-format: ^29.0.0
checksum: 56e55cde9949bcc0ee2fa34ce5b7c32c2bfb20e53424aa4ff3a210859eeaaa3fdf6f42f81a3f655238039cdaaaf108b054b7a8602f394e6c52b903659338d8c6
checksum: 19b1efdeed9d9a60a81edc8226cdeae5af7479e493eaed273e01243891c9651f7b8b4c08fc633a7d0d1d379b091c4179bbaa0807af62542325fd72f2dd17ce1c
languageName: node
linkType: hard

Expand Down Expand Up @@ -13349,7 +13349,7 @@ __metadata:
"@testing-library/jest-dom": ^6.0.0
"@testing-library/react": ^12.1.5
"@testing-library/user-event": ^14.4.3
"@types/jest": ^29.5.3
"@types/jest": ^29.5.12
"@types/node": ^13.9.0
"@types/react": ^17.0.2
"@types/react-click-outside": ^3.0.3
Expand Down Expand Up @@ -13396,7 +13396,7 @@ __metadata:
semantic-ui-css: ^2.5.0
semantic-ui-react: ^2.1.4
storybook: ^7.3.2
ts-jest: ^29.1.1
ts-jest: ^29.1.4
typescript: ^5.1.6
uuid: ^9.0.1
webpack: ^5.88.2
Expand Down Expand Up @@ -18712,9 +18712,9 @@ __metadata:
languageName: node
linkType: hard

"ts-jest@npm:^29.1.1":
version: 29.1.1
resolution: "ts-jest@npm:29.1.1"
"ts-jest@npm:^29.1.4":
version: 29.1.4
resolution: "ts-jest@npm:29.1.4"
dependencies:
bs-logger: 0.x
fast-json-stable-stringify: 2.x
Expand All @@ -18726,13 +18726,16 @@ __metadata:
yargs-parser: ^21.0.1
peerDependencies:
"@babel/core": ">=7.0.0-beta.0 <8"
"@jest/transform": ^29.0.0
"@jest/types": ^29.0.0
babel-jest: ^29.0.0
jest: ^29.0.0
typescript: ">=4.3 <6"
peerDependenciesMeta:
"@babel/core":
optional: true
"@jest/transform":
optional: true
"@jest/types":
optional: true
babel-jest:
Expand All @@ -18741,7 +18744,7 @@ __metadata:
optional: true
bin:
ts-jest: cli.js
checksum: a8c9e284ed4f819526749f6e4dc6421ec666f20ab44d31b0f02b4ed979975f7580b18aea4813172d43e39b29464a71899f8893dd29b06b4a351a3af8ba47b402
checksum: e36cba389adbb3700b46422e883c8d25e76febcc01c4a39c801ef15e6edbd6da1695bdd144100153e992f98a754aea4099906955b1b9a83c3c72d77009c3d7e2
languageName: node
linkType: hard

Expand Down

0 comments on commit ca37f71

Please sign in to comment.