Skip to content

Commit

Permalink
carry over tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codemonkey800 committed Sep 11, 2024
1 parent 7678813 commit c501973
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 0 deletions.
113 changes: 113 additions & 0 deletions frontend/packages/data-portal/e2e/carryOver.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { expect, test } from '@playwright/test'

import { QueryParams } from 'app/constants/query'

import {
BROWSE_DATASETS_URL,
E2E_CONFIG,
SINGLE_DATASET_URL,
translations,
} from './constants'
import { BreadcrumbsPage } from './pageObjects/breadcrumbsPage'
import { FiltersActor } from './pageObjects/filters/filtersActor'
import { FiltersPage } from './pageObjects/filters/filtersPage'
import { TableActor } from './pageObjects/table/tableActor'
import { TablePage } from './pageObjects/table/tablePage'

let filtersPage: FiltersPage
let filtersActor: FiltersActor
let tablePage: TablePage
let tableActor: TableActor
let breadcrumbsPage: BreadcrumbsPage

test.beforeEach(({ page }) => {
filtersPage = new FiltersPage(page)
filtersActor = new FiltersActor(filtersPage)
tablePage = new TablePage(page)
tableActor = new TableActor(tablePage)
breadcrumbsPage = new BreadcrumbsPage(page)
})

const TEST_PARAM = QueryParams.ObjectName
const TEST_VALUE = E2E_CONFIG.objectName

test.describe('Carry over filters', () => {
test('should carry over datasets filter into single dataset page', async () => {
await filtersPage.goTo(BROWSE_DATASETS_URL)
await filtersActor.addSingleSelectFilter({
label: translations.objectName,
value: TEST_VALUE,
})

await tableActor.expectResultWithUrlParam(TEST_PARAM, TEST_VALUE)
})

test('should carry over single dataset filter into single run page', async () => {
await filtersPage.goTo(SINGLE_DATASET_URL)
await filtersActor.addSingleSelectFilter({
label: translations.objectName,
value: TEST_VALUE,
})

await tableActor.expectResultWithUrlParam(TEST_PARAM, TEST_VALUE)
})
test('should have filter in browse dataset breadcrumb url', async () => {
await filtersPage.goTo(BROWSE_DATASETS_URL)
await filtersActor.addSingleSelectFilter({
label: translations.objectName,
value: TEST_VALUE,
})

// Check links at single dataset level
await tableActor.openFirstResult(TEST_PARAM, TEST_VALUE)

await expect(
breadcrumbsPage.getBreadcrumb({
index: 0,
param: TEST_PARAM,
value: TEST_VALUE,
}),
).toBeVisible()

// Check links at single run level
await tableActor.openFirstResult(TEST_PARAM, TEST_VALUE)

await expect(
breadcrumbsPage.getBreadcrumb({
index: 0,
param: TEST_PARAM,
value: TEST_VALUE,
}),
).toBeVisible()
})

test('should have filter in single dataset breadcrumb url', async () => {
await filtersPage.goTo(SINGLE_DATASET_URL)
await filtersActor.addSingleSelectFilter({
label: translations.objectName,
value: TEST_VALUE,
})

await tableActor.openFirstResult(TEST_PARAM, TEST_VALUE)

await expect(
breadcrumbsPage.getBreadcrumb({
index: 0,
param: TEST_PARAM,
value: TEST_VALUE,
}),
).toBeVisible()
})

// TODO When we have more data to test with
// eslint-disable-next-line playwright/no-skipped-test
test.skip('should carry over single deposition filter into single dataset page', async () => {})

// TODO When we have more data to test with
// eslint-disable-next-line playwright/no-skipped-test
test.skip('should carry over single deposition filter into single run page', async () => {})

// TODO When we have more data to test with
// eslint-disable-next-line playwright/no-skipped-test
test.skip('should remove deposition id filter when click on remove filter button', async () => {})
})
2 changes: 2 additions & 0 deletions frontend/packages/data-portal/e2e/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export const E2E_CONFIG = merge(
export const BROWSE_DATASETS_PATH = '/browse-data/datasets'
export const SINGLE_DATASET_PATH = `/datasets/${E2E_CONFIG.datasetId}`
export const SINGLE_RUN_PATH = `/runs/${E2E_CONFIG.runId}`
export const SINGLE_DEPOSITION_PATH = `/depositions/${E2E_CONFIG.depositionId}`

export const BROWSE_DATASETS_URL = `${E2E_CONFIG.url}${BROWSE_DATASETS_PATH}`
export const SINGLE_DATASET_URL = `${E2E_CONFIG.url}${SINGLE_DATASET_PATH}`
export const SINGLE_RUN_URL = `${E2E_CONFIG.url}${SINGLE_RUN_PATH}`
export const SINGLE_DEPOSITION_URL = `${E2E_CONFIG.url}${SINGLE_DEPOSITION_PATH}`
21 changes: 21 additions & 0 deletions frontend/packages/data-portal/e2e/pageObjects/breadcrumbsPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { QueryParams } from 'app/constants/query'
import { TestIds } from 'app/constants/testIds'

import { BasePage } from './basePage'

export class BreadcrumbsPage extends BasePage {
getBreadcrumb({
index,
param,
value,
}: {
index: number
param?: QueryParams
value?: string
}) {
return this.page
.getByTestId(TestIds.Breadcrumbs)
.locator(this.getUrlWithParamSelector(param, value))
.nth(index)
}
}
20 changes: 20 additions & 0 deletions frontend/packages/data-portal/e2e/pageObjects/table/tableActor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect } from '@playwright/test'

import { QueryParams } from 'app/constants/query'

import { TablePage } from './tablePage'

export class TableActor {
constructor(private tablePage: TablePage) {}

async expectResultWithUrlParam(param: QueryParams, value: string) {
await expect(
this.tablePage.getResultLink({ param, value, index: 0 }),
).toBeVisible()
}

async openFirstResult(param?: QueryParams, value?: string) {
await this.tablePage.getResultLink({ index: 0, param, value }).click()
await this.tablePage.waitForInteractive()
}
}
23 changes: 23 additions & 0 deletions frontend/packages/data-portal/e2e/pageObjects/table/tablePage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { QueryParams } from 'app/constants/query'

import { BasePage } from '../basePage'

export class TablePage extends BasePage {
getNthRow(index: number) {
return this.page.locator('tbody').locator('tr').nth(index)
}

getResultLink({
index,
param,
value,
}: {
index: number
param?: QueryParams
value?: string
}) {
return this.getNthRow(index)
.locator(this.getUrlWithParamSelector(param, value))
.first()
}
}

0 comments on commit c501973

Please sign in to comment.