Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1add80d

Browse files
committed
Add coverage files to ignore
1 parent 18a9f88 commit 1add80d

File tree

5 files changed

+235
-10
lines changed

5 files changed

+235
-10
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ vendor
1515
yarn-error.log
1616

1717
# Front-end ignore
18-
site/dist/
18+
site/dist/
19+
coverage/

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@
88
"build:watch": "webpack build --config site/webpack.config.js --watch",
99
"format:check": "prettier --check '**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}'",
1010
"format:write": "prettier --write '**/*.{css,htmljs,json,jsx,md,ts,tsx,yaml,yml}'",
11-
"test": "jest --selectProjects test"
11+
"test": "jest --selectProjects test",
12+
"test:coverage": "jest --selectProjects test --collectCoverage"
1213
},
1314
"devDependencies": {
1415
"@material-ui/core": "4.9.4",
1516
"@material-ui/icons": "4.5.1",
1617
"@material-ui/lab": "4.0.0-alpha.42",
18+
"@testing-library/jest-dom": "5.16.1",
19+
"@testing-library/react": "12.1.2",
20+
"@testing-library/react-hooks": "7.0.2",
21+
"@testing-library/user-event": "13.5.0",
1722
"@types/jest": "27.4.0",
1823
"@types/node": "14.18.4",
1924
"@types/react": "17.0.38",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { fireEvent, render, screen } from "@testing-library/react"
2+
import React from "react"
3+
import { SplitButton, SplitButtonProps } from "./SplitButton"
4+
5+
namespace Helpers {
6+
export type SplitButtonOptions = "a" | "b" | "c"
7+
8+
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
9+
export const callback = (selectedOption: SplitButtonOptions): void => { }
10+
11+
export const options: SplitButtonProps<SplitButtonOptions>["options"] = [
12+
{
13+
label: "test a",
14+
value: "a",
15+
},
16+
{
17+
label: "test b",
18+
value: "b",
19+
},
20+
{
21+
label: "test c",
22+
value: "c",
23+
},
24+
]
25+
}
26+
27+
describe("SplitButton", () => {
28+
describe("onClick", () => {
29+
it("is called when primary action is clicked", () => {
30+
// Given
31+
const mockedAndSpyedCallback = jest.fn(Helpers.callback)
32+
33+
// When
34+
render(<SplitButton onClick={mockedAndSpyedCallback} options={Helpers.options} />)
35+
fireEvent.click(screen.getByText("test a"))
36+
37+
// Then
38+
expect(mockedAndSpyedCallback.mock.calls.length).toBe(1)
39+
expect(mockedAndSpyedCallback.mock.calls[0][0]).toBe("a")
40+
})
41+
42+
it("is called when clicking option in pop-up", () => {
43+
// Given
44+
const mockedAndSpyedCallback = jest.fn(Helpers.callback)
45+
46+
// When
47+
render(<SplitButton onClick={mockedAndSpyedCallback} options={Helpers.options} />)
48+
const buttons = screen.getAllByRole("button")
49+
const dropdownButton = buttons[1]
50+
fireEvent.click(dropdownButton)
51+
fireEvent.click(screen.getByText("test c"))
52+
53+
// Then
54+
expect(mockedAndSpyedCallback.mock.calls.length).toBe(1)
55+
expect(mockedAndSpyedCallback.mock.calls[0][0]).toBe("c")
56+
})
57+
})
58+
})
File renamed without changes.

0 commit comments

Comments
 (0)