Skip to content

Commit

Permalink
fix wcag error and improve PDF testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bjosttveit committed Sep 3, 2024
1 parent 343bd85 commit 253be96
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
7 changes: 3 additions & 4 deletions src/layout/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,13 @@ export function Map({
{label && (
<Tooltip
permanent={true}
interactive={true}
content={label}
interactive={isInteractive}
direction='top'
eventHandlers={{
click: (e) => e.originalEvent.preventDefault(),
}}
>
{label}
</Tooltip>
/>
)}
</GeoJSON>
))}
Expand Down
6 changes: 4 additions & 2 deletions src/layout/Map/MapComponent.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@
}

/**
* This will give the map a square aspect ratio when loading the print page
* This will give the map an (almost) square aspect ratio when loading the print page
* Since it has @media only screen it will still scale to fit the page,
* but the initial fitBounds will not depend on the PDF-service's browser viewport
* Ideally, the browser's viewport would match the pages aspect ratio, as
* geometries could still be cut off for extremely narrow pages, and would have a lot of
* space on the right side for a landscape print, but for all "normal" portrait page formats
* this should work well.
* Additionally, for very wide pages the map tiles on the far right will not have a chance to
* load before the page prints, but you should at least see the relevant area.
**/
@media only screen {
.print-hack {
width: 40rem;
width: 42rem;
}
}

Expand Down
7 changes: 5 additions & 2 deletions test/e2e/integration/frontend-test/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,11 @@ describe('UI Components', () => {
it('Map component with simpleBinding', () => {
cy.intercept('GET', 'https://cache.kartverket.no/**/*.png', { fixture: 'map-tile.png' });
cy.intercept('GET', 'https://tile.openstreetmap.org/**/*.png', { fixture: 'map-tile.png' });
cy.interceptLayout('changename', (comp) => {
if (comp.id === 'map' && comp.type === 'Map') {
delete comp.dataModelBindings.geometries;
}
});

cy.goto('changename');
cy.get(appFrontend.changeOfName.newFirstName).type('123');
Expand Down Expand Up @@ -784,8 +789,6 @@ describe('UI Components', () => {
cy.interceptLayout('changename', (comp) => {
if (comp.id === 'map' && comp.type === 'Map') {
delete comp.dataModelBindings.simpleBinding;
delete comp.centerLocation;
delete comp.zoom;
}
});

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/integration/frontend-test/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('PDF', () => {
cy.getSummary('Adresse').should('contain.text', 'Økern 1');
cy.getSummary('Velg lokasjon').findByAltText('Marker').should('be.visible');
cy.getSummary('Velg lokasjon')
.findByText(/Valgt lokasjon: 59\.\d{6}° nord, 10\.\d{6}° øst/)
.findByText(/Valgt lokasjon: 67\.\d{6}° nord, 16\.\d{6}° øst/)
.should('be.visible');
});
});
Expand Down
29 changes: 21 additions & 8 deletions test/e2e/support/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,13 @@ const DEFAULT_COMMAND_TIMEOUT = Cypress.config().defaultCommandTimeout;
Cypress.Commands.add('testPdf', (snapshotName, callback, returnToForm = false) => {
cy.log('Testing PDF');

// Store initial viewport size for later
const size = { width: 0, height: 0 };
cy.window().then((win) => {
size.width = win.innerWidth;
size.height = win.innerHeight;
});

// Make sure instantiation is completed before we get the url
cy.location('hash').should('contain', '#/instance/');

Expand All @@ -544,21 +551,24 @@ Cypress.Commands.add('testPdf', (snapshotName, callback, returnToForm = false) =
cy.visit(visitUrl);
});

// Enable print media emulation
cy.then(() =>
Cypress.automation('remote:debugger:protocol', {
command: 'Emulation.setEmulatedMedia',
params: { media: 'print' },
}),
);

cy.readFile('test/percy.css').then((percyCSS) => {
cy.reload();

// Wait for readyForPrint, after this everything should be rendered so using timeout: 0
cy.get('#pdfView > #readyForPrint')
.should('exist')
.then(() => {
// Enable print media emulation
cy.then(() =>
Cypress.automation('remote:debugger:protocol', {
command: 'Emulation.setEmulatedMedia',
params: { media: 'print' },
}),
);
// Set viewport to A4 paper
cy.viewport(794, 1123);
cy.get('body').invoke('css', 'margin', '0.75in');

Cypress.config('defaultCommandTimeout', 0);

// Verify that generic elements that should be hidden are not present
Expand All @@ -585,6 +595,9 @@ Cypress.Commands.add('testPdf', (snapshotName, callback, returnToForm = false) =
params: {},
}),
);
// Revert to original viewport
cy.then(() => cy.viewport(size.width, size.height));
cy.get('body').invoke('css', 'margin', '');

cy.location('href').then((href) => {
cy.visit(href.replace('?pdf=1', ''));
Expand Down

0 comments on commit 253be96

Please sign in to comment.