mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 19:44:59 +03:00
1d3299e384
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions
Signed-off-by: Jasmin <jasmin@hardcoreeng.com>
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { expect, Page } from '@playwright/test'
|
|
import { join } from 'path'
|
|
|
|
export class VisualCheck {
|
|
readonly page: Page
|
|
|
|
constructor (page: Page) {
|
|
this.page = page
|
|
}
|
|
|
|
async compareScreenshot (selector: string | null, screenshotName: string): Promise<void> {
|
|
let screenshot
|
|
|
|
if (selector !== null && selector !== undefined) {
|
|
const element = this.page.locator(selector)
|
|
await expect(element).toBeVisible()
|
|
screenshot = await element.screenshot()
|
|
} else {
|
|
screenshot = await this.page.screenshot()
|
|
}
|
|
|
|
// Compare the screenshot with the stored snapshot
|
|
expect(screenshot).toMatchSnapshot(join(__dirname, '..', 'screenshots', `${screenshotName}.png`), {
|
|
maxDiffPixelRatio: 0.2
|
|
})
|
|
}
|
|
|
|
async comparePDFPreview (screenshotName: string): Promise<void> {
|
|
// Wait for the iframe to be present in the DOM
|
|
const iframe = this.page.locator('iframe.pdfviewer-content')
|
|
await iframe.waitFor({ state: 'attached', timeout: 10000 })
|
|
|
|
// Wait for the iframe to finish loading
|
|
await this.page.waitForFunction(
|
|
() => {
|
|
const iframe = document.querySelector('iframe.pdfviewer-content') as HTMLIFrameElement
|
|
return iframe?.contentDocument?.readyState === 'complete'
|
|
},
|
|
{ timeout: 30000 }
|
|
)
|
|
|
|
const pdfPreviewModal = this.page.locator('.antiDialog > .content')
|
|
await expect(pdfPreviewModal).toBeVisible()
|
|
|
|
const screenshot = await this.page.screenshot()
|
|
|
|
expect(screenshot).toMatchSnapshot(join(__dirname, '..', 'screenshots', `${screenshotName}.png`), {
|
|
maxDiffPixelRatio: 0.2
|
|
})
|
|
}
|
|
}
|