Skip to content

Commit

Permalink
test(design): re-enable some more tests (#6017)
Browse files Browse the repository at this point in the history
  • Loading branch information
eventualbuddha authored Feb 13, 2025
1 parent 287cc3a commit efc4245
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 186 deletions.
30 changes: 23 additions & 7 deletions apps/design/backend/src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import { ElectionRecord } from '.';
import { ElectionPackage, getTempBallotLanguageConfigsForCert } from './store';
import { renderBallotStyleReadinessReport } from './ballot_style_reports';
import { BALLOT_STYLE_READINESS_REPORT_FILE_NAME } from './app';
import { join } from 'node:path';

vi.setConfig({
testTimeout: 60_000,
Expand Down Expand Up @@ -1285,7 +1286,7 @@ test.skip('setBallotTemplate changes the ballot template used to render ballots'
).toHaveLength(props.length);
});

test.skip('v3-compatible election package', async () => {
test('v3-compatible election package', async () => {
// This test runs unnecessarily long if we're generating exports for all
// languages, so disabling multi-language support for this case:
mockFeatureFlagger.disableFeatureFlag(
Expand All @@ -1308,19 +1309,31 @@ test.skip('v3-compatible election package', async () => {
ballotTemplateId: 'NhBallotV3',
});

const electionPackageFilePath = await exportElectionPackage({
const electionPackageAndBallotsFileName = await exportElectionPackage({
user: vxUser,
fileStorageClient,
apiClient,
electionId,
workspace,
electionSerializationFormat: 'vxf',
});
const zipFile = await openZip(readFileSync(electionPackageFilePath));
const entries = getEntries(zipFile);
const electionPackageAndBallotsZip = await openZip(
fileStorageClient.getRawFile(
join(vxUser.orgId, electionPackageAndBallotsFileName)
)!
);
const electionPackageAndBallotsZipEntries = getEntries(
electionPackageAndBallotsZip
);
const electionPackageZipBuffer = await find(
electionPackageAndBallotsZipEntries,
(entry) => entry.name.startsWith('election-package')
).async('nodebuffer');
const electionPackageZip = await openZip(electionPackageZipBuffer);
const electionPackageZipEntries = getEntries(electionPackageZip);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const election: any = await readJsonEntry(
getFileByName(entries, ElectionPackageFileName.ELECTION)
getFileByName(electionPackageZipEntries, ElectionPackageFileName.ELECTION)
);
// Date should be off-by-one to account for timezone bug in v3
expect(fixtureElection.date.toISOString()).toEqual('2021-06-06');
Expand All @@ -1329,7 +1342,10 @@ test.skip('v3-compatible election package', async () => {
// System settings should have field names matching v3 format
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const systemSettings: any = await readJsonEntry(
getFileByName(entries, ElectionPackageFileName.SYSTEM_SETTINGS)
getFileByName(
electionPackageZipEntries,
ElectionPackageFileName.SYSTEM_SETTINGS
)
);
expect(Object.keys(systemSettings)).toEqual([
'auth',
Expand All @@ -1340,5 +1356,5 @@ test.skip('v3-compatible election package', async () => {
]);

// No other files included
expect(entries.length).toEqual(2);
expect(electionPackageAndBallotsZipEntries.length).toEqual(2);
});
14 changes: 6 additions & 8 deletions apps/design/backend/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class MockAuthClient extends AuthClient {
class MockFileStorageClient implements FileStorageClient {
private mockFiles: Record<string, Buffer> = {};

getRawFile(filePath: string): Buffer | undefined {
return this.mockFiles[filePath];
}

async readFile(
filePath: string
): Promise<Result<Readable, FileStorageClientError>> {
Expand Down Expand Up @@ -183,7 +187,7 @@ export async function processNextBackgroundTaskIfAny({
}

export const ELECTION_PACKAGE_FILE_NAME_REGEX =
/election-package-([0-9a-z]{7})-([0-9a-z]{7})\.zip$/;
/election-package-and-ballots-([0-9a-z]{7})-([0-9a-z]{7})\.zip$/;

export async function exportElectionPackage({
user,
Expand Down Expand Up @@ -213,13 +217,7 @@ export async function exportElectionPackage({
const electionPackage = await apiClient.getElectionPackage({
electionId,
});
const electionPackageFileName = assertDefined(
return assertDefined(
assertDefined(electionPackage.url).match(ELECTION_PACKAGE_FILE_NAME_REGEX)
)[0];
const electionPackageFilePath = path.join(
workspace.assetDirectoryPath,
electionPackageFileName
);

return electionPackageFilePath;
}
7 changes: 0 additions & 7 deletions apps/design/frontend/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,4 @@

src/app.test.tsx
src/contests_screen.test.tsx
src/election_info_screen.test.tsx
src/elections_screen.test.tsx
src/geography_screen.test.tsx
src/image_input.test.tsx
src/features_context.test.tsx
src/export_screen.test.tsx
test/api_helpers.tsx
test/fixtures.ts
2 changes: 1 addition & 1 deletion apps/design/frontend/src/ballot_order_info_screen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ vi.useFakeTimers({
now: mockDateTime,
});

const electionRecord = generalElectionRecord;
const electionRecord = generalElectionRecord(nonVxUser.orgId);
const electionId = electionRecord.election.id;

let apiMock: MockApiClient;
Expand Down
13 changes: 7 additions & 6 deletions apps/design/frontend/src/ballot_screen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import { withRoute } from '../test/routing_helpers';
import { routes } from './routes';
import { BallotScreen } from './ballot_screen';

const electionId = generalElectionRecord.election.id;
const ballotStyle = generalElectionRecord.ballotStyles[0];
const precinct = generalElectionRecord.precincts[0];
const electionRecord = generalElectionRecord(nonVxUser.orgId);
const electionId = electionRecord.election.id;
const ballotStyle = electionRecord.ballotStyles[0];
const precinct = electionRecord.precincts[0];

function MockDocument({
children,
Expand Down Expand Up @@ -88,7 +89,7 @@ test('shows a PDF ballot preview', async () => {
apiMock.getUser.expectCallWith().resolves(nonVxUser);
apiMock.getElection
.expectCallWith({ user: nonVxUser, electionId })
.resolves(generalElectionRecord);
.resolves(electionRecord);
apiMock.getBallotPreviewPdf
.expectCallWith({
electionId,
Expand Down Expand Up @@ -155,7 +156,7 @@ test('changes ballot type', async () => {
apiMock.getUser.expectCallWith().resolves(nonVxUser);
apiMock.getElection
.expectCallWith({ user: nonVxUser, electionId })
.resolves(generalElectionRecord);
.resolves(electionRecord);
apiMock.getBallotPreviewPdf
.expectCallWith({
electionId,
Expand Down Expand Up @@ -209,7 +210,7 @@ test('changes tabulation mode', async () => {
apiMock.getUser.expectCallWith().resolves(nonVxUser);
apiMock.getElection
.expectCallWith({ user: nonVxUser, electionId })
.resolves(generalElectionRecord);
.resolves(electionRecord);
apiMock.getBallotPreviewPdf
.expectCallWith({
electionId,
Expand Down
36 changes: 21 additions & 15 deletions apps/design/frontend/src/ballots_screen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ function renderScreen(electionId: ElectionId) {

describe('Ballot styles tab', () => {
test('General election with splits', async () => {
const electionId = generalElectionRecord.election.id;
const electionRecord = generalElectionRecord(nonVxUser.orgId);
const electionId = electionRecord.election.id;
apiMock.getUser.expectCallWith().resolves(nonVxUser);
apiMock.getElection
.expectCallWith({ user: nonVxUser, electionId })
.resolves(generalElectionRecord);
.resolves(electionRecord);
apiMock.getBallotsFinalizedAt.expectCallWith({ electionId }).resolves(null);
renderScreen(electionId);
await screen.findByRole('heading', { name: 'Proof Ballots' });
Expand Down Expand Up @@ -77,11 +78,12 @@ describe('Ballot styles tab', () => {
});

test('Primary election with splits', async () => {
const electionId = primaryElectionRecord.election.id;
const electionRecord = primaryElectionRecord(nonVxUser.orgId);
const electionId = electionRecord.election.id;
apiMock.getUser.expectCallWith().resolves(nonVxUser);
apiMock.getElection
.expectCallWith({ user: nonVxUser, electionId })
.resolves(primaryElectionRecord);
.resolves(electionRecord);
apiMock.getBallotsFinalizedAt.expectCallWith({ electionId }).resolves(null);
renderScreen(electionId);
await screen.findByRole('heading', { name: 'Proof Ballots' });
Expand Down Expand Up @@ -121,13 +123,14 @@ describe('Ballot styles tab', () => {
});

test('Precincts/splits with no ballot styles show a message', async () => {
const record = generalElectionRecord(nonVxUser.orgId);
const electionRecord: ElectionRecord = {
...generalElectionRecord,
ballotStyles: generalElectionRecord.ballotStyles.filter(
...record,
ballotStyles: record.ballotStyles.filter(
(ballotStyle) => ballotStyle.id === '2_en'
),
};
const electionId = generalElectionRecord.election.id;
const electionId = electionRecord.election.id;
apiMock.getUser.expectCallWith().resolves(nonVxUser);
apiMock.getElection
.expectCallWith({ user: nonVxUser, electionId })
Expand Down Expand Up @@ -156,11 +159,12 @@ describe('Ballot styles tab', () => {
});

test('Finalizing ballots', async () => {
const electionId = generalElectionRecord.election.id;
const electionRecord = generalElectionRecord(nonVxUser.orgId);
const electionId = electionRecord.election.id;
apiMock.getUser.expectCallWith().resolves(nonVxUser);
apiMock.getElection
.expectCallWith({ user: nonVxUser, electionId })
.resolves(generalElectionRecord);
.resolves(electionRecord);
apiMock.getBallotsFinalizedAt
.expectOptionalRepeatedCallsWith({ electionId })
.resolves(null);
Expand Down Expand Up @@ -198,13 +202,14 @@ describe('Ballot styles tab', () => {
});

test('Ballot layout tab - VX User', async () => {
const { election } = generalElectionRecord;
const electionRecord = generalElectionRecord(vxUser.orgId);
const { election } = electionRecord;
const electionId = election.id;

apiMock.getUser.expectCallWith().resolves(vxUser);
apiMock.getElection
.expectCallWith({ user: vxUser, electionId })
.resolves(generalElectionRecord);
.resolves(electionRecord);
apiMock.getBallotsFinalizedAt.expectCallWith({ electionId }).resolves(null);
renderScreen(electionId);
await screen.findByRole('heading', { name: 'Proof Ballots' });
Expand Down Expand Up @@ -255,7 +260,7 @@ test('Ballot layout tab - VX User', async () => {
})
.resolves();
apiMock.getElection.expectCallWith({ user: vxUser, electionId }).resolves({
...generalElectionRecord,
...electionRecord,
election: updatedElection,
});
userEvent.click(screen.getByRole('button', { name: /Save/ }));
Expand All @@ -265,13 +270,14 @@ test('Ballot layout tab - VX User', async () => {
});

test('Ballot layout tab - NH User', async () => {
const { election } = generalElectionRecord;
const electionRecord = generalElectionRecord(nonVxUser.orgId);
const { election } = electionRecord;
const electionId = election.id;

apiMock.getUser.expectCallWith().resolves(nonVxUser);
apiMock.getElection
.expectCallWith({ user: nonVxUser, electionId })
.resolves(generalElectionRecord);
.resolves(electionRecord);
apiMock.getBallotsFinalizedAt.expectCallWith({ electionId }).resolves(null);
renderScreen(electionId);
await screen.findByRole('heading', { name: 'Proof Ballots' });
Expand Down Expand Up @@ -318,7 +324,7 @@ test('Ballot layout tab - NH User', async () => {
})
.resolves();
apiMock.getElection.expectCallWith({ user: nonVxUser, electionId }).resolves({
...generalElectionRecord,
...electionRecord,
election: updatedElection,
});
userEvent.click(screen.getByRole('button', { name: /Save/ }));
Expand Down
Loading

0 comments on commit efc4245

Please sign in to comment.