-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add initial jest tests + code coverage (#13)
- Adds initial infra for running front-end tests (`jest`, `ts-jest`, `jest.config.js`, etc) - Adds codecov integration front-end code
- Loading branch information
1 parent
afc2fa3
commit 423611b
Showing
20 changed files
with
2,512 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ yarn-error.log | |
|
||
# Front-end ignore | ||
.next/ | ||
site/.next/ | ||
site/.next/ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ yarn-error.log | |
|
||
# Front-end ignore | ||
.next/ | ||
site/.next/ | ||
site/.next/ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = { | ||
projects: [ | ||
{ | ||
coverageReporters: ["text", "lcov"], | ||
displayName: "test", | ||
preset: "ts-jest", | ||
roots: ["<rootDir>/site"], | ||
transform: { | ||
"^.+\\.tsx?$": "ts-jest", | ||
}, | ||
testEnvironment: "jsdom", | ||
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$", | ||
testPathIgnorePatterns: ["/node_modules/", "/__tests__/fakes"], | ||
moduleDirectories: ["node_modules", "<rootDir>"], | ||
}, | ||
], | ||
collectCoverageFrom: [ | ||
"<rootDir>/site/**/*.js", | ||
"<rootDir>/site/**/*.ts", | ||
"<rootDir>/site/**/*.tsx", | ||
"!<rootDir>/site/**/*.stories.tsx", | ||
"!<rootDir>/site/.next/**/*.*", | ||
"!<rootDir>/site/next-env.d.ts", | ||
"!<rootDir>/site/next.config.js", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react" | ||
import React from "react" | ||
import { SplitButton, SplitButtonProps } from "./SplitButton" | ||
|
||
namespace Helpers { | ||
export type SplitButtonOptions = "a" | "b" | "c" | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars | ||
export const callback = (selectedOption: SplitButtonOptions): void => {} | ||
|
||
export const options: SplitButtonProps<SplitButtonOptions>["options"] = [ | ||
{ | ||
label: "test a", | ||
value: "a", | ||
}, | ||
{ | ||
label: "test b", | ||
value: "b", | ||
}, | ||
{ | ||
label: "test c", | ||
value: "c", | ||
}, | ||
] | ||
} | ||
|
||
describe("SplitButton", () => { | ||
describe("onClick", () => { | ||
it("is called when primary action is clicked", () => { | ||
// Given | ||
const mockedAndSpyedCallback = jest.fn(Helpers.callback) | ||
|
||
// When | ||
render(<SplitButton onClick={mockedAndSpyedCallback} options={Helpers.options} />) | ||
fireEvent.click(screen.getByText("test a")) | ||
|
||
// Then | ||
expect(mockedAndSpyedCallback.mock.calls.length).toBe(1) | ||
expect(mockedAndSpyedCallback.mock.calls[0][0]).toBe("a") | ||
}) | ||
|
||
it("is called when clicking option in pop-up", () => { | ||
// Given | ||
const mockedAndSpyedCallback = jest.fn(Helpers.callback) | ||
|
||
// When | ||
render(<SplitButton onClick={mockedAndSpyedCallback} options={Helpers.options} />) | ||
const buttons = screen.getAllByRole("button") | ||
const dropdownButton = buttons[1] | ||
fireEvent.click(dropdownButton) | ||
fireEvent.click(screen.getByText("test c")) | ||
|
||
// Then | ||
expect(mockedAndSpyedCallback.mock.calls.length).toBe(1) | ||
expect(mockedAndSpyedCallback.mock.calls[0][0]).toBe("c") | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { screen } from "@testing-library/react" | ||
import { render } from "../../test_helpers" | ||
import React from "react" | ||
import { EmptyState, EmptyStateProps } from "./index" | ||
|
||
describe("EmptyState", () => { | ||
it("renders (smoke test)", async () => { | ||
// When | ||
render(<EmptyState message="Hello, world" />) | ||
|
||
// Then | ||
await screen.findByText("Hello, world") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react" | ||
import { SvgIcon } from "@material-ui/core" | ||
import { render } from "./../../test_helpers" | ||
|
||
import * as Icons from "./index" | ||
|
||
const getAllIcons = (): [string, typeof SvgIcon][] => { | ||
let k: keyof typeof Icons | ||
let ret: [string, typeof SvgIcon][] = [] | ||
for (k in Icons) { | ||
ret.push([k, Icons[k]]) | ||
} | ||
return ret | ||
} | ||
|
||
describe("Icons", () => { | ||
const allIcons = getAllIcons() | ||
|
||
it.each(allIcons)(`rendering icon %p`, (_name, Icon) => { | ||
render(<Icon />) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from "react" | ||
import { screen } from "@testing-library/react" | ||
|
||
import { render } from "../../test_helpers" | ||
import { Navbar } from "./index" | ||
|
||
describe("Navbar", () => { | ||
it("renders content", async () => { | ||
// When | ||
render(<Navbar />) | ||
|
||
// Then | ||
await screen.findAllByText("Coder", { exact: false }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from "react" | ||
import { screen } from "@testing-library/react" | ||
|
||
import { render } from "../../test_helpers" | ||
import { Footer } from "./Footer" | ||
|
||
describe("Footer", () => { | ||
it("renders content", async () => { | ||
// When | ||
render(<Footer />) | ||
|
||
// Then | ||
await screen.findByText("Copyright", { exact: false }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1 @@ | ||
import React from "react" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
|
||
import { Footer } from "./Footer" | ||
import { Navbar } from "../Navbar" | ||
|
||
export const Page: React.FC<{ children: React.ReactNode }> = ({ children }) => { | ||
// TODO: More interesting styling here! | ||
|
||
const styles = useStyles() | ||
|
||
const header = ( | ||
<div className={styles.header}> | ||
<Navbar /> | ||
</div> | ||
) | ||
|
||
const footer = ( | ||
<div className={styles.footer}> | ||
<Footer /> | ||
</div> | ||
) | ||
|
||
const body = <div className={styles.body}> {children}</div> | ||
|
||
return ( | ||
<div className={styles.root}> | ||
{header} | ||
{body} | ||
{footer} | ||
</div> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
root: { | ||
display: "flex", | ||
flexDirection: "column", | ||
}, | ||
header: { | ||
flex: 0, | ||
}, | ||
body: { | ||
height: "100%", | ||
flex: 1, | ||
}, | ||
footer: { | ||
flex: 0, | ||
}, | ||
})) | ||
export * from "./Footer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.