Skip to content

Commit 228c617

Browse files
committed
f
1 parent 7a1e132 commit 228c617

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

.roo/.rules/general.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Answering Rules
2+
ALWAYS start your answers with a STARTING_CHARACTER
3+
The default STARTING_CHARACTER is 🐙
4+
5+
I prefer SHORT, SUCCINCT and CONCISE answers over long ones
6+
7+
# Coding Rules
8+
NEVER USE COMMENTS
9+
10+
declare and assign variables as close as possible to where they are used
11+
12+
I prefer SIMPLE design with fewer elements
13+
14+
run the tests after each change using just `npm test`

webapp/src/RoleSheet.spec.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ describe('RoleSheet', () => {
5656

5757
expect(mockScorePoints).toHaveBeenCalledWith("Talking", 2);
5858
})
59+
60+
it(`earn button stays when no todos are marked`, async () => {
61+
const mockScorePoints = jest.fn();
62+
render(<RoleSheet role="Typing" position="Typing" player={new Player("Roger")} scorePoints={mockScorePoints} />);
63+
64+
const earnPointsButton = screen.getByLabelText('Earn Points');
65+
expect(earnPointsButton).toBeInTheDocument();
66+
67+
await clickEarnPoints();
68+
69+
expect(mockScorePoints).toHaveBeenCalledTimes(0);
70+
expect(earnPointsButton).toBeInTheDocument();
71+
})
72+
5973
})
6074

6175

@@ -67,7 +81,8 @@ async function checkTodo(todo) {
6781
}
6882

6983
async function clickEarnPoints() {
70-
const submitButton = screen.getByRole('button', { name: /Earn Points/ });
84+
// Find the submit button within the form by its aria-label
85+
const submitButton = screen.getByLabelText('Earn Points');
7186
await act(async () => {
7287
userEvent.click(submitButton);
7388
});

webapp/src/RoleSheet.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ export function RoleSheet({
2121

2222
function onSubmitCheckboxes(e) {
2323
e.preventDefault();
24-
// Only count checkboxes within this specific form for this role
2524
const checkboxes = e.target.querySelectorAll(`input[type="checkbox"][id^="${role}-"]:checked`);
2625
const amount = checkboxes.length;
27-
scorePoints(role, amount);
28-
setPointsScored(true);
26+
if(amount > 0) {
27+
scorePoints(role, amount);
28+
setPointsScored(true);
29+
}
2930
}
3031

3132
return <div className="role">
@@ -43,14 +44,16 @@ export function RoleSheet({
4344
<EarnPointsForRole role={role} scorePoints={scorePoints} />
4445
<div>
4546
<form onSubmit={onSubmitCheckboxes}>
46-
{role == position && roles[role].todos.map((s, index) => <div key={s}>
47-
<input type="checkbox" id={`${role}-${index}`} className="earn-points-checkbox" style={{float: "left", display: "block", marginTop: "6px", width: "9%", minHeight: "20px"}} />
48-
<div style={{marginLeft: "32px", margin: "4px", padding: "4px"}}>{s}</div>
49-
</div>)}
47+
{role == position && roles[role].todos.map((todo, index) =>
48+
<div key={todo}>
49+
<input type="checkbox" id={`${role}-${index}`} className="earn-points-checkbox" style={{float: "left", display: "block", marginTop: "6px", width: "9%", minHeight: "20px"}} />
50+
<div style={{marginLeft: "32px", margin: "4px", padding: "4px"}}>{todo}</div>
51+
</div>
52+
)}
5053

5154
{!pointsScored && (
5255
<button
53-
className="rpgui-button add-points-button"
56+
className="rpgui-button"
5457
aria-label={"Earn Points"}>
5558
<p>Earn</p>
5659
</button>

0 commit comments

Comments
 (0)