|
1 | | -import { render, screen } from "@testing-library/react"; |
| 1 | +import { render, screen, act } from "@testing-library/react"; |
| 2 | +import userEvent from "@testing-library/user-event"; |
2 | 3 | import React from "react"; |
3 | 4 | import { Player } from "./model/Player"; |
4 | 5 | import { RoleSheet } from "./RoleSheet"; |
5 | 6 | import { Role, levels, roles } from "./model/Roles"; |
6 | 7 |
|
7 | 8 |
|
8 | 9 | describe('RoleSheet', () => { |
9 | | - it(`shows Typing skills when in Typing position`, () => { |
| 10 | + it(`shows Typing todos when in Typing position`, () => { |
10 | 11 | render(<RoleSheet role="Typing" position="Typing" player={new Player("Roger")} scorePoints={() => { }} />); |
11 | 12 |
|
12 | 13 | roles["Typing"].todos.forEach(todo => expect(screen.getByText(todo)).toBeInTheDocument()) |
13 | 14 | }); |
14 | 15 |
|
15 | | - it(`shows Talking skills when in Talking position`, () => { |
| 16 | + it(`shows Talking todos when in Talking position`, () => { |
16 | 17 | render(<RoleSheet role="Talking" position="Talking" player={new Player("Roger")} scorePoints={() => { }} />); |
17 | 18 |
|
18 | 19 | roles["Talking"].todos.forEach(todo => expect(screen.getByText(todo)).toBeInTheDocument()) |
19 | 20 | }); |
20 | 21 |
|
21 | | - it(`shows Observing skills when in Observing position`, () => { |
| 22 | + it(`shows Observing todos when in Observing position`, () => { |
22 | 23 | render(<RoleSheet role="Observing" position="Observing" player={new Player("Roger")} scorePoints={() => { }} />); |
23 | 24 |
|
24 | 25 | roles["Observing"].todos.forEach(todo => expect(screen.getByText(todo)).toBeInTheDocument()) |
25 | 26 | }); |
| 27 | + |
| 28 | + it(`scores a single point using the checkboxes when submitting`, async () => { |
| 29 | + const mockScorePoints = jest.fn(); |
| 30 | + render(<RoleSheet role="Typing" position="Typing" player={new Player("Roger")} scorePoints={mockScorePoints} />); |
| 31 | + await checkTodo('Typing-0'); |
| 32 | + |
| 33 | + await clickEarnPoints(); |
| 34 | + |
| 35 | + expect(mockScorePoints).toHaveBeenCalledWith("Typing", 1); |
| 36 | + }) |
| 37 | + |
| 38 | + it(`scores two points using the checkboxes when submitting`, async () => { |
| 39 | + const mockScorePoints = jest.fn(); |
| 40 | + render(<RoleSheet role="Typing" position="Typing" player={new Player("Roger")} scorePoints={mockScorePoints} />); |
| 41 | + await checkTodo('Typing-0'); |
| 42 | + await checkTodo('Typing-1'); |
| 43 | + |
| 44 | + await clickEarnPoints(); |
| 45 | + |
| 46 | + expect(mockScorePoints).toHaveBeenCalledWith("Typing", 2); |
| 47 | + }) |
26 | 48 | }) |
27 | 49 |
|
| 50 | + |
| 51 | +async function clickEarnPoints() { |
| 52 | + const submitButton = screen.getByRole('button', { name: /Earn Points/ }); |
| 53 | + await act(async () => { |
| 54 | + userEvent.click(submitButton); |
| 55 | + }); |
| 56 | +} |
| 57 | + |
| 58 | +async function checkTodo(todo) { |
| 59 | + const firstCheckbox = document.getElementById(todo) as HTMLInputElement; |
| 60 | + await act(async () => { |
| 61 | + userEvent.click(firstCheckbox); |
| 62 | + }); |
| 63 | +} |
28 | 64 | // TODO if canEarnPoints for role, show skills of role |
29 | 65 | // cannot rotate until players have filled the form |
30 | 66 | // TODO use it.each ??? but maybe its too clever? |
|
0 commit comments