-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRoleSheet.spec.tsx
More file actions
144 lines (107 loc) · 5.32 KB
/
RoleSheet.spec.tsx
File metadata and controls
144 lines (107 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { render, screen, act } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import React from "react";
import { Player } from "./model/Player";
import { RoleSheet } from "./RoleSheet";
import { roles } from "./model/Roles";
describe('RoleSheet', () => {
it(`shows Typing todos when in Typing position`, () => {
render(<RoleSheet role="Typing" position="Typing" player={new Player("Roger")} scorePoints={() => { }} />);
roles["Typing"].todos.forEach(todo => expect(screen.getByText(todo)).toBeInTheDocument())
});
it(`shows Talking todos when in Talking position`, () => {
render(<RoleSheet role="Talking" position="Talking" player={new Player("Roger")} scorePoints={() => { }} />);
roles["Talking"].todos.forEach(todo => expect(screen.getByText(todo)).toBeInTheDocument())
});
it(`shows Observing todos when in Observing position`, () => {
render(<RoleSheet role="Observing" position="Observing" player={new Player("Roger")} scorePoints={() => { }} />);
roles["Observing"].todos.forEach(todo => expect(screen.getByText(todo)).toBeInTheDocument())
});
it(`shows Other Roles todos when in Observing position`, () => {
const roger = new Player("Roger");
roger.scoreTimes("Typing", 3);
roger.selectRole("Sponsor");
render(<RoleSheet role="Sponsor" position="Observing" player={roger} scorePoints={() => { }} />);
roles["Sponsor"].todos.forEach(todo => expect(screen.getByText(todo)).toBeInTheDocument())
});
it(`scores a single point using the checkboxes when submitting`, async () => {
const mockScorePoints = jest.fn();
render(<RoleSheet role="Typing" position="Typing" player={new Player("Roger")} scorePoints={mockScorePoints} />);
await checkTodo('Typing-0');
await clickEarnPoints();
expect(mockScorePoints).toHaveBeenCalledWith("Typing", 1);
})
it(`scores two points using the checkboxes when submitting`, async () => {
const mockScorePoints = jest.fn();
render(<RoleSheet role="Typing" position="Typing" player={new Player("Roger")} scorePoints={mockScorePoints} />);
await checkTodo('Typing-0');
await checkTodo('Typing-1');
await clickEarnPoints();
expect(mockScorePoints).toHaveBeenCalledWith("Typing", 2);
})
it(`scores two points Talking using the checkboxes when submitting`, async () => {
const mockScorePoints = jest.fn();
render(<RoleSheet role="Talking" position="Talking" player={new Player("Roger")} scorePoints={mockScorePoints} />);
await checkTodo('Talking-0');
await checkTodo('Talking-1');
await clickEarnPoints();
expect(mockScorePoints).toHaveBeenCalledWith("Talking", 2);
})
it(`after scoring points todo checkboxes are reset`, async () => {
render(<RoleSheet role="Talking" position="Talking" player={new Player("Roger")} scorePoints={jest.fn()} />);
await checkTodo('Talking-0');
await checkTodo('Talking-1');
await clickEarnPoints();
expectUnchecked('Talking-0');
expectUnchecked('Talking-1');
})
it(`earn button stays when no todos are marked`, async () => {
const mockScorePoints = jest.fn();
render(<RoleSheet role="Typing" position="Typing" player={new Player("Roger")} scorePoints={mockScorePoints} />);
const earnPointsButton = screen.getByLabelText('Earn Points');
expect(earnPointsButton).toBeInTheDocument();
await clickEarnPoints();
expect(mockScorePoints).toHaveBeenCalledTimes(0);
expect(earnPointsButton).toBeInTheDocument();
})
it(`earn button remains visible after earning points`, async () => {
const mockScorePoints = jest.fn();
render(<RoleSheet role="Typing" position="Typing" player={new Player("Roger")} scorePoints={mockScorePoints} />);
await checkTodo('Typing-0');
await clickEarnPoints();
expect(mockScorePoints).toHaveBeenCalledWith("Typing", 1);
expect(screen.getByLabelText('Earn Points')).toBeInTheDocument();
})
it('hides earn button when role does not match position', () => {
render(
<RoleSheet
role="Talking"
position="Typing"
player={new Player("Roger")}
scorePoints={jest.fn()}
/>
);
expect(screen.queryByLabelText('Earn Points')).not.toBeInTheDocument();
});
})
async function checkTodo(todo) {
const firstCheckbox = document.getElementById(todo) as HTMLInputElement;
await act(async () => {
userEvent.click(firstCheckbox);
});
}
async function clickEarnPoints() {
const submitButton = screen.getByLabelText('Earn Points');
await act(async () => {
userEvent.click(submitButton);
});
}
function expectUnchecked(todoId) {
const checkbox = document.getElementById(todoId) as HTMLInputElement;
expect(checkbox.checked).toBe(false);
}
// TODO if canEarnPoints for role, show skills of role
// cannot rotate until players have filled the form
// TODO use it.each ??? but maybe its too clever?
// rename role.todo to skills (might be used in other places)
// now we use <div>, but its semantically a list (should use <li>)