Skip to content

Commit 0bd4a02

Browse files
authored
Merge branch 'staging' into 10434-story
2 parents 7dfe2a5 + 40575eb commit 0bd4a02

20 files changed

+154
-298
lines changed

cypress/local-only/tests/integration/fileAPetition/petitions-clerk-creates-paper-case.cy.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import { unchecksOrdersAndNoticesBoxesInCase } from '../../../support/pages/unch
1919

2020
describe('Petition clerk creates a paper filing', function () {
2121
describe('Create and submit a paper petition', () => {
22+
beforeEach(() => {
23+
cy.window().then(win => {
24+
cy.stub(win, 'open').as('windowOpen');
25+
});
26+
});
2227
it('should create a paper petition', () => {
2328
navigateToDocumentQC('petitionsclerk');
2429

@@ -43,23 +48,17 @@ describe('Petition clerk creates a paper filing', function () {
4348
it('should display attachment links in the attachment section', () => {
4449
cy.get('[data-testid="petitionFileButton"]').should('be.visible');
4550
cy.get('[data-testid="petitionFileButton"]').click();
46-
cy.get('[data-testid="modal-dialog-header"]').should('be.visible');
47-
cy.get('[data-testid="close-modal-button"]').click();
4851
cy.get('[data-testid="stinFileDisplay"]').should('be.visible');
4952
cy.get('[data-testid="stinFileDisplay"]').should('not.be.enabled');
5053

5154
cy.get('[data-testid="requestForPlaceOfTrialFileButton"]').should(
5255
'be.visible',
5356
);
5457
cy.get('[data-testid="requestForPlaceOfTrialFileButton"]').click();
55-
cy.get('[data-testid="modal-dialog-header"]').should('be.visible');
56-
cy.get('[data-testid="close-modal-button"]').click();
5758
cy.get('[data-testid="attachmentToPetitionFileButton"]').should(
5859
'be.visible',
5960
);
6061
cy.get('[data-testid="attachmentToPetitionFileButton"]').click();
61-
cy.get('[data-testid="modal-dialog-header"]').should('be.visible');
62-
cy.get('[data-testid="close-modal-button"]').click();
6362
});
6463

6564
it('should display Orders/Notices Automatically Created notification', () => {

shared/src/business/useCases/loadPDFForPreviewInteractor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const loadPDFForPreviewInteractor = async (
1313
docketEntryId,
1414
docketNumber,
1515
}: { docketEntryId?: string; docketNumber?: string },
16-
): Promise<void> => {
16+
): Promise<Blob> => {
1717
try {
1818
return await applicationContext.getPersistenceGateway().getDocument({
1919
applicationContext,

web-client/integration-tests/journey/respondentRequestsAccessToCase.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@ export const respondentRequestsAccessToCase = (cerebralTest, fakeFile) => {
112112
);
113113
expect(cerebralTest.getState('validationErrors')).toEqual({});
114114

115-
await cerebralTest.runSequence('openPdfPreviewModalSequence', {
116-
file: fakeFile,
117-
modalId: 'PDFPreviewModal-Entry of Appearance for Respondent',
118-
});
119-
120115
await cerebralTest.runSequence('updateFormValueSequence', {
121116
key: 'redactionAcknowledgement',
122117
value: true,
Lines changed: 45 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,44 @@
11
import { applicationContextForClient as applicationContext } from '@web-client/test/createClientTestApplicationContext';
2-
import { loadPdfAction } from './loadPdfAction';
2+
import { loadPdfForTabAction } from '../PDFPreviewTab/loadPdfForTabAction';
3+
import { openUrlInNewTab } from '@web-client/presenter/utilities/openUrlInNewTab';
34
import { presenter } from '../../presenter-mock';
45
import { runAction } from '@web-client/presenter/test.cerebral';
56
import { testPdfDoc } from '../../../../../shared/src/business/test/getFakeFile';
67

7-
describe('loadPdfAction', () => {
8-
global.Blob = function () {};
8+
jest.mock('@web-client/presenter/utilities/openUrlInNewTab');
9+
10+
describe('loadPdfForTabAction', () => {
11+
let originalWindowOpen;
912

1013
const fakeFile = testPdfDoc;
1114
const b64File = `data:application/pdf;base64,${Buffer.from(
12-
String.fromCharCode.apply(null, fakeFile),
15+
String.fromCharCode(...fakeFile),
1316
).toString('base64')}`;
1417

1518
const mocks = {
16-
readAsArrayBufferMock: jest.fn().mockImplementation(async function () {
19+
readAsArrayBufferMock: jest.fn().mockImplementation(async function (this: {
20+
result: any;
21+
onload: any;
22+
}) {
1723
this.result = fakeFile;
1824
await this.onload();
1925
}),
20-
readAsDataURLMock: jest.fn().mockImplementation(async function () {
26+
readAsDataURLMock: jest.fn().mockImplementation(async function (this: {
27+
result: any;
28+
onload: any;
29+
}) {
2130
this.result = b64File;
2231
await this.onload();
2332
}),
2433
};
2534

26-
/**
27-
* Mock FileReader Implementation
28-
*/
29-
function MockFileReader() {
30-
this.onload = null;
31-
this.onerror = null;
32-
this.readAsDataURL = mocks.readAsDataURLMock;
33-
this.readAsArrayBuffer = mocks.readAsArrayBufferMock;
35+
class MockFileReader {
36+
public result: unknown = null;
37+
public onload: any;
38+
public onerror: any;
39+
40+
readAsDataURL = mocks.readAsDataURLMock;
41+
readAsArrayBuffer = mocks.readAsArrayBufferMock;
3442
}
3543

3644
beforeAll(() => {
@@ -44,98 +52,76 @@ describe('loadPdfAction', () => {
4452
);
4553
presenter.providers.applicationContext = applicationContext;
4654
presenter.providers.router = {
47-
createObjectURL: jest.fn(),
55+
createObjectURL: jest.fn().mockReturnValue('some url'),
4856
};
57+
originalWindowOpen = window.open;
58+
(openUrlInNewTab as jest.Mock).mockImplementation(jest.fn());
59+
window.open = jest.fn();
4960
});
5061

51-
it('should detect binary (not base64-encoded) pdf data and read it successfully', async () => {
52-
const result = await runAction(loadPdfAction, {
62+
afterAll(() => {
63+
window.open = originalWindowOpen;
64+
jest.restoreAllMocks();
65+
});
66+
67+
it('should call window.open with correcturl for pdf file', async () => {
68+
await runAction(loadPdfForTabAction, {
5369
modules: {
5470
presenter,
5571
},
56-
props: {
57-
file: fakeFile,
58-
},
59-
state: {
60-
pdfPreviewModal: {},
61-
},
72+
props: { file: fakeFile },
6273
});
6374

64-
expect(mocks.readAsArrayBufferMock).toHaveBeenCalled();
65-
expect(result.state.modal.pdfPreviewModal.error).toBeUndefined();
75+
expect(openUrlInNewTab).toHaveBeenCalledWith({ url: 'some url' });
6676
});
6777

68-
it('should detect base64-encoded pdf data and read it successfully', async () => {
69-
const result = await runAction(loadPdfAction, {
78+
it('should detect binary (not base64-encoded) pdf data and read it successfully', async () => {
79+
await runAction(loadPdfForTabAction, {
7080
modules: {
7181
presenter,
7282
},
7383
props: {
74-
file: b64File,
75-
},
76-
state: {
77-
pdfPreviewModal: {},
84+
file: fakeFile,
7885
},
7986
});
8087

81-
expect(mocks.readAsDataURLMock).toHaveBeenCalled();
82-
expect(result.state.modal.pdfPreviewModal.error).toBeUndefined();
88+
expect(mocks.readAsArrayBufferMock).toHaveBeenCalled();
8389
});
8490

8591
it('should return an error when given an invalid pdf', async () => {
8692
presenter.providers.router.createObjectURL.mockImplementationOnce(() => {
8793
throw new Error('bad pdf data');
8894
});
8995
await expect(
90-
runAction(loadPdfAction, {
96+
runAction(loadPdfForTabAction, {
9197
modules: {
9298
presenter,
9399
},
94100
props: {
95101
file: 'data:binary/pdf,INVALID-BYTES',
96102
},
97-
state: { pdfPreviewModal: {} },
98103
}),
99104
).rejects.toThrow('bad pdf data');
100105
});
101106

102107
it('should error out when the FileReader fails', async () => {
103-
mocks.readAsArrayBufferMock.mockImplementationOnce(function () {
108+
mocks.readAsArrayBufferMock.mockImplementationOnce(function (this: {
109+
result: any;
110+
onerror: any;
111+
}) {
104112
this.result = 'abc';
105113
this.onerror(new Error('An error called via reader.onerror.'));
106114
});
107115

108116
await expect(
109-
runAction(loadPdfAction, {
117+
runAction(loadPdfForTabAction, {
110118
modules: {
111119
presenter,
112120
},
113121
props: {
114122
file: 'this my file',
115123
},
116-
state: {
117-
pdfPreviewModal: {},
118-
},
119124
}),
120125
).rejects.toThrow('An error called via reader.onerror.');
121126
});
122-
123-
it('sets the pdfPreviewUrl on state from the given file', async () => {
124-
presenter.providers.router.createObjectURL.mockReturnValue('fakePdfUri');
125-
126-
const result = await runAction(loadPdfAction, {
127-
modules: {
128-
presenter,
129-
},
130-
props: {
131-
file: b64File,
132-
},
133-
state: {
134-
modal: { pdfPreviewModal: { error: 'Some Error' } },
135-
},
136-
});
137-
138-
expect(result.state.modal.pdfPreviewModal.error).toBeUndefined();
139-
expect(result.state.pdfPreviewUrl).toEqual('fakePdfUri');
140-
});
141127
});

web-client/src/presenter/actions/PDFPreviewModal/loadPdfAction.ts renamed to web-client/src/presenter/actions/PDFPreviewTab/loadPdfForTabAction.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,18 @@
1-
import { state } from '@web-client/presenter/app.cerebral';
2-
3-
/**
4-
* loads the pdf for being used in preview modal
5-
*
6-
* @param {object} providers the providers object
7-
* @param {object} providers.store the cerebral store object
8-
* @param {Function} providers.props the cerebral props object
9-
* @returns {Promise} promise which resolves if it successfully loads the pdf
10-
*/
11-
export const loadPdfAction = ({
1+
import { openUrlInNewTab } from '../../utilities/openUrlInNewTab';
2+
export const loadPdfForTabAction = ({
123
applicationContext,
134
props,
145
router,
15-
store,
166
}: ActionProps) => {
177
const { file } = props;
188
const isBase64Encoded = typeof file === 'string' && file.startsWith('data');
199

20-
store.set(state.modal.pdfPreviewModal, {});
21-
22-
return new Promise((resolve, reject) => {
10+
return new Promise<void>((resolve, reject) => {
2311
const reader = applicationContext.getFileReaderInstance();
2412

2513
reader.onload = () => {
26-
let binaryFile;
27-
if (isBase64Encoded) {
14+
let binaryFile: string | ArrayBuffer | null;
15+
if (isBase64Encoded && reader.result === 'string') {
2816
const base64File = reader.result.replace(/[^,]+,/, '');
2917
binaryFile = atob(base64File);
3018
} else {
@@ -33,23 +21,22 @@ export const loadPdfAction = ({
3321

3422
try {
3523
const pdfDataUri = router.createObjectURL(
24+
// @ts-ignore
3625
new Blob([binaryFile], { type: 'application/pdf' }),
3726
);
38-
store.set(state.pdfPreviewUrl, pdfDataUri);
39-
store.unset(state.modal.pdfPreviewModal.error);
27+
openUrlInNewTab({ url: pdfDataUri });
4028
resolve();
4129
} catch (err) {
42-
store.set(state.modal.pdfPreviewModal.error, err);
4330
reject(err);
4431
}
4532
};
4633

4734
reader.onerror = function (err) {
48-
store.set(state.modal.pdfPreviewModal.error, err);
4935
reject(err);
5036
};
5137

5238
if (isBase64Encoded) {
39+
// @ts-ignore
5340
reader.readAsDataURL(file);
5441
} else {
5542
reader.readAsArrayBuffer(file);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { applicationContextForClient as applicationContext } from '@web-client/test/createClientTestApplicationContext';
2+
import { getPDFForPreviewTabAction } from './getPDFForPreviewTabAction';
3+
import { presenter } from '../presenter-mock';
4+
import { runAction } from '@web-client/presenter/test.cerebral';
5+
6+
describe('getPDFForPreviewTabAction', () => {
7+
beforeAll(() => {
8+
presenter.providers.applicationContext = applicationContext;
9+
applicationContext
10+
.getUseCases()
11+
.loadPDFForPreviewInteractor.mockResolvedValue('fake file data');
12+
});
13+
14+
it('returns original props if we already have what appears to be an actual file', async () => {
15+
const props = { file: { name: 'name of a file on a real file object' } };
16+
const result = await runAction(getPDFForPreviewTabAction, {
17+
modules: {
18+
presenter,
19+
},
20+
props,
21+
state: {},
22+
});
23+
expect(result.props).toEqual(props);
24+
expect(
25+
applicationContext.getUseCases().loadPDFForPreviewInteractor,
26+
).not.toHaveBeenCalled();
27+
});
28+
29+
it('returns results from loadPDFForPreviewInteractor if provided a docketNumber and docketEntryId', async () => {
30+
const props = { file: { docketEntryId: '456' } };
31+
await runAction(getPDFForPreviewTabAction, {
32+
modules: {
33+
presenter,
34+
},
35+
props,
36+
state: {
37+
caseDetail: {
38+
docketNumber: '123-20',
39+
},
40+
},
41+
});
42+
expect(
43+
applicationContext.getUseCases().loadPDFForPreviewInteractor.mock
44+
.calls[0][1],
45+
).toMatchObject({
46+
docketEntryId: '456',
47+
docketNumber: '123-20',
48+
});
49+
});
50+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { state } from '@web-client/presenter/app.cerebral';
2+
3+
export const getPDFForPreviewTabAction = async ({
4+
applicationContext,
5+
get,
6+
props,
7+
}: ActionProps) => {
8+
if (props.file.name) {
9+
return props;
10+
}
11+
const { docketEntryId } = props.file;
12+
const docketNumber = get(state.caseDetail.docketNumber);
13+
14+
const pdfObj = await applicationContext
15+
.getUseCases()
16+
.loadPDFForPreviewInteractor(applicationContext, {
17+
docketEntryId,
18+
docketNumber,
19+
});
20+
return { file: pdfObj };
21+
};

web-client/src/presenter/actions/openCaseDocumentDownloadUrlAction.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { state } from '@web-client/presenter/app.cerebral';
22

3-
/**
4-
* opens the document in a new tab
5-
* @param {object} providers the providers object
6-
* @param {object} providers.props the cerebral props object
7-
* @param {object} providers.store the cerebral store object used for clearing alertError, alertSuccess
8-
*/
93
export const openCaseDocumentDownloadUrlAction = async ({
104
applicationContext,
115
props,

web-client/src/presenter/computeds/fileDocumentHelper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export const fileDocumentHelper = (
119119
supportingDocumentTypeList,
120120
...showSecondaryProperties,
121121
...supportingDocumentFlags,
122+
docketNumber: caseDetail.docketNumber,
122123
};
123124

124125
if (form.hasSupportingDocuments) {

0 commit comments

Comments
 (0)