Skip to content

Commit 13618be

Browse files
committed
integrate prsima
1 parent 56d5b41 commit 13618be

File tree

19 files changed

+915
-38
lines changed

19 files changed

+915
-38
lines changed

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ yarn-error.log*
3535

3636
# typescript
3737
*.tsbuildinfo
38+
39+
.env*

‎__mocks__/fileMock.js‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎__mocks__/fileMock.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const mock = "file-mock";
2+
export default mock;

‎__mocks__/link.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Link({ children, href }) {
2+
return <children.type {...children.props} href={href} />;
3+
}

‎components/Layout/Sidebar/NavToggle/NavToggle.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { forwardRef } from "react";
22
import type { ComponentProps } from "react";
33
import clsx from "clsx";
44
import useTranslation from "next-translate/useTranslation";
5+
import { useId } from "@reach/auto-id";
56

67
interface Props extends ComponentProps<"button"> {
78
readonly type?: "button" | "submit" | "reset";
@@ -18,8 +19,8 @@ const ToggleIcon = ({ isOpen }: Pick<Props, "isOpen">) => {
1819
className="w-6 h-6 text-white"
1920
>
2021
<path
21-
x-show="open"
2222
fillRule="evenodd"
23+
data-testid="nav-toggle-icon"
2324
d={
2425
isOpen
2526
? "M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
@@ -39,7 +40,6 @@ const NavToggle = forwardRef<HTMLButtonElement, Props>(
3940
{...props}
4041
type={type}
4142
ref={ref}
42-
aria-label={t("sidebar.toggle.label")}
4343
aria-expanded={isOpen}
4444
className={clsx(
4545
"rounded-lg",
@@ -49,7 +49,7 @@ const NavToggle = forwardRef<HTMLButtonElement, Props>(
4949
)}
5050
>
5151
<ToggleIcon isOpen={isOpen} />
52-
<span className="sr-only">Menu</span>
52+
<span className="sr-only">{t("sidebar.toggle.label")}</span>
5353
</button>
5454
);
5555
},
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { render, screen } from "@testing-library/react";
2+
import NavToggle from "../NavToggle";
3+
4+
test("it should have icon path when closed", async () => {
5+
render(<NavToggle isOpen={false} />);
6+
expect(await screen.findByTestId("nav-toggle-icon")).toHaveAttribute(
7+
"d",
8+
"M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z",
9+
);
10+
});
11+
12+
test("it should have different icon path when open", async () => {
13+
render(<NavToggle isOpen />);
14+
expect(await screen.findByTestId("nav-toggle-icon")).toHaveAttribute(
15+
"d",
16+
"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",
17+
);
18+
});
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import { render } from "@testing-library/react";
1+
import { render, screen } from "@test/test-utils";
2+
import userEvent from "@testing-library/user-event";
23
import { axe } from "jest-axe";
34
import Sidebar from "..";
45

56
test("it should render with no violations", async () => {
67
const { container } = render(<Sidebar />);
78
expect(await axe(container)).toHaveNoViolations();
89
});
10+
11+
test("clicking the nav should toggle", async () => {
12+
render(<Sidebar />);
13+
userEvent.click(await screen.findByRole("button", { name: /menu/i }));
14+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { render } from "@testing-library/react";
2+
import { axe } from "jest-axe";
3+
import Layout from "..";
4+
5+
test("it should render with no violations", async () => {
6+
const { container } = render(<Layout />);
7+
expect(await axe(container)).toHaveNoViolations();
8+
});

‎jest.config.js‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
module.exports = {
2+
testEnvironment: "jsdom",
23
collectCoverageFrom: [
34
"**/*.{js,jsx,ts,tsx}",
45
"!**/*.d.ts",
56
"!**/node_modules/**",
7+
"!**/.next/**/*",
8+
"!**/coverage/**/*",
9+
"!*.config.js",
10+
"!components/**/index.ts",
611
],
712
moduleNameMapper: {
8-
/* Handle CSS imports (with CSS modules)
9-
https://jestjs.io/docs/webpack#mocking-css-modules */
1013
"^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy",
11-
12-
// Handle CSS imports (without CSS modules)
13-
"^.+\\.(css|sass|scss)$": "<rootDir>/__mocks__/styleMock.js",
14-
15-
/* Handle image imports
16-
https://jestjs.io/docs/webpack#handling-static-assets */
1714
"^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$":
1815
"<rootDir>/__mocks__/fileMock.js",
16+
"next/link": require.resolve("./__mocks__/Link.tsx"),
17+
"^@test(/.*)$": "<rootDir>/test$1",
1918
},
2019
setupFilesAfterEnv: ["./jest.setup.ts"],
2120
testPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/.next/"],
2221
testEnvironment: "jsdom",
2322
transform: {
24-
/* Use babel-jest to transpile tests with the next/babel preset
25-
https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object */
2623
"^.+\\.(js|jsx|ts|tsx)$": ["babel-jest", { presets: ["next/babel"] }],
2724
},
2825
transformIgnorePatterns: [

‎locales/en/common.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"blog": "blog"
66
},
77
"toggle": {
8-
"label": "Mobile Navigation Menu",
9-
"srLabel": "Menu"
8+
"label": "Menu"
109
}
1110
}
1211
}

0 commit comments

Comments
 (0)