Skip to content

Commit

Permalink
add axe testing
Browse files Browse the repository at this point in the history
  • Loading branch information
luantr committed Nov 14, 2023
1 parent da73abf commit 488530c
Show file tree
Hide file tree
Showing 9 changed files with 686 additions and 544 deletions.
1,167 changes: 631 additions & 536 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@
"devDependencies": {
"@testing-library/dom": "^9.2.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/react": "^14.1.0",
"@testing-library/user-event": "^14.4.3",
"@types/amplitude-js": "^8.9.3",
"@types/cookie": "^0.4.1",
"@types/http-errors": "^1.8.1",
"@types/jest-axe": "^3.5.8",
"@types/node": "^17.0.1",
"@types/on-headers": "^1.0.0",
"@types/react": "17.0.37",
Expand All @@ -67,7 +68,8 @@
"eslint-plugin-testing-library": "^5.10.2",
"husky": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.5.0",
"jest": "^29.7.0",
"jest-axe": "^8.0.0",
"jest-environment-jsdom": "^29.5.0",
"jsdom": "^22.1.0",
"lint-staged": "^13.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/common/utils/__tests__/dateUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {

describe("dateUtils", () => {
beforeAll(() => {
jest.useFakeTimers();
jest.setSystemTime(new Date("2020-02-02").getTime());
});
afterAll(() => {
Expand Down
12 changes: 11 additions & 1 deletion src/pages/arbeidsgiver/[narmestelederid]/motebehov/meld.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { waitFor, within } from "@testing-library/react";
import { act, waitFor, within } from "@testing-library/react";
import { render, screen } from "../../../../test/testUtils";
import mockRouter from "next-router-mock";
import { rest } from "msw";
import { testServer } from "../../../../mocks/testServer";
import MeldBehov from "@/pages/arbeidsgiver/[narmestelederid]/motebehov/meld.page";
import { sykmeldtFixture } from "../../../../mocks/data/fixtures/sykmeldt";
import { axe } from "jest-axe";

describe("meld page arbeidsgiver", () => {
beforeEach(() => {
mockRouter.setCurrentUrl("/arbeidsgiver?narmestelederid=123");
});

it("should have no a11y violations", async () => {
const { container } = render(<MeldBehov />);

await act(async () => {
const result = await axe(container);
expect(result).toHaveNoViolations();
});
});

it("should post on submit", async () => {
const requestResolver = jest.fn();
testServer.use(
Expand Down
12 changes: 11 additions & 1 deletion src/pages/arbeidsgiver/[narmestelederid]/motebehov/svar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { waitFor, within } from "@testing-library/react";
import { act, waitFor, within } from "@testing-library/react";
import { render, screen } from "../../../../test/testUtils";
import mockRouter from "next-router-mock";
import { rest } from "msw";
import { testServer } from "../../../../mocks/testServer";
import SvarBehov from "@/pages/arbeidsgiver/[narmestelederid]/motebehov/svar.page";
import { sykmeldtFixture } from "../../../../mocks/data/fixtures/sykmeldt";
import { axe } from "jest-axe";

describe("svar page arbeidsgiver", () => {
beforeEach(() => {
mockRouter.setCurrentUrl("/arbeidsgiver?narmestelederid=123");
});

it("should have no a11y violations", async () => {
const { container } = render(<SvarBehov />);

await act(async () => {
const result = await axe(container);
expect(result).toHaveNoViolations();
});
});

it("should post on submit", async () => {
const requestResolver = jest.fn();
testServer.use(
Expand Down
13 changes: 12 additions & 1 deletion src/pages/sykmeldt/motebehov/meld.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import { waitFor, within } from "@testing-library/react";
import { act, waitFor, within } from "@testing-library/react";
import { render, screen } from "../../../test/testUtils";
import MeldBehov from "@/pages/sykmeldt/motebehov/meld.page";
import mockRouter from "next-router-mock";
import { rest } from "msw";
import { testServer } from "../../../mocks/testServer";
import { axe } from "jest-axe";

describe("meld page sykmeldt", () => {
beforeEach(() => {
mockRouter.setCurrentUrl("/sykmeldt");
});

it("should have no a11y violations", async () => {
const { container } = render(<MeldBehov />);

await act(async () => {
const result = await axe(container);
expect(result).toHaveNoViolations();
});
});

it("should post on submit", async () => {
const requestResolver = jest.fn();
testServer.use(
Expand Down
13 changes: 12 additions & 1 deletion src/pages/sykmeldt/motebehov/svar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import { waitFor, within } from "@testing-library/react";
import { act, waitFor, within } from "@testing-library/react";
import { render, screen } from "../../../test/testUtils";
import mockRouter from "next-router-mock";
import { rest } from "msw";
import { testServer } from "../../../mocks/testServer";
import SvarBehov from "@/pages/sykmeldt/motebehov/svar.page";
import { axe } from "jest-axe";

describe("svar page sykmeldt", () => {
beforeEach(() => {
mockRouter.setCurrentUrl("/sykmeldt");
});

it("should have no a11y violations", async () => {
const { container } = render(<SvarBehov />);

await act(async () => {
const result = await axe(container);
expect(result).toHaveNoViolations();
});
});

it("should post on submit", async () => {
const requestResolver = jest.fn();
testServer.use(
Expand Down
1 change: 1 addition & 0 deletions src/server/data/common/__tests__/mapDialogmoteData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createBrevDTO } from "../../../../mocks/data/factories/brevDTO";

describe("mapDialogmoteData", () => {
beforeAll(() => {
jest.useFakeTimers();
jest.setSystemTime(new Date("2020-02-02").getTime());
});
afterAll(() => {
Expand Down
5 changes: 3 additions & 2 deletions src/test/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import "@testing-library/jest-dom";
import "@testing-library/user-event";
import { testServer } from "../mocks/testServer";

jest.useFakeTimers("modern");
import { toHaveNoViolations } from "jest-axe";

expect.extend(toHaveNoViolations);

jest.mock("@/common/hooks/useAmplitude", () => ({
useAmplitude: () => ({ trackEvent: jest.fn() }),
Expand All @@ -14,7 +16,6 @@ jest.mock("next/config", () => () => ({
basePath: "/basepath",
},
}));

jest.mock("src/auth/beskyttetSide.ts", () => {
return jest.fn().mockImplementation((callback) => {
callback();
Expand Down

0 comments on commit 488530c

Please sign in to comment.