test: addListFilter helper (#11026)
Adds a new `addListFilter` e2e helper. This will help to standardize this common functionality across all tests that require filtering list tables and help reduce the overall lines of code within each test file.
This commit is contained in:
53
test/helpers/e2e/addListFilter.ts
Normal file
53
test/helpers/e2e/addListFilter.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
import { expect } from '@playwright/test'
|
||||
import { exactText } from 'helpers.js'
|
||||
import { wait } from 'payload/shared'
|
||||
|
||||
import { openListFilters } from './openListFilters.js'
|
||||
|
||||
export const addListFilter = async ({
|
||||
page,
|
||||
fieldLabel = 'ID',
|
||||
operatorLabel = 'equals',
|
||||
value = '',
|
||||
skipValueInput,
|
||||
}: {
|
||||
fieldLabel: string
|
||||
operatorLabel: string
|
||||
page: Page
|
||||
skipValueInput?: boolean
|
||||
value?: string
|
||||
}) => {
|
||||
await openListFilters(page, {})
|
||||
|
||||
const whereBuilder = page.locator('.where-builder')
|
||||
|
||||
await whereBuilder.locator('.where-builder__add-first-filter').click()
|
||||
|
||||
const conditionField = whereBuilder.locator('.condition__field')
|
||||
await conditionField.click()
|
||||
|
||||
const conditionOptions = conditionField.locator('.rs__option', {
|
||||
hasText: exactText(fieldLabel),
|
||||
})
|
||||
|
||||
await conditionOptions.click()
|
||||
await expect(whereBuilder.locator('.condition__field')).toContainText(fieldLabel)
|
||||
|
||||
const operatorInput = whereBuilder.locator('.condition__operator')
|
||||
await operatorInput.click()
|
||||
const operatorOptions = operatorInput.locator('.rs__option')
|
||||
await operatorOptions.locator(`text=${operatorLabel}`).click()
|
||||
|
||||
if (!skipValueInput) {
|
||||
const valueInput = whereBuilder.locator('.condition__value >> input')
|
||||
await valueInput.fill(value)
|
||||
await wait(100)
|
||||
await expect(valueInput).toHaveValue(value)
|
||||
const valueOptions = whereBuilder.locator('.condition__value').locator('.rs__option')
|
||||
if ((await whereBuilder.locator('.condition__value >> input.rs__input').count()) > 0) {
|
||||
await valueOptions.locator(`text=${value}`).click()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user