-
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
85719e5
commit f63ea22
Showing
8 changed files
with
93 additions
and
22 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,19 +1,89 @@ | ||
import { beforeEach, describe, expect, it } from "vitest"; | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import { expect } from "vitest"; | ||
import { render, screen } from "@testing-library/react"; | ||
import Progress from "./Progress"; | ||
import { mock } from "vitest-mock-extended"; | ||
import useMembers from "../../hooks/useMembers"; | ||
import { test, vi } from "vitest"; | ||
import { Member } from "../../api/services/common/types"; | ||
|
||
vi.mock("../../hooks/useMembers"); | ||
|
||
test("render the site header", () => { | ||
vi.mocked(useMembers).mockReturnValue( | ||
mock({ isLoading: false, error: null, members: [] }), | ||
mock({ | ||
isLoading: false, | ||
error: null, | ||
members: [mock<Member>({ id: "sam", solvedProblems: [] })], | ||
}), | ||
); | ||
|
||
vi.stubGlobal("location", { | ||
href: `http://example.com?member=sam`, | ||
search: `?member=sam`, | ||
}); | ||
|
||
render(<Progress />); | ||
|
||
const header = screen.getByRole("banner"); | ||
expect(header).toBeInTheDocument(); | ||
}); | ||
|
||
test("display error message if member is not found", () => { | ||
vi.mocked(useMembers).mockReturnValue( | ||
mock({ isLoading: false, error: null, members: [] }), | ||
); | ||
|
||
render(<Progress />); | ||
|
||
const errorMessage = screen.getByText("Member not found!"); | ||
expect(errorMessage).toBeInTheDocument(); | ||
}); | ||
|
||
test("display member is not found when query paramemer is not passed", () => { | ||
vi.mocked(useMembers).mockReturnValue( | ||
mock({ isLoading: false, error: null, members: [] }), | ||
); | ||
vi.stubGlobal("location", { | ||
href: "http://example.com", | ||
}); | ||
render(<Progress />); | ||
|
||
const errorMessage = screen.getByText("Member not found!"); | ||
expect(errorMessage).toBeInTheDocument(); | ||
}); | ||
|
||
test("render page when query parameter is passed", async () => { | ||
const mockedMember = mock<Member>(); | ||
const mockedQueryParam = "evan"; | ||
|
||
mockedMember.id = mockedQueryParam; | ||
mockedMember.name = "soundmin"; | ||
mockedMember.solvedProblems = [ | ||
{ title: "Problem 1", difficulty: "easy" }, | ||
{ title: "Problem 2", difficulty: "medium" }, | ||
{ title: "Problem 3", difficulty: "easy" }, | ||
]; | ||
|
||
vi.mocked(useMembers).mockReturnValue( | ||
mock({ | ||
isLoading: false, | ||
error: null, | ||
members: [mockedMember], | ||
}), | ||
); | ||
|
||
vi.stubGlobal("location", { | ||
href: `http://example.com?member=${mockedQueryParam}`, | ||
search: `?member=${mockedQueryParam}`, | ||
}); | ||
|
||
render(<Progress />); | ||
|
||
// Assert that the error message is not shown | ||
const errorMessage = screen.queryByText("Member not found!"); | ||
expect(errorMessage).not.toBeInTheDocument(); | ||
|
||
// Wait for the member's name to appear | ||
const userNameElement = await screen.findByText(mockedMember.name); | ||
expect(userNameElement).toBeInTheDocument(); | ||
}); |
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