Skip to content

Commit

Permalink
add frontend state
Browse files Browse the repository at this point in the history
  • Loading branch information
kshen0 committed Mar 7, 2024
1 parent 0edaf4d commit 1437ff2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
13 changes: 13 additions & 0 deletions apps/mark-scan/frontend/src/app_root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import { PatDeviceCalibrationPage } from './pages/pat_device_identification/pat_
import { CastingBallotPage } from './pages/casting_ballot_page';
import { BallotSuccessfullyCastPage } from './pages/ballot_successfully_cast_page';
import { EmptyBallotBoxPage } from './pages/empty_ballot_box_page';
import { PollWorkerAuthEndedUnexpectedlyPage } from './pages/poll_worker_auth_ended_unexpectedly_page';

interface VotingState {
votes?: VotesDict;
Expand Down Expand Up @@ -439,6 +440,18 @@ export function AppRoot({
return <JamClearedPage stateMachineState={stateMachineState} />;
}

const isInPaperLoadingStage =
stateMachineState === 'accepting_paper' ||
stateMachineState === 'loading_paper';
if (
stateMachineState === 'poll_worker_auth_ended_unexpectedly' ||
// Handle when the frontend auth state is up to date but the state machine state is not
(isInPaperLoadingStage &&
(isCardlessVoterAuth(authStatus) || authStatus.status === 'logged_out'))
) {
return <PollWorkerAuthEndedUnexpectedlyPage />;
}

if (optionalElectionDefinition && precinctSelection) {
if (
authStatus.status === 'logged_out' &&
Expand Down
42 changes: 40 additions & 2 deletions apps/mark-scan/frontend/src/app_states.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ test('`empty_ballot_box` state renders EmptyBallotBoxPage', async () => {
await screen.findByText('Ballot Box Full');
});

const testSpecs: Array<{
const ballotCastPageTestSpecs: Array<{
state: SimpleServerStatus;
}> = [
{ state: 'ballot_accepted' },
{ state: 'resetting_state_machine_after_success' },
];

test.each(testSpecs)(
test.each(ballotCastPageTestSpecs)(
'$state state renders BallotSuccessfullyCastPage',
async ({ state }) => {
apiMock.mockApiClient.getElectionState.reset();
Expand All @@ -253,3 +253,41 @@ test.each(testSpecs)(
await screen.findByText('Thank you for voting.');
}
);

const authEndedEarlyPageTestSpecs: Array<{
state: SimpleServerStatus;
auth: 'cardless_voter' | 'logged_out';
}> = [
{ state: 'poll_worker_auth_ended_unexpectedly', auth: 'cardless_voter' },
{ state: 'poll_worker_auth_ended_unexpectedly', auth: 'logged_out' },
{ state: 'accepting_paper', auth: 'cardless_voter' },
{ state: 'accepting_paper', auth: 'logged_out' },
{ state: 'loading_paper', auth: 'cardless_voter' },
{ state: 'loading_paper', auth: 'logged_out' },
];

test.each(authEndedEarlyPageTestSpecs)(
'$state state renders PollWorkerAuthEndedUnexpectedlyPage',
async ({ state, auth }) => {
apiMock.setPaperHandlerState(state);
if (auth === 'cardless_voter') {
apiMock.setAuthStatusCardlessVoterLoggedInWithDefaults(
electionDefinition
);
} else {
apiMock.setAuthStatusLoggedOut();
}

render(
<App
hardware={hardware}
apiClient={apiMock.mockApiClient}
reload={jest.fn()}
/>
);

await screen.findByText(
'The poll worker card was removed before paper loading completed. Please try again.'
);
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { appStrings, P } from '@votingworks/ui';
import { CenteredPageLayout } from '../components/centered_page_layout';

export function PollWorkerAuthEndedUnexpectedlyPage(): JSX.Element {
return (
<CenteredPageLayout title={appStrings.noteBmdSessionRestart()} voterFacing>
<P>{appStrings.notePollWorkerAuthEndedBeforePaperLoadComplete()}</P>
</CenteredPageLayout>
);
}
7 changes: 7 additions & 0 deletions libs/ui/src/ui_strings/app_strings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,13 @@ export const appStrings = {
<UiString uiStringKey="noteVoterSettingsAudioUnmuted">Audio is on</UiString>
),

notePollWorkerAuthEndedBeforePaperLoadComplete: () => (
<UiString uiStringKey="notePollWorkerAuthEndedBeforePaperLoadComplete">
The poll worker card was removed before paper loading completed. Please
try again.
</UiString>
),

promptBmdConfirmRemoveWriteIn: () => (
<UiString uiStringKey="promptBmdConfirmRemoveWriteIn">
Do you want to deselect and remove your write-in candidate?
Expand Down
1 change: 1 addition & 0 deletions libs/ui/src/ui_strings/app_strings_catalog/latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"noteBmdPatCalibrationStep2": "Step 2 of 3",
"noteBmdPatCalibrationStep3": "Step 3 of 3",
"noteBmdSessionRestart": "Your voting session will restart shortly.",
"notePollWorkerAuthEndedBeforePaperLoadComplete": "The poll worker card was removed before paper loading completed. Please try again.",
"noteScannerBlankContestsCardPlural": "Did you mean to leave these contests blank?",
"noteScannerBlankContestsCardSingular": "Did you mean to leave this contest blank?",
"noteScannerOvervoteContestsCardPlural": "Your votes in these contests will not be counted.",
Expand Down

0 comments on commit 1437ff2

Please sign in to comment.