Skip to content

Commit

Permalink
Better fuzz testing for PDF generation (#2965)
Browse files Browse the repository at this point in the history
* improvements to cypress pdf testing

* reuse cy.enableResponseFuzzing in start-app-instance

* enable fuzzing on subform pdf
  • Loading branch information
bjosttveit authored Feb 5, 2025
1 parent 0f3f3b8 commit 784baaa
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 141 deletions.
29 changes: 7 additions & 22 deletions test/e2e/integration/frontend-test/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('PDF', () => {

cy.testPdf({
snapshotName: 'message',
enableResponseFuzzing: true,
callback: () => {
cy.findByRole('heading', { level: 1, name: /frontend-test/i }).should('be.visible');
cy.findByRole('table').should('contain.text', 'Mottaker:Testdepartementet');
Expand Down Expand Up @@ -84,8 +85,7 @@ describe('PDF', () => {
{}, // intercept this every time
);

// Add a delay to simulate slow loading map tiles
cy.intercept('GET', '/map-tile/**', { delay: 50, fixture: 'map-tile.png' });
cy.intercept('GET', '/map-tile/**', { fixture: 'map-tile.png' });

cy.goto('changename');

Expand All @@ -109,6 +109,7 @@ describe('PDF', () => {
cy.testPdf({
snapshotName: 'changeName 1',
returnToForm: true,
enableResponseFuzzing: true,
callback: () => {
cy.findByRole('table').should('contain.text', 'Mottaker:Testdepartementet');
cy.getSummary('Nytt fornavn').should('contain.text', 'Ola');
Expand Down Expand Up @@ -151,6 +152,7 @@ describe('PDF', () => {

cy.testPdf({
snapshotName: 'changeName 2',
enableResponseFuzzing: true,
callback: () => {
cy.findByRole('table').should('contain.text', 'Mottaker:Testdepartementet');
cy.getSummary('Nytt fornavn').should('contain.text', 'Ola');
Expand All @@ -177,26 +179,6 @@ describe('PDF', () => {
});
});

it('options should load before #readyForPrint is shown', () => {
cy.goto('changename');
cy.dsSelect(appFrontend.changeOfName.sources, 'Digitaliseringsdirektoratet');
cy.dsSelect(appFrontend.changeOfName.reference, 'Sophie Salt');
cy.dsSelect(appFrontend.changeOfName.reference2, 'Dole');

cy.intercept(/.*\/options\/(list|references|test).*/, async (r) => {
await new Promise((resolve) => setTimeout(resolve, 3000));
r.continue();
});

cy.testPdf({
callback: () => {
cy.getSummary('hvor fikk du vite om skjemaet').should('contain.text', 'Digitaliseringsdirektoratet');
cy.getSummary('Referanse').should('contain.text', 'Sophie Salt');
cy.getSummary('Referanse 2').should('contain.text', 'Dole');
},
});
});

it('should generate PDF for group step', () => {
cy.goto('group');
cy.findByRole('checkbox', { name: /liten/i }).check();
Expand Down Expand Up @@ -226,6 +208,7 @@ describe('PDF', () => {

cy.testPdf({
snapshotName: 'group',
enableResponseFuzzing: true,
callback: () => {
cy.findByRole('table').should('contain.text', 'Mottaker:Testdepartementet');

Expand Down Expand Up @@ -256,6 +239,7 @@ describe('PDF', () => {

cy.testPdf({
snapshotName: 'likert',
enableResponseFuzzing: true,
callback: () => {
cy.findByRole('table').should('contain.text', 'Mottaker:Testdepartementet');

Expand All @@ -281,6 +265,7 @@ describe('PDF', () => {

cy.testPdf({
snapshotName: 'datalist',
enableResponseFuzzing: true,
callback: () => {
cy.findByRole('table').should('contain.text', 'Mottaker:Testdepartementet');
cy.getSummary('Hvem gjelder saken?').should('contain.text', 'Caroline');
Expand Down
1 change: 1 addition & 0 deletions test/e2e/integration/subform-test/subform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ describe('Subform test', () => {

cy.testPdf({
snapshotName: 'subform',
enableResponseFuzzing: true,
callback: () => {
cy.getSummary('Navn').should('contain.text', 'Per');
cy.getSummary('Alder').should('contain.text', '28 år');
Expand Down
Loading

0 comments on commit 784baaa

Please sign in to comment.