-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: test case & coverage setup for todo app with vitest
- Loading branch information
1 parent
ec96f4e
commit 6889dd2
Showing
10 changed files
with
3,597 additions
and
81 deletions.
There are no files selected for viewing
3,563 changes: 3,487 additions & 76 deletions
3,563
examples/apps/todo/web/react-vite-tailwind/package-lock.json
Large diffs are not rendered by default.
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
16 changes: 16 additions & 0 deletions
16
examples/apps/todo/web/react-vite-tailwind/src/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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import App from "./App"; | ||
import { render, screen, userEvent } from "./utils/test-utils"; | ||
|
||
describe("App component", () => { | ||
it("should render header component", () => { | ||
render(<App />); | ||
const headerTitle = screen.getByText("All todos"); | ||
expect(headerTitle).toBeInTheDocument(); | ||
}); | ||
|
||
it("should open dialog on click of Create new", async () => { | ||
render(<App />); | ||
userEvent.click(screen.getByTestId("create-new-btn")); | ||
expect(await screen.findAllByText(/Create A New Task/i)).toBeTruthy(); | ||
}); | ||
}); |
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
41 changes: 41 additions & 0 deletions
41
examples/apps/todo/web/react-vite-tailwind/src/test/mocks/handlers.ts
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,41 @@ | ||
import { HttpResponse, http } from "msw"; | ||
|
||
// Mock Data | ||
export const todos = [ | ||
{ | ||
_id: "65ad0a17fde2eb089b1fdcc3", | ||
title: "Vitae veritatis quod.", | ||
description: | ||
"Blanditiis dicta rerum delectus harum esse. Quasi voluptates tempore accusamus quae architecto dolor nisi velit molestias. Incidunt praesentium nam inventore blanditiis nam. Magni quae harum. Doloremque adipisci ducimus. Tempore suscipit fuga provident possimus cum velit dolorem autem. Rem odio cumque nesciunt. Tempora dicta sint modi soluta voluptates consectetur eos tempora enim. Nesciunt veniam iusto aliquid maiores at repellat dolor est. Distinctio ullam occaecati consequuntur incidunt assumenda.", | ||
isComplete: false, | ||
__v: 0, | ||
createdAt: "2024-01-21T12:12:07.392Z", | ||
updatedAt: "2024-01-21T12:12:07.392Z", | ||
}, | ||
{ | ||
_id: "65ad0a17fde2eb089b1fdcc4", | ||
title: "Culpa praesentium blanditiis.", | ||
description: | ||
"Occaecati eius voluptatem corporis quasi incidunt. Dolores dolorum eum molestias culpa tempore. Asperiores eos nostrum doloremque blanditiis sed doloribus ipsam totam perferendis. Laborum accusamus incidunt enim quisquam ea quis modi beatae. Similique in voluptate neque aliquam deleniti laborum. Ex cum ab doloribus quasi quas. Possimus consequatur quae. Inventore quibusdam saepe officiis repellendus blanditiis odio. Possimus fugiat quidem perferendis tempore at soluta unde voluptate. Dicta non ipsam dolores quo. Numquam alias soluta placeat minima occaecati pariatur. Vitae quidem consequuntur pariatur voluptatibus laboriosam in fuga ut. Corrupti dolores perspiciatis animi alias odio. Eos nulla consequatur eaque consectetur fuga beatae at.", | ||
isComplete: true, | ||
__v: 0, | ||
createdAt: "2024-01-21T12:12:07.392Z", | ||
updatedAt: "2024-01-21T12:12:07.392Z", | ||
}, | ||
{ | ||
_id: "65ad0a17fde2eb089b1fdcc5", | ||
title: "Quos quisquam totam.", | ||
description: | ||
"Corporis officia eius. Assumenda accusamus corrupti tenetur quam. Alias cupiditate perferendis molestias possimus. Consequuntur odit architecto repellendus aliquid doloremque dicta. Provident illo culpa provident explicabo. Totam numquam dolor reiciendis. Ipsum asperiores iste saepe. Hic minus blanditiis animi exercitationem voluptatibus quaerat. A architecto similique in officiis aspernatur deserunt quibusdam quae eum. Eum explicabo eius ipsum fugiat voluptatem. Est fuga distinctio. Repellendus deserunt nam fugit sit exercitationem assumenda sunt. Dolores architecto at. Harum deleniti quod iste. Quo facere ea quam consequatur.", | ||
isComplete: false, | ||
__v: 0, | ||
createdAt: "2024-01-21T12:12:07.392Z", | ||
updatedAt: "2024-01-21T12:12:07.392Z", | ||
}, | ||
]; | ||
|
||
export const handlers = [ | ||
http.get(`${import.meta.env.VITE_SERVER_URL}/todos`, () => { | ||
return HttpResponse.json(todos, { status: 200 }); | ||
}), | ||
]; |
4 changes: 4 additions & 0 deletions
4
examples/apps/todo/web/react-vite-tailwind/src/test/mocks/server.ts
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,4 @@ | ||
import { setupServer } from 'msw/node' | ||
import { handlers } from './handlers' | ||
|
||
export const server = setupServer(...handlers) |
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,6 @@ | ||
import '@testing-library/jest-dom'; | ||
import {server} from './mocks/server'; | ||
|
||
beforeAll(() => server.listen({onUnhandledRequest: 'error'})); | ||
afterAll(() => server.close()); | ||
afterEach(() => server.resetHandlers()); |
19 changes: 19 additions & 0 deletions
19
examples/apps/todo/web/react-vite-tailwind/src/utils/test-utils.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { cleanup, render } from '@testing-library/react' | ||
import { afterEach } from 'vitest' | ||
|
||
afterEach(() => { | ||
cleanup() | ||
}) | ||
|
||
function customRender(ui: React.ReactElement, options = {}) { | ||
return render(ui, { | ||
// wrap provider(s) here if needed | ||
wrapper: ({ children }) => children, | ||
...options, | ||
}) | ||
} | ||
|
||
export * from '@testing-library/react' | ||
export { default as userEvent } from '@testing-library/user-event' | ||
// override render export | ||
export { customRender as render } |
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