Skip to content

Commit

Permalink
dynamic function for wait
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0nox committed Jan 24, 2025
1 parent 364f403 commit 6750102
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 9 additions & 3 deletions report-viewer/tests/e2e/OpenOldReport.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from '@playwright/test'
import { expect, Page, test } from '@playwright/test'
import { uploadFile } from './TestUtils'

const oldVersionZips = [
Expand All @@ -16,7 +16,7 @@ const oldVersionZips = [

for (const oldVersion of oldVersionZips) {
test(`Test old version redirect for v${oldVersion.version}`, async ({ page }) => {
await uploadFile(oldVersion.zipName, page, '/old/' + oldVersion.version)
await uploadFile(oldVersion.zipName, page, getWaitForOldPageFunction(oldVersion.version))

const bodyContent = await page.locator('body').textContent()
expect(bodyContent).toContain(
Expand All @@ -33,7 +33,7 @@ for (const oldVersion of oldVersionZips) {
}

test('Test unsupported old version', async ({ page }) => {
await uploadFile('progpedia-report-v4_0_0.zip', page, '/old/4.0.0')
await uploadFile('progpedia-report-v4_0_0.zip', page, getWaitForOldPageFunction('4.0.0'))

const bodyContent = await page.locator('body').textContent()
expect(bodyContent).toContain(
Expand All @@ -45,3 +45,9 @@ test('Test unsupported old version', async ({ page }) => {
'Opening reports generated with version 4.0.0 is not supported by this report viewer.'
)
})

function getWaitForOldPageFunction(version: string) {
return async (page: Page) => {
await page.waitForURL(`/old/${version}`)
}
}
9 changes: 7 additions & 2 deletions report-viewer/tests/e2e/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { Page } from '@playwright/test'
* Expects to be on the file upload page.
* @param fileName
*/
export async function uploadFile(fileName: string, page: Page, expectedURL: string = '/overview') {
export async function uploadFile(
fileName: string,
page: Page,
waitCondition: (page: Page) => Promise<void> = async (page) =>
await page.locator('text="JPlag Report"').waitFor({ state: 'visible' })
) {
page.route('**/results.zip', async (route) => {
await route.fulfill({
// fullfill with the file
Expand All @@ -19,5 +24,5 @@ export async function uploadFile(fileName: string, page: Page, expectedURL: stri

await page.goto('/')

await page.waitForURL(expectedURL)
await waitCondition(page)
}

0 comments on commit 6750102

Please sign in to comment.