Skip to content

Commit 1c049df

Browse files
committed
t
1 parent 6a34123 commit 1c049df

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

webapp/src/MobProgrammingRPG.integration.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const randomPort = () => {
99
return `${8000 + Math.floor(Math.random() * 100)}`;
1010
}
1111

12-
describe('Mob Programming RPG', () => {
12+
xdescribe('Mob Programming RPG', () => {
1313

1414
beforeAll(() => {
1515
global.IS_REACT_ACT_ENVIRONMENT = false;

webapp/src/RoleSheet.spec.tsx

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,66 @@
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";
23
import React from "react";
34
import { Player } from "./model/Player";
45
import { RoleSheet } from "./RoleSheet";
56
import { Role, levels, roles } from "./model/Roles";
67

78

89
describe('RoleSheet', () => {
9-
it(`shows Typing skills when in Typing position`, () => {
10+
it(`shows Typing todos when in Typing position`, () => {
1011
render(<RoleSheet role="Typing" position="Typing" player={new Player("Roger")} scorePoints={() => { }} />);
1112

1213
roles["Typing"].todos.forEach(todo => expect(screen.getByText(todo)).toBeInTheDocument())
1314
});
1415

15-
it(`shows Talking skills when in Talking position`, () => {
16+
it(`shows Talking todos when in Talking position`, () => {
1617
render(<RoleSheet role="Talking" position="Talking" player={new Player("Roger")} scorePoints={() => { }} />);
1718

1819
roles["Talking"].todos.forEach(todo => expect(screen.getByText(todo)).toBeInTheDocument())
1920
});
2021

21-
it(`shows Observing skills when in Observing position`, () => {
22+
it(`shows Observing todos when in Observing position`, () => {
2223
render(<RoleSheet role="Observing" position="Observing" player={new Player("Roger")} scorePoints={() => { }} />);
2324

2425
roles["Observing"].todos.forEach(todo => expect(screen.getByText(todo)).toBeInTheDocument())
2526
});
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+
})
2648
})
2749

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+
}
2864
// TODO if canEarnPoints for role, show skills of role
2965
// cannot rotate until players have filled the form
3066
// TODO use it.each ??? but maybe its too clever?

0 commit comments

Comments
 (0)