-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35f61e1
commit 789ed64
Showing
2 changed files
with
384 additions
and
1,087 deletions.
There are no files selected for viewing
42 changes: 29 additions & 13 deletions
42
packages/frontend/__tests__/App.test.tsx → packages/frontend/tests/App.test.tsx
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,95 +1,111 @@ | ||
import { render } from "@testing-library/react"; | ||
import { mocked } from "jest-mock"; | ||
import { MemoryRouter } from "react-router-dom"; | ||
import * as swr from "swr"; | ||
import { beforeAll, describe, expect, test, vi } from "vitest"; | ||
|
||
import { App } from "../src/App"; | ||
import { testData } from "./testData"; | ||
|
||
jest.mock("swr"); | ||
vi.mock("swr"); | ||
|
||
describe("App", () => { | ||
beforeAll(() => { | ||
window.scrollTo = jest.fn(); | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function -- Function mock | ||
vi.spyOn(window, "scrollTo").mockImplementation(() => {}); | ||
}); | ||
|
||
test("should render correctly", () => { | ||
mocked(swr).default.mockReturnValue({ | ||
expect.assertions(1); | ||
|
||
vi.mocked(swr).default.mockReturnValue({ | ||
data: testData, | ||
error: undefined, | ||
isLoading: false, | ||
isValidating: false, | ||
mutate: jest.fn(), | ||
mutate: vi.fn(), | ||
}); | ||
const { container } = render( | ||
<MemoryRouter> | ||
<App /> | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
test("should render projects correctly", () => { | ||
mocked(swr).default.mockReturnValue({ | ||
expect.assertions(1); | ||
|
||
vi.mocked(swr).default.mockReturnValue({ | ||
data: testData, | ||
error: undefined, | ||
isLoading: false, | ||
isValidating: false, | ||
mutate: jest.fn(), | ||
mutate: vi.fn(), | ||
}); | ||
const { container } = render( | ||
<MemoryRouter initialEntries={["/projekty"]}> | ||
<App /> | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
test("should render project listing correctly", () => { | ||
mocked(swr).default.mockReturnValue({ | ||
expect.assertions(1); | ||
|
||
vi.mocked(swr).default.mockReturnValue({ | ||
data: testData, | ||
error: undefined, | ||
isLoading: false, | ||
isValidating: false, | ||
mutate: jest.fn(), | ||
mutate: vi.fn(), | ||
}); | ||
const { container } = render( | ||
<MemoryRouter initialEntries={["/skaut/skaut-google-drive-gallery"]}> | ||
<App /> | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
test("should render issue listing correctly", () => { | ||
mocked(swr).default.mockReturnValue({ | ||
expect.assertions(1); | ||
|
||
vi.mocked(swr).default.mockReturnValue({ | ||
data: testData, | ||
error: undefined, | ||
isLoading: false, | ||
isValidating: false, | ||
mutate: jest.fn(), | ||
mutate: vi.fn(), | ||
}); | ||
const { container } = render( | ||
<MemoryRouter initialEntries={["/skaut/skaut-google-drive-gallery/3"]}> | ||
<App /> | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
test("should handle error gracefully", () => { | ||
mocked(swr).default.mockReturnValue({ | ||
expect.assertions(1); | ||
|
||
vi.mocked(swr).default.mockReturnValue({ | ||
data: undefined, | ||
error: true, | ||
isLoading: false, | ||
isValidating: false, | ||
mutate: jest.fn(), | ||
mutate: vi.fn(), | ||
}); | ||
const { container } = render( | ||
<MemoryRouter> | ||
<App /> | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.