Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions example/static/samples/pdf/single-resource-short.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,34 @@
"context": "https://drb-files-qa-s3.amazonaws.com/manifests/context.jsonld",
"metadata": {
"@type": "https://schema.org/Book",
"title": "EIB Working Paper 2021/03 - Assessing climate change risks at the country level",
"title": "Annual exhibition",
"author": "Ferrazzi, Matteo",
"conformsTo": "http://librarysimplified.org/terms/profiles/pdf"
},
"links": [
{
"href": "https://library.oapen.org/bitstream/20.500.12657/50076/1/9789286150340.pdf",
"href": "https://drb-files-qa.s3.us-east-1.amazonaws.com/tagged_pdfs/33433131779294.pdf",
"type": "application/pdf",
"rel": "alternate"
},
{
"rel": "self",
"href": "https://drb-files-qa.s3.amazonaws.com/manifests/doab/20.500.12854/71362.json",
"type": "application/webpub+json"
}
],
"readingOrder": [
{
"href": "https://library.oapen.org/bitstream/20.500.12657/50076/1/9789286150340.pdf",
"title": "EIB Working Paper 2021/03 - Assessing climate change risks at the country level",
"href": "https://drb-files-qa.s3.us-east-1.amazonaws.com/tagged_pdfs/33433131779294.pdf",
"title": "Annual exhibition",
"type": "application/pdf"
}
],
"resources": [
{
"href": "https://library.oapen.org/bitstream/20.500.12657/50076/1/9789286150340.pdf",
"href": "https://drb-files-qa.s3.us-east-1.amazonaws.com/tagged_pdfs/33433131779294.pdf",
"type": "application/pdf"
}
],
"toc": [
{
"href": "https://library.oapen.org/bitstream/20.500.12657/50076/1/9789286150340.pdf",
"title": "EIB Working Paper 2021/03 - Assessing climate change risks at the country level"
"href": "https://drb-files-qa.s3.us-east-1.amazonaws.com/tagged_pdfs/33433131779294.pdf",
"title": "Annual exhibition"
}
]
}
}
43 changes: 16 additions & 27 deletions playwright/pageobjects/web-reader.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class WebReaderPage {
readonly exitFullScreenButton: Locator;
readonly nextPageButton: Locator;
readonly previousPageButton: Locator;
readonly pageInput: Locator;
readonly firstChapter: Locator;
readonly lastChapter: Locator;

Expand All @@ -34,14 +35,15 @@ class WebReaderPage {
this.exitFullScreenButton = page.getByRole('button', {
name: 'Exit full screen mode',
});

// footer
this.nextPageButton = this.page.getByRole('button', {
name: 'Next page',
});
this.previousPageButton = page.getByRole('button', {
name: 'Previous page',
});
this.pageInput = page.getByRole('spinbutton', {
name: 'Current page number',
});
}

async changeScreenSize(): Promise<void> {
Expand Down Expand Up @@ -182,11 +184,8 @@ class PdfReaderPage extends WebReaderPage {
readonly pageTwo = this.page
.locator('#mainContent')
.locator('[data-page-number="2"]');
readonly firstIndexPage = this.page.getByText('367', { exact: true });
readonly lastIndexPage = this.page.getByText('376', { exact: true });
readonly permissionsPage = this.page
.locator('[data-page-number="2"]')
.getByText('Permissions', { exact: true });
readonly firstIndexPage = this.page.getByText('3', { exact: true });
readonly lastIndexPage = this.page.getByText('7', { exact: true });

async loadPub(gotoPage: string): Promise<WebReaderPage> {
await this.page.goto(gotoPage, { waitUntil: 'domcontentloaded' });
Expand All @@ -196,31 +195,25 @@ class PdfReaderPage extends WebReaderPage {
}

async loadPage(): Promise<void> {
const loadingPDF = this.page.getByText('Loading...');
await expect(loadingPDF).not.toBeVisible();
const loadingBook = this.page.getByLabel('Loading book...');
await expect(loadingBook).not.toBeVisible();
const loadingPDF = this.page.getByText('Loading PDF…');
await expect(loadingPDF).not.toBeVisible();
}

async changeSettings(): Promise<void> {
await expect(this.settingsButton).toBeVisible();
await this.settingsButton.click();
await expect(this.zoomInButton).toBeVisible();
await this.zoomInButton.click();
}

async getZoomValue(): Promise<number> {
return await this.page.locator('canvas').evaluate((el) => {
return Number(
window.getComputedStyle(el).getPropertyValue('--scale-factor')
);
});
return await this.page
.locator('canvas:visible')
.first()
.evaluate((el) => {
return Number(
window.getComputedStyle(el).getPropertyValue('--user-unit')
);
});
}

async zoomIn(): Promise<void> {
const beforeScaleFactor = await this.getZoomValue();
await expect(this.settingsButton).toBeVisible();
await this.settingsButton.click();
await expect(this.zoomInButton).toBeVisible();
await this.zoomInButton.click();
const afterScaleFactor = await this.getZoomValue();
Expand All @@ -229,8 +222,6 @@ class PdfReaderPage extends WebReaderPage {

async zoomOut(): Promise<void> {
const beforeScaleFactor = await this.getZoomValue();
await expect(this.settingsButton).toBeVisible();
await this.settingsButton.click();
await expect(this.zoomOutButton).toBeVisible();
await this.zoomOutButton.click();
const afterScaleFactor = await this.getZoomValue();
Expand Down Expand Up @@ -265,8 +256,6 @@ class PdfReaderPage extends WebReaderPage {
await expect(this.nextPageButton).toBeEnabled();
await expect(this.previousPageButton).toBeVisible();
await expect(this.previousPageButton).toBeDisabled();
await expect(this.settingsButton).toBeVisible();
await this.settingsButton.click();
await expect(this.tocButton).toBeVisible();
await this.tocButton.click();
await expect(this.lastChapter).toBeVisible();
Expand Down
34 changes: 34 additions & 0 deletions playwright/tests/pdf-reader-buttons.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect, test } from '@playwright/test';
import { PdfReaderPage } from '../pageobjects/web-reader.page.ts';

test.describe('Test settings in PDF pub', () => {
test('Confirm reader settings are visible', async ({ page }) => {
const pdfReaderPage = new PdfReaderPage(page);
await pdfReaderPage.loadPub('/pdf/single-resource-short');
await expect(pdfReaderPage.fullScreenButton).toBeVisible();
await expect(pdfReaderPage.zoomInButton).toBeVisible();
await expect(pdfReaderPage.zoomOutButton).toBeVisible();
});

test('Zoom in', async ({ page }) => {
const pdfReaderPage = new PdfReaderPage(page);
await pdfReaderPage.loadPub('/pdf/single-resource-short');
await pdfReaderPage.zoomIn();
});

test('Zoom out', async ({ page }) => {
const pdfReaderPage = new PdfReaderPage(page);
await pdfReaderPage.loadPub('/pdf/single-resource-short');
await pdfReaderPage.zoomOut();
});

test('Open and exit full screen', async ({ page }) => {
const pdfReaderPage = new PdfReaderPage(page);
await pdfReaderPage.loadPub('/pdf/single-resource-short');
await expect(pdfReaderPage.fullScreenButton).toBeVisible();
await pdfReaderPage.fullScreenButton.click();
await expect(pdfReaderPage.exitFullScreenButton).toBeVisible();
await pdfReaderPage.exitFullScreenButton.click();
await expect(pdfReaderPage.fullScreenButton).toBeVisible();
});
});
Loading
Loading