Skip to content

Commit

Permalink
tests for round-end and excluding main.jsx from coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexia-May committed Oct 24, 2024
1 parent db0aa24 commit b97b70c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
33 changes: 32 additions & 1 deletion frontend/tests/pages/RoundEnd.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe("Round end tests", () => {
const targetNumberEl = screen.getAllByText("Alexia(Host)");
expect(targetNumberEl).toBeDefined();
});

test("there is a next round button", () => {
render(
<RoundEnd gameState={gameState} pokemon={mockPokemon} redirect={""} setRedirect={setRedirect} />
Expand All @@ -95,6 +96,7 @@ describe("Round end tests", () => {
});
expect(nextRoundButtonEl).toBeDefined();
});

test("when the next round button is clicked it calls the socket", async () => {
render(
<RoundEnd gameState={gameState} pokemon={mockPokemon} redirect={""} setRedirect={setRedirect} />
Expand All @@ -106,6 +108,7 @@ describe("Round end tests", () => {
await user.click(nextRoundButtonEl);
expect(socket.emit).toHaveBeenCalledWith("next_round");
});

test("there is a quit game button button", () => {
render(
<RoundEnd gameState={gameState} pokemon={mockPokemon} redirect={""} setRedirect={setRedirect} />
Expand All @@ -114,6 +117,7 @@ describe("Round end tests", () => {
const quitGameButtonEl = screen.getByRole("button", { name: "Quit Game" });
expect(quitGameButtonEl).toBeDefined();
});

test("when the next quit button it calls socket and naviagte", async () => {
render(
<RoundEnd gameState={gameState} pokemon={mockPokemon} redirect={""} setRedirect={setRedirect} />
Expand All @@ -127,6 +131,7 @@ describe("Round end tests", () => {
expect(socket.emit).toHaveBeenCalledWith("quit_game", gameState.id);
expect(navigate).toHaveBeenCalledWith("/")
});

test("when the redirct state changes the user is redirect", () => {
render(
<RoundEnd gameState={gameState} pokemon={mockPokemon} redirect={"/test-route"} setRedirect={setRedirect} />
Expand All @@ -135,4 +140,30 @@ describe("Round end tests", () => {
expect(navigate).toHaveBeenCalledWith("/test-route")
expect(setRedirect).toHaveBeenCalledWith("")
})
});

test("when there is there is no winner, display prompt", () => {
const gameWithNoWinners = {
players: [
{
currentGuess: null,
id: "WHbOG6ET1uHeg-MqAAA8",
name: "Alexia(Host)",
totalScore: 0,
},
{
currentGuess: null,
id: "werjighig52-54252tgv",
name: "Lucy",
totalScore: 2,
},
],
targetNumber: 42,
currentRoundWinner: null
}
render(<RoundEnd gameState={gameWithNoWinners} pokemon={mockPokemon} redirect={""} setRedirect={setRedirect} />)

expect(screen.getByText("No one guessed in time!"))
expect(screen.getByText("Poor Sam..."))
});
})

3 changes: 2 additions & 1 deletion frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default defineConfig({
"**/vitest.{workspace,projects}.[jt]s?(on)",
"**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}",
"**/*.config.*",
"**/socket.js"
"**/socket.js",
"**/main.jsx"
],
},
},
Expand Down

0 comments on commit b97b70c

Please sign in to comment.