From 9095853f7b0e44f1b35b4eb2ca325ea9553262b0 Mon Sep 17 00:00:00 2001 From: JasminMus <167111741+JasminMus@users.noreply.github.com> Date: Mon, 16 Sep 2024 06:31:27 +0200 Subject: [PATCH] Add test for downloading PDF (#6541) Signed-off-by: Jasmin Co-authored-by: Alexey Zinoviev --- dev/docker-compose.yaml | 2 + qms-tests/docker-compose.yaml | 18 +++- .../sanity/tests/documents/REQ-04-01.spec.ts | 82 +++++++++++++++++++ .../model/documents/document-content-page.ts | 6 ++ .../sanity/tests/model/documents/pdf-pages.ts | 28 +++++++ 5 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 qms-tests/sanity/tests/documents/REQ-04-01.spec.ts create mode 100644 qms-tests/sanity/tests/model/documents/pdf-pages.ts diff --git a/dev/docker-compose.yaml b/dev/docker-compose.yaml index 83a2dc862c..6c31ffd90e 100644 --- a/dev/docker-compose.yaml +++ b/dev/docker-compose.yaml @@ -217,6 +217,8 @@ services: memory: 1024M print: image: hardcoreeng/print + extra_hosts: + - "host.docker.internal:host-gateway" restart: unless-stopped ports: - 4005:4005 diff --git a/qms-tests/docker-compose.yaml b/qms-tests/docker-compose.yaml index ddb2bfa59b..982aea573b 100644 --- a/qms-tests/docker-compose.yaml +++ b/qms-tests/docker-compose.yaml @@ -2,6 +2,8 @@ version: "3" services: mongodb: image: 'mongo:7-jammy' + extra_hosts: + - "host.docker.internal:host-gateway" command: mongod --port 27018 environment: - PUID=1000 @@ -38,6 +40,8 @@ services: test: curl -s http://localhost:9200/_cluster/health | grep -vq '"status":"red"' account: image: hardcoreeng/account + extra_hosts: + - "host.docker.internal:host-gateway" pull_policy: never links: - mongodb @@ -56,6 +60,8 @@ services: - BRANDING_PATH=/var/cfg/branding-test.json workspace: image: hardcoreeng/workspace + extra_hosts: + - "host.docker.internal:host-gateway" links: - mongodb - minio @@ -73,6 +79,8 @@ services: restart: unless-stopped front: image: hardcoreeng/front + extra_hosts: + - "host.docker.internal:host-gateway" pull_policy: never links: - account @@ -103,6 +111,8 @@ services: - SIGN_URL=http://host.docker.internal:4006 transactor: image: hardcoreeng/transactor + extra_hosts: + - "host.docker.internal:host-gateway" pull_policy: never links: - mongodb @@ -132,6 +142,8 @@ services: - BRANDING_PATH=/var/cfg/branding-test.json collaborator: image: hardcoreeng/collaborator + extra_hosts: + - "host.docker.internal:host-gateway" links: - mongodb - minio @@ -151,6 +163,8 @@ services: restart: on-failure print: image: hardcoreeng/print + extra_hosts: + - "host.docker.internal:host-gateway" restart: unless-stopped ports: - 4005:4005 @@ -165,6 +179,8 @@ services: memory: 300M sign: image: hardcoreeng/sign + extra_hosts: + - "host.docker.internal:host-gateway" restart: unless-stopped ports: - 4006:4006 @@ -177,7 +193,7 @@ services: - MONGO_OPTIONS={"appName":"sign","maxPoolSize":1} - MINIO_ENDPOINT=minio - MINIO_ACCESS_KEY=minioadmin - - ACCOUNTS_URL=http://host.docker.internal:3000 + - ACCOUNTS_URL=http://account:3003 - MINIO_SECRET_KEY=minioadmin - CERTIFICATE_PATH=/var/cfg/certificate.p12 - SERVICE_ID=sign-service diff --git a/qms-tests/sanity/tests/documents/REQ-04-01.spec.ts b/qms-tests/sanity/tests/documents/REQ-04-01.spec.ts new file mode 100644 index 0000000000..dfd19c2884 --- /dev/null +++ b/qms-tests/sanity/tests/documents/REQ-04-01.spec.ts @@ -0,0 +1,82 @@ +import { test } from '@playwright/test' +import { attachScreenshot, generateId, HomepageURI, PlatformSetting, PlatformURI } from '../utils' +import { allure } from 'allure-playwright' +import { DocumentDetails, DocumentRights, DocumentStatus, NewDocument } from '../model/types' +import { DocumentContentPage } from '../model/documents/document-content-page' +import { prepareDocumentStep } from './common-documents-steps' +import { DocumentApprovalsPage } from '../model/documents/document-approvals-page' +import { PdfPages } from '../model/documents/pdf-pages' + +test.use({ + storageState: PlatformSetting +}) + +test.describe('QMS. PDF Download', () => { + test.beforeEach(async ({ page }) => { + await (await page.goto(`${PlatformURI}/${HomepageURI}`))?.finished() + }) + + test.afterEach(async ({ browser }) => { + const contexts = browser.contexts() + for (const context of contexts) { + await context.close() + } + }) + + test('TESTS-271. Download PDF', async ({ page }) => { + await allure.description('Requirement\nUsers need to approve the document') + await allure.tms('TESTS-271', 'https://tracex.hc.engineering/workbench/platform/tracker/TESTS-271') + const approveDocument: NewDocument = { + template: 'HR (HR)', + title: `Approve document-${generateId()}`, + description: `Approve document description-${generateId()}` + } + const documentDetails: DocumentDetails = { + type: 'HR', + category: 'Human Resources', + version: 'v0.1', + status: DocumentStatus.DRAFT, + owner: 'Appleseed John', + author: 'Appleseed John' + } + + await prepareDocumentStep(page, approveDocument) + const documentContentPage = new DocumentContentPage(page) + await test.step('2. Send for Approval', async () => { + await documentContentPage.buttonSendForApproval.click() + await documentContentPage.fillSelectApproversForm([documentDetails.owner]) + await documentContentPage.checkDocumentStatus(DocumentStatus.IN_APPROVAL) + await documentContentPage.checkDocument({ + ...documentDetails, + status: DocumentStatus.IN_APPROVAL + }) + await documentContentPage.checkCurrentRights(DocumentRights.VIEWING) + }) + + await test.step('3. Approve document', async () => { + await documentContentPage.confirmApproval() + }) + + await test.step('4. Check the document and status', async () => { + await documentContentPage.checkDocumentStatus(DocumentStatus.EFFECTIVE) + await documentContentPage.checkDocument({ + ...documentDetails, + status: DocumentStatus.EFFECTIVE, + version: 'v0.1' + }) + await documentContentPage.checkCurrentRights(DocumentRights.VIEWING) + + await documentContentPage.openApprovals() + const documentApprovalsPage = new DocumentApprovalsPage(page) + await documentApprovalsPage.checkSuccessApproval(documentDetails.owner) + await attachScreenshot('TESTS-271_approve_document.png', page) + }) + await test.step('5. Download PDF', async () => { + await documentContentPage.clickDocumentThreeDots() + const pdfPages = new PdfPages(page) + await pdfPages.printToPdfClick() + await pdfPages.downloadAndVerifyPdf() + }) + await attachScreenshot('TESTS-271_ddownloaded_document.png', page) + }) +}) diff --git a/qms-tests/sanity/tests/model/documents/document-content-page.ts b/qms-tests/sanity/tests/model/documents/document-content-page.ts index 9c4c18a09f..bda47bbabe 100644 --- a/qms-tests/sanity/tests/model/documents/document-content-page.ts +++ b/qms-tests/sanity/tests/model/documents/document-content-page.ts @@ -83,6 +83,7 @@ export class DocumentContentPage extends DocumentCommonPage { readonly changeSpaceButton: Locator readonly createNewTemplateFromSpace: Locator readonly okButton: Locator + readonly documentThreeDots: Locator constructor (page: Page) { super(page) @@ -176,6 +177,7 @@ export class DocumentContentPage extends DocumentCommonPage { this.changeSpaceButton = page.locator('[id="space\\.selector"]') this.createNewTemplateFromSpace = page.getByRole('button', { name: 'Create new template' }) this.okButton = page.getByRole('button', { name: 'Ok', exact: true }) + this.documentThreeDots = page.locator("div[class='no-print ml-1'] button[type='button']") } async checkDocumentTitle (title: string): Promise { @@ -198,6 +200,10 @@ export class DocumentContentPage extends DocumentCommonPage { await this.newTemplate.click() } + async clickDocumentThreeDots (): Promise { + await this.documentThreeDots.click() + } + async selectControlDocumentSubcategory ( buttonName: 'My Document' | 'Library' | 'Templates' | 'Categories' | 'General documentation' ): Promise { diff --git a/qms-tests/sanity/tests/model/documents/pdf-pages.ts b/qms-tests/sanity/tests/model/documents/pdf-pages.ts new file mode 100644 index 0000000000..f39ceb9b9f --- /dev/null +++ b/qms-tests/sanity/tests/model/documents/pdf-pages.ts @@ -0,0 +1,28 @@ +import { type Locator, type Page, expect } from '@playwright/test' + +export class PdfPages { + readonly page: Page + readonly printToPdf: Locator + readonly printToPdfHeader: Locator + readonly downloadPdf: Locator + + constructor (page: Page) { + this.page = page + this.printToPdf = page.getByRole('button', { name: 'Print to PDF' }) + this.printToPdfHeader = page.getByText('PDF PDF print preview') + this.downloadPdf = page.locator('form').getByRole('link').getByRole('button') + } + + async printToPdfClick (): Promise { + await this.printToPdf.click() + await expect(this.printToPdfHeader).toBeVisible() + } + + async downloadAndVerifyPdf (): Promise { + const [download] = await Promise.all([this.page.waitForEvent('download'), this.downloadPdf.click()]) + const filePath = await download.path() + expect(filePath).toBeTruthy() + const fileName = download.suggestedFilename() + console.log(`Downloaded file: ${fileName}`) + } +}