From 3aa49bd6e5ea293ac341e7070575761959265369 Mon Sep 17 00:00:00 2001 From: Les Date: Fri, 12 Jul 2024 14:36:42 +0200 Subject: [PATCH] fix test ids --- .../CandidatesVotesForm.test.tsx | 24 +++++++++---------- .../CandidatesVotesForm.tsx | 4 +--- frontend/lib/ui/InputGrid/InputGridRow.tsx | 1 + 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/frontend/app/component/form/candidates_votes_form/CandidatesVotesForm.test.tsx b/frontend/app/component/form/candidates_votes_form/CandidatesVotesForm.test.tsx index 33a587920..3eddeace1 100644 --- a/frontend/app/component/form/candidates_votes_form/CandidatesVotesForm.test.tsx +++ b/frontend/app/component/form/candidates_votes_form/CandidatesVotesForm.test.tsx @@ -62,7 +62,7 @@ describe("Test CandidatesVotesForm", () => { const user = userEvent.setup(); render(Component); - const candidate1 = screen.getByTestId("candidate-votes-1"); + const candidate1 = screen.getByTestId("candidate_votes-1.votes"); await user.clear(candidate1); await user.type(candidate1, "12345"); expect(candidate1).toHaveValue("12.345"); @@ -83,7 +83,7 @@ describe("Test CandidatesVotesForm", () => { render(Component); - const candidate1 = screen.getByTestId("candidate-votes-1"); + const candidate1 = screen.getByTestId("candidate_votes-1.votes"); expect(candidate1).toHaveFocus(); await user.clear(candidate1); await user.type(candidate1, "12345"); @@ -91,7 +91,7 @@ describe("Test CandidatesVotesForm", () => { await user.keyboard("{enter}"); - const candidate2 = screen.getByTestId("candidate-votes-2"); + const candidate2 = screen.getByTestId("candidate_votes-2.votes"); expect(candidate2).toHaveFocus(); await user.clear(candidate2); await user.type(candidate2, "6789"); @@ -99,7 +99,7 @@ describe("Test CandidatesVotesForm", () => { await user.keyboard("{enter}"); - const candidate3 = screen.getByTestId("candidate-votes-3"); + const candidate3 = screen.getByTestId("candidate_votes-3.votes"); expect(candidate3).toHaveFocus(); await user.clear(candidate3); await user.type(candidate3, "123"); @@ -107,7 +107,7 @@ describe("Test CandidatesVotesForm", () => { await user.keyboard("{enter}"); - const candidate4 = screen.getByTestId("candidate-votes-4"); + const candidate4 = screen.getByTestId("candidate_votes-4.votes"); expect(candidate4).toHaveFocus(); await user.clear(candidate4); await user.paste("4242"); @@ -115,7 +115,7 @@ describe("Test CandidatesVotesForm", () => { await user.keyboard("{enter}"); - const candidate5 = screen.getByTestId("candidate-votes-5"); + const candidate5 = screen.getByTestId("candidate_votes-5.votes"); expect(candidate5).toHaveFocus(); await user.clear(candidate5); await user.type(candidate5, "12"); @@ -123,7 +123,7 @@ describe("Test CandidatesVotesForm", () => { await user.keyboard("{enter}"); - const candidate6 = screen.getByTestId("candidate-votes-6"); + const candidate6 = screen.getByTestId("candidate_votes-6.votes"); expect(candidate6).toHaveFocus(); await user.clear(candidate6); // Test if maxLength on field works @@ -132,7 +132,7 @@ describe("Test CandidatesVotesForm", () => { await user.keyboard("{enter}"); - const candidate7 = screen.getByTestId("candidate-votes-7"); + const candidate7 = screen.getByTestId("candidate_votes-7.votes"); expect(candidate7).toHaveFocus(); await user.clear(candidate7); await user.type(candidate7, "3"); @@ -140,7 +140,7 @@ describe("Test CandidatesVotesForm", () => { await user.keyboard("{enter}"); - const total = screen.getByTestId("list-total"); + const total = screen.getByTestId("total"); await user.click(total); expect(total).toHaveFocus(); await user.clear(total); @@ -260,21 +260,21 @@ describe("Test CandidatesVotesForm", () => { render(Component); - const candidateOne = screen.getByTestId("candidate-votes-1"); + const candidateOne = screen.getByTestId("candidate_votes-1.votes"); await user.clear(candidateOne); await user.type( candidateOne, expectedRequest.data.political_group_votes[0]?.candidate_votes[0]?.votes.toString() ?? "0", ); - const candidateTwo = screen.getByTestId("candidate-votes-2"); + const candidateTwo = screen.getByTestId("candidate_votes-2.votes"); await user.clear(candidateTwo); await user.type( candidateTwo, expectedRequest.data.political_group_votes[0]?.candidate_votes[1]?.votes.toString() ?? "0", ); - const listTotal = screen.getByTestId("list-total"); + const listTotal = screen.getByTestId("total"); await user.clear(listTotal); await user.type( listTotal, diff --git a/frontend/app/component/form/candidates_votes_form/CandidatesVotesForm.tsx b/frontend/app/component/form/candidates_votes_form/CandidatesVotesForm.tsx index 522ccb492..77b7f75f5 100644 --- a/frontend/app/component/form/candidates_votes_form/CandidatesVotesForm.tsx +++ b/frontend/app/component/form/candidates_votes_form/CandidatesVotesForm.tsx @@ -40,8 +40,6 @@ export function CandidatesVotesForm({ group }: CandidatesVotesFormProps) { setTemporaryCache, } = usePoliticalGroup(group.number); - console.log(errors); - usePreventFormEnterSubmit(formRef); const getValues = React.useCallback( @@ -64,7 +62,6 @@ export function CandidatesVotesForm({ group }: CandidatesVotesFormProps) { const errorsAndWarnings = useErrorsAndWarnings(errors, warnings, inputMaskWarnings); - console.log(errorsAndWarnings); //const blocker = useBlocker() use const blocker to render confirmation UI. useBlocker(() => { if (formRef.current && !isCalled) { @@ -146,6 +143,7 @@ export function CandidatesVotesForm({ group }: CandidatesVotesFormProps) { format={format} addSeparator={addSeparator} defaultValue={defaultValue} + isFocused={index === 0} /> ); })} diff --git a/frontend/lib/ui/InputGrid/InputGridRow.tsx b/frontend/lib/ui/InputGrid/InputGridRow.tsx index 30e9e216b..17065d202 100644 --- a/frontend/lib/ui/InputGrid/InputGridRow.tsx +++ b/frontend/lib/ui/InputGrid/InputGridRow.tsx @@ -20,6 +20,7 @@ export interface InputGridRowProps { isTotal?: boolean; isFocused?: boolean; addSeparator?: boolean; + autoFocus?: boolean; } export function InputGridRow({