|
| 1 | +import type { Page } from '@playwright/test' |
| 2 | + |
| 3 | +import { expect, test } from '@playwright/test' |
| 4 | +import path from 'path' |
| 5 | +import { wait } from 'payload/shared' |
| 6 | +import { fileURLToPath } from 'url' |
| 7 | + |
| 8 | +import { ensureCompilationIsDone, initPageConsoleErrorCatch } from '../../../helpers.js' |
| 9 | +import { AdminUrlUtil } from '../../../helpers/adminUrlUtil.js' |
| 10 | +import { initPayloadE2ENoConfig } from '../../../helpers/initPayloadE2ENoConfig.js' |
| 11 | +import { reInitializeDB } from '../../../helpers/reInitializeDB.js' |
| 12 | +import { RESTClient } from '../../../helpers/rest.js' |
| 13 | +import { TEST_TIMEOUT_LONG } from '../../../playwright.config.js' |
| 14 | +import { checkboxFieldsSlug } from '../../slugs.js' |
| 15 | + |
| 16 | +const filename = fileURLToPath(import.meta.url) |
| 17 | +const currentFolder = path.dirname(filename) |
| 18 | +const dirname = path.resolve(currentFolder, '../../') |
| 19 | + |
| 20 | +const { beforeAll, beforeEach, describe } = test |
| 21 | + |
| 22 | +let client: RESTClient |
| 23 | +let page: Page |
| 24 | +let serverURL: string |
| 25 | +let url: AdminUrlUtil |
| 26 | + |
| 27 | +describe('Checkboxes', () => { |
| 28 | + beforeAll(async ({ browser }, testInfo) => { |
| 29 | + testInfo.setTimeout(TEST_TIMEOUT_LONG) |
| 30 | + process.env.SEED_IN_CONFIG_ONINIT = 'false' // Makes it so the payload config onInit seed is not run. Otherwise, the seed would be run unnecessarily twice for the initial test run - once for beforeEach and once for onInit |
| 31 | + ;({ serverURL } = await initPayloadE2ENoConfig({ |
| 32 | + dirname, |
| 33 | + // prebuild, |
| 34 | + })) |
| 35 | + |
| 36 | + url = new AdminUrlUtil(serverURL, checkboxFieldsSlug) |
| 37 | + |
| 38 | + const context = await browser.newContext() |
| 39 | + page = await context.newPage() |
| 40 | + initPageConsoleErrorCatch(page) |
| 41 | + |
| 42 | + await ensureCompilationIsDone({ page, serverURL }) |
| 43 | + }) |
| 44 | + |
| 45 | + beforeEach(async () => { |
| 46 | + await reInitializeDB({ |
| 47 | + serverURL, |
| 48 | + snapshotKey: 'fieldsTest', |
| 49 | + uploadsDir: path.resolve(dirname, './collections/Upload/uploads'), |
| 50 | + }) |
| 51 | + if (client) { |
| 52 | + await client.logout() |
| 53 | + } |
| 54 | + client = new RESTClient(null, { defaultSlug: 'users', serverURL }) |
| 55 | + await client.login() |
| 56 | + await ensureCompilationIsDone({ page, serverURL }) |
| 57 | + }) |
| 58 | + |
| 59 | + test('should not crash on filtering where checkbox is first field', async () => { |
| 60 | + await page.goto(url.list) |
| 61 | + |
| 62 | + const filterButton = page.locator('.list-controls__toggle-where') |
| 63 | + await filterButton.click() |
| 64 | + |
| 65 | + const addButton = page.locator('.where-builder__add-first-filter') |
| 66 | + await addButton.click() |
| 67 | + |
| 68 | + const operator = page.locator('.condition__operator .rs__control') |
| 69 | + await operator.click() |
| 70 | + |
| 71 | + const equals = page.locator('.rs__option:has-text("equals")') |
| 72 | + await equals.click() |
| 73 | + |
| 74 | + const value = page.locator('.condition__value') |
| 75 | + await value.click() |
| 76 | + |
| 77 | + const trueOption = page.locator('.rs__option:has-text("True")') |
| 78 | + await trueOption.click() |
| 79 | + |
| 80 | + await wait(1000) |
| 81 | + |
| 82 | + await expect(page.locator('table > tbody > tr')).toHaveCount(1) |
| 83 | + }) |
| 84 | +}) |
0 commit comments