Skip to content

Commit

Permalink
Extend end-to-end tests
Browse files Browse the repository at this point in the history
- Allow configuration of the local IIIF server port so multiple servers can run at the same time
- Extend collections tests to check if multiple child manifests can be loaded successively
- Add basic tests for TIFY's API
  • Loading branch information
t11r committed May 26, 2023
1 parent 49e96f2 commit 2060024
Show file tree
Hide file tree
Showing 14 changed files with 7,040 additions and 46 deletions.
5 changes: 4 additions & 1 deletion cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { defineConfig } = require('cypress');

// TODO: Should this be placed elsewhere?
process.env.iiifApiPort = 8082;
require('./tests/iiif-api/server');

module.exports = defineConfig({
Expand All @@ -17,4 +17,7 @@ module.exports = defineConfig({
downloadsFolder: 'tests/e2e/downloads',
supportFile: false,
},
env: {
iiifApiUrl: `http://0.0.0.0:${process.env.iiifApiPort}`,
},
});
20 changes: 20 additions & 0 deletions tests/e2e/api.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// TODO: Extend API tests

describe('API', () => {
it('controls TIFY programmatically', () => {
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/gdz-PPN857449303`);

cy.window().its('tify').then((tify) => {
tify.ready.then(() => {
tify.setLanguage('de');
cy.contains('Seiten');

tify.setPage(2);
cy.contains('.tify-page-select-button', '2 : -');

tify.setView('export');
cy.contains('.-active', 'Export');
});
});
});
});
17 changes: 11 additions & 6 deletions tests/e2e/collection.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Collection', () => {
it('shows the collection view', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/wellcome-b19974760');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/wellcome-b19974760`);

// Only Info and Collection buttons should be visible
cy.contains('Info');
Expand All @@ -16,23 +16,28 @@ describe('Collection', () => {
});

it('filters the collection list', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/wellcome-b19974760');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/wellcome-b19974760`);

cy.get('[aria-label="Filter collection"]').type('2008');
cy.get('.tify-collection-item').should('have.length', 2);
cy.get('[aria-label="Filter collection"]').type('nope');
cy.contains('No results');
});

it('loads the specified child manifest', () => {
it('loads a child manifest', () => {
const encodedParams = encodeURIComponent(JSON.stringify({
childManifestUrl: 'http://0.0.0.0:8081/manifest/wellcome-b19974760_1_0004',
childManifestUrl: `${Cypress.env('iiifApiUrl')}/manifest/wellcome-b19974760_1_0004`,
}));

cy.visit(`/?manifest=http://0.0.0.0:8081/manifest/wellcome-b19974760&tify=${encodedParams}`);
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/wellcome-b19974760&tify=${encodedParams}`);

cy.contains('Info').click();
cy.contains('.tify-info-button', 'Collection').click();
cy.contains('The chemist and druggist.');
cy.contains('h1', 'The chemist and druggist, 15. September 1859');

cy.contains('.tify-header-button', 'Collection').click();
cy.contains('Volume 1').click();
cy.contains('15. October 1859').click();
cy.contains('h1', 'The chemist and druggist, 15. October 1859');
});
});
2 changes: 1 addition & 1 deletion tests/e2e/export.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Export', () => {
it('displays export links', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/gdz-PPN857449303');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/gdz-PPN857449303`);

cy.contains('Export').click();
cy.contains('Download Individual Images').should('be.visible');
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/fulltext.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
describe('Fulltext', () => {
it('displays fulltext', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/wellcome-b18035723&tify={"pages":[15]}');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/wellcome-b18035723&tify={"pages":[15]}`);
cy.get('.tify').then(() => {
cy.contains('Fulltext').click();
cy.contains('Alles höhere Leben - ob Tier oder').should('be.visible');
});
});

it('displays XML fulltext', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/gdz-PPN235181684_0029&tify={"view":"fulltext"}');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/gdz-PPN235181684_0029&tify={"view":"fulltext"}`);
cy.get('.tify').then(() => {
cy.contains('Unter Mitwirkung der Herren').should('be.visible');
});
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/info.spec.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
describe('Info', () => {
it('displays related metadata', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/wellcome-b18035723');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/wellcome-b18035723`);
cy.contains('Info').click();
cy.contains('Related Resources');
cy.contains('Wunder der Vererbung / von Fritz Bolle.');

cy.visit('/?manifest=http://0.0.0.0:8081/manifest/ubl-0000000001');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/ubl-0000000001`);
cy.contains('Info').click();
cy.contains('Related Resources');
cy.contains('/object/viewid/0000000001');
cy.contains('/0000000001/manifest');
});

it('collapses long metadata values', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/gdz-HANS_DE_7_w042081');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/gdz-HANS_DE_7_w042081`);
cy.contains('button', 'Expand');
});

it('shows metadata of the current structure', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/gdz-PPN857449303');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/gdz-PPN857449303`);
cy.contains('Info').click();
cy.contains('Current Element').should('be.visible');
cy.contains('Titelseite');
Expand All @@ -28,7 +28,7 @@ describe('Info', () => {
});

it('shows metadata of a nested structure', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/gdz-DE_611_BF_5619_1801_1806');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/gdz-DE_611_BF_5619_1801_1806`);
cy.contains('Info').click();
cy.get('[title="Next page"]').first()
.click()
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/main.spec.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
describe('Main', () => {
it('starts the app', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/gdz-PPN857449303&language=de');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/gdz-PPN857449303&language=de`);
cy.get('#tify > .tify');
});

it('checks the manifest (valid JSON, but not IIIF)', () => {
// Prevent the test from failing due to an uncaught exception (which is expected)
cy.on('uncaught:exception', () => false);

cy.visit('/?manifest=http://0.0.0.0:8081/manifest/invalid');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/invalid`);
cy.contains('Please provide a valid IIIF Presentation API 2.x manifest');
});

it('checks the manifest (invalid JSON)', () => {
// Prevent the test from failing due to an uncaught exception (which is expected)
cy.on('uncaught:exception', () => false);

cy.visit('/?manifest=http://0.0.0.0:8081/manifest/not-json');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/not-json`);
cy.contains('Error loading IIIF manifest');
});
});
6 changes: 3 additions & 3 deletions tests/e2e/pagination.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ describe('Pagination', () => {
const currentPage = '.tify-page-select-button';

it('changes the page via buttons', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/gdz-HANS_DE_7_w042081&tify={"pages":[15]}');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/gdz-HANS_DE_7_w042081&tify={"pages":[15]}`);

cy.contains(currentPage, '15 : 7r');

Expand Down Expand Up @@ -30,7 +30,7 @@ describe('Pagination', () => {
});

it('changes the page via keyboard', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/gdz-HANS_DE_7_w042081&tify={"pages":[15]}');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/gdz-HANS_DE_7_w042081&tify={"pages":[15]}`);

cy.contains(currentPage, '15 : 7r');

Expand Down Expand Up @@ -71,7 +71,7 @@ describe('Pagination', () => {
});

it('highlights the current page after a page change', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/gdz-HANS_DE_7_w042081');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/gdz-HANS_DE_7_w042081`);
cy.get('[title="Last page"]').first().click();
cy.get('[aria-label="Current page"]').first().click();
cy.contains('.-current.-highlighted', '69 : -');
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/scan.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Scan', () => {
},
}));

cy.visit(`/?manifest=http://0.0.0.0:8081/manifest/gdz-HANS_DE_7_w042081&tify=${encodedParams}`);
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/gdz-HANS_DE_7_w042081&tify=${encodedParams}`);
cy.get('[title="Toggle image filters"]')
.click()
.get('.tify-scan-filters-popup')
Expand All @@ -28,21 +28,21 @@ describe('Scan', () => {
zoom: 2,
}));

cy.visit(`/?manifest=http://0.0.0.0:8081/manifest/gdz-HANS_DE_7_w042081&tify=${encodedParams}`);
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/gdz-HANS_DE_7_w042081&tify=${encodedParams}`);

cy.get('[title="Rotate"].-active');
cy.get('[title="Toggle image filters"].-active');

cy.get('.tify').type('{shift}0');
cy.url().should(
'include',
`/?manifest=${encodeURIComponent('http://0.0.0.0:8081/manifest/gdz-HANS_DE_7_w042081')}`
`/?manifest=${encodeURIComponent(`${Cypress.env('iiifApiUrl')}/manifest/gdz-HANS_DE_7_w042081`)}`
+ `&tify=${encodeURIComponent('{"view":""}')}`,
);
});

it('controls the scan via keyboard', () => {
cy.visit('/?manifest=http://0.0.0.0:8081/manifest/gdz-HANS_DE_7_w042081');
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/gdz-HANS_DE_7_w042081`);

cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting

Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/toc.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('TOC', () => {
it('allows navigation', () => {
const manifestUrl = 'http://0.0.0.0:8081/manifest/gdz-HANS_DE_7_w042081';
const manifestUrl = `${Cypress.env('iiifApiUrl')}/manifest/gdz-HANS_DE_7_w042081`;
cy.visit(`/?manifest=${manifestUrl}`);

cy.contains('Contents').click();
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('TOC', () => {
});

it('is visible when there are structures without canvases', () => {
const manifestUrl = 'http://0.0.0.0:8081/manifest/cambridge-MS-ADD-08640';
const manifestUrl = `${Cypress.env('iiifApiUrl')}/manifest/cambridge-MS-ADD-08640`;
const encodedParams = encodeURIComponent(JSON.stringify({
view: 'toc',
}));
Expand All @@ -63,7 +63,7 @@ describe('TOC', () => {
});

it('hides the first item if its viewingHint is "top"', () => {
const manifestUrl = 'http://0.0.0.0:8081/manifest/digitale-sammlungen-bsb00026283';
const manifestUrl = `${Cypress.env('iiifApiUrl')}/manifest/digitale-sammlungen-bsb00026283`;
const encodedParams = encodeURIComponent(JSON.stringify({
view: 'toc',
}));
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/views.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
describe('Views', () => {
it('changes the view via buttons', () => {
const encodedParams = encodeURIComponent(JSON.stringify({
childManifestUrl: 'http://0.0.0.0:8081/manifest/wellcome-b19974760_1_0004',
childManifestUrl: `${Cypress.env('iiifApiUrl')}/manifest/wellcome-b19974760_1_0004`,
}));

cy.visit(`/?manifest=http://0.0.0.0:8081/manifest/wellcome-b19974760&tify=${encodedParams}`);
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/wellcome-b19974760&tify=${encodedParams}`);

cy.contains('Fulltext').click();
cy.get('.-active').contains('Fulltext');
Expand All @@ -30,10 +30,10 @@ describe('Views', () => {

it('changes the view via keyboard', () => {
const encodedParams = encodeURIComponent(JSON.stringify({
childManifestUrl: 'http://0.0.0.0:8081/manifest/wellcome-b19974760_1_0004',
childManifestUrl: `${Cypress.env('iiifApiUrl')}/manifest/wellcome-b19974760_1_0004`,
}));

cy.visit(`/?manifest=http://0.0.0.0:8081/manifest/wellcome-b19974760&tify=${encodedParams}`);
cy.visit(`/?manifest=${Cypress.env('iiifApiUrl')}/manifest/wellcome-b19974760&tify=${encodedParams}`);

cy.contains('The chemist and druggist');

Expand Down
5 changes: 0 additions & 5 deletions tests/iiif-api/config.json

This file was deleted.

Loading

0 comments on commit 2060024

Please sign in to comment.