Files
supabase/e2e/studio/features/table-editor.spec.ts
Jordi Enric 55c3fdb49a E2E Testing Setup Consolidation (#35080)
* add new e2e folder

* add local supabase and confitional storage

* fix e2e selfhosted

* update actions

* add correct e2e folder

* fix e2e actions

* fix action project ids

* fix permissions

* fix script

* fix playwright install

* playwright root

* pnpm i

* fix api rul

* add env docs

* update run script

* only install deps for e2e

* use same dep

* only install deps for tests

* upd lockfile

* use official vercel integration

* use vercel cli

* remove old folder

* fix script

* rm filter

* rename e2e studio package

* fix install browsers

* add polling for vercel build

* use vercel-preview-url package

* undo actions

* rename ci env to ci

* chore:add rls check and make playwright test less flakey (#35348)

* update ci action

* fix paths

* fix browser install

* run ci against staging

* try caching builds

* fix envs

* fix env check

* fix sign in

* fix sign in url

* fix envs and url

* fix caching

* fix race condition in sign in page

* fix race condition in sign in page

* add check to see if being redirected

* fix caching, check IS_PLATFORM var

* log is_platform

* try vercel build

* fix vercel project id

* fix path

* add temp vercel.json file

* fix paths

* undo project id stuff

* rm cwd

* fix path

* fix paths again

* fix path

* fix base url

* try different fix

* fix config base url

* fix base studio url issues

* retain video on fails

* Update e2e/studio/README.md

Co-authored-by: Copple <10214025+kiwicopple@users.noreply.github.com>

* Update e2e/studio/README.md

Co-authored-by: Copple <10214025+kiwicopple@users.noreply.github.com>

* fix env file naming

* undo caching

* rm old tests folder

* fix readme scripts

* rm vercel deploy for now, just run build locally

* fix url

* fix build script

* fix is_platform

* fix stuck studio start

* fix env vars

* retain network and logs on fail for better debugging

* add apiurl env

* back to vercel

* disable catpcha

* fix test

* update environment configuration to remove default URLs for CI and streamline API base URL handling

* fix typeerr

* fix urls in home.spec

* fix urls in logs.spec

* fix urls in sqleditor spec

* fix table editor spec

* add tourl util

* use staging api in ci

* re add base url env var

* fix url in projects page

* fix url in sql editor spec

* fix sign in not waiting for cookies omfg

* fix env var name

* fix sql-editor test

* simplify table removal

* add opt out telemetry step

* fix logs tests

* fix table editor spec

* remove flaky steps from table editor tests

* use vercel deployment events instead of build

* add studio check

* fix condition

* debug event

* rm if

* trigger deploy

* undo ac

* make opt out button step optional, some envs dont hav eit

* use testid for sql run button

* use id instaed of timestamp in logs tests

* empty

* rm retries

* up glbal timeout

* chore: fix failing sql-editor playwright test (#35767)

* chore: fix failing sql-editor playwright test

* chore: minor fixes

* Chore/update playwright config (#35826)

chore: update playwright config

* rm supabase project from e2e tests

* refactor and simplify environments

* fix sql editor test

* fix ci env vars

* fix

* fix on windows

* update readme

* add playwright install script to readme

* rm turbopack trace flag

* npm to pnpm for scripts

* delete ivan lines

---------

Co-authored-by: Michael Ong <minghao_3728@hotmail.com>
Co-authored-by: Copple <10214025+kiwicopple@users.noreply.github.com>
2025-06-03 17:37:39 +02:00

211 lines
8.3 KiB
TypeScript

import { expect, Page } from '@playwright/test'
import { test } from '../utils/test'
import { toUrl } from '../utils/to-url'
// Helper to generate a random table name
const getRandomTableName = () => `pw-test-${Math.floor(Math.random() * 10000)}`
const getSelectors = (tableName: string) => ({
tableButton: (page) => page.getByRole('button', { name: `View ${tableName}` }),
newTableBtn: (page) => page.getByRole('button', { name: 'New table', exact: true }),
tableNameInput: (page) => page.getByTestId('table-name-input'),
createdAtExtraOptions: (page) => page.getByTestId('created_at-extra-options'),
addColumnBtn: (page) => page.getByRole('button', { name: 'Add column' }),
columnNameInput: (page) => page.getByRole('textbox', { name: 'column_name' }),
chooseColumnType: (page) => page.locator('button').filter({ hasText: 'Choose a column type...' }),
signedIntOption: (page) => page.getByText('Signed two-byte integer'),
defaultValueField: (page) => page.getByTestId('defaultValueColumn-default-value'),
saveBtn: (page) => page.getByRole('button', { name: 'Save' }),
definitionTab: (page) => page.getByText('definition', { exact: true }),
viewLines: (page) => page.locator('div.view-lines'),
insertRowBtn: (page) => page.getByTestId('table-editor-insert-new-row'),
insertModal: (page) => page.getByText('Insert a new row into'),
defaultValueInput: (page) => page.getByTestId('defaultValueColumn-input'),
actionBarSaveRow: (page) => page.getByTestId('action-bar-save-row'),
grid: (page) => page.getByRole('grid'),
row: (page) => page.getByRole('row'),
sortBtn: (page) => page.getByRole('button', { name: 'Sort', exact: true }),
pickSortColumnBtn: (page) => page.getByTestId('table-editor-pick-column-to-sort-button'),
sortColumnOption: (page) =>
page.getByLabel('Pick a column to sort by').getByText('defaultValueColumn'),
applySortingBtn: (page) => page.getByRole('button', { name: 'Apply sorting' }),
sortedByRuleBtn: (page) => page.getByRole('button', { name: 'Sorted by 1 rule' }),
filterBtn: (page) => page.getByRole('button', { name: 'Filter', exact: true }),
addFilterBtn: (page) => page.getByRole('button', { name: 'Add filter' }),
columnPickerBtn: (page) => page.getByRole('button', { name: 'id' }),
filterColumnOption: (page) => page.getByLabel('id').getByText('defaultValueColumn'),
filterInput: (page) => page.getByPlaceholder('Enter a value'),
applyFilterBtn: (page) => page.getByRole('button', { name: 'Apply filter' }),
viewTableLabel: (page) => page.getByLabel(`View ${tableName}`, { exact: true }),
deleteTableBtn: (page) => page.getByText('Delete table'),
confirmDeleteBtn: (page) => page.getByRole('button', { name: 'Delete' }),
rlsCheckbox: (page) => page.getByLabel('Enable Row Level Security ('),
rlsConfirmBtn: (page) => page.getByRole('button', { name: 'Confirm' }),
deleteTableToast: (page) => page.getByText('Successfully deleted table "'),
})
test.describe('Table Editor', () => {
let page: Page
let tableName: string
test.beforeAll(async ({ browser, ref }) => {
test.setTimeout(60000)
/**
* Create a new table for the tests
*/
page = await browser.newPage()
await page.goto(toUrl(`/project/${ref}/editor`))
tableName = getRandomTableName()
const s = getSelectors(tableName)
await s.newTableBtn(page).click()
await s.tableNameInput(page).fill(tableName)
await s.createdAtExtraOptions(page).click()
await page.getByText('Is Nullable').click()
await s.createdAtExtraOptions(page).click({ force: true })
await s.addColumnBtn(page).click()
await s.columnNameInput(page).fill('defaultValueColumn')
await s.chooseColumnType(page).click()
await s.signedIntOption(page).click()
await s.defaultValueField(page).click()
await s.defaultValueField(page).fill('2')
await s.saveBtn(page).click()
// wait till we see the success toast
// Text: Table tableName is good to go!
await expect(
page.getByText(`Table ${tableName} is good to go!`),
'Success toast should be visible after table creation'
).toBeVisible({
timeout: 50000,
})
await expect(
page.getByRole('button', { name: `View ${tableName}` }),
'Table should be visible after creation'
).toBeVisible()
})
test.afterAll(async () => {
test.setTimeout(60000)
/**
* Delete the table after the tests are done
*/
const s = getSelectors(tableName)
const exists = (await s.tableButton(page).count()) > 0
if (!exists) return
await s.viewTableLabel(page).click()
await s.viewTableLabel(page).getByRole('button').nth(1).click()
await s.deleteTableBtn(page).click()
await s.confirmDeleteBtn(page).click()
await expect(
s.deleteTableToast(page),
'Delete confirmation toast should be visible'
).toBeVisible()
})
test('should perform all table operations sequentially', async ({ ref }) => {
const s = getSelectors(tableName)
test.setTimeout(60000)
// 1. View table definition
await page.evaluate(() => document.querySelector('.ReactQueryDevtools')?.remove())
await s.definitionTab(page).click()
await expect(
s.viewLines(page),
'Table definition should contain the correct SQL'
).toContainText(
`CREATE TABLE public.${tableName} ( id bigint GENERATED BY DEFAULT AS IDENTITY NOT NULL, created_at timestamp with time zone NULL DEFAULT now(), "defaultValueColumn" smallint NULL DEFAULT '2'::smallint, CONSTRAINT ${tableName}_pkey PRIMARY KEY (id)) TABLESPACE pg_default;`
)
// 2. Insert test data
await page.getByRole('button', { name: `View ${tableName}` }).click()
await s.insertRowBtn(page).click()
await s.insertModal(page).click()
await s.defaultValueInput(page).fill('100')
await s.actionBarSaveRow(page).click()
await page.getByRole('button', { name: `View ${tableName}` }).click()
await s.insertRowBtn(page).click()
await s.insertModal(page).click()
await s.defaultValueInput(page).fill('4')
await s.actionBarSaveRow(page).click()
// Wait for the grid to be visible and data to be loaded
await expect(s.grid(page), 'Grid should be visible after inserting data').toBeVisible()
// 3. Sort rows
await s.sortBtn(page).click()
await s.pickSortColumnBtn(page).click()
await s.sortColumnOption(page).click()
await s.applySortingBtn(page).click()
await page.keyboard.down('Escape')
// Wait for sorting to complete
await page.waitForResponse((response) => response.url().includes(`pg-meta/${ref}/query`))
// give it a second to rerender
await page.waitForTimeout(1000)
const defaultValueCells = page.getByRole('gridcell')
const thirdGridCell = defaultValueCells.nth(3)
const thirdGridCellText = await thirdGridCell.textContent()
expect(thirdGridCellText, 'Third grid cell should contain the value "4"').toEqual('4')
// 4. Filter rows
await s.filterBtn(page).click()
await s.addFilterBtn(page).click()
await s.columnPickerBtn(page).click()
await s.filterColumnOption(page).click()
await s.filterInput(page).fill('4')
await s.applyFilterBtn(page).click()
await page.keyboard.down('Escape')
await expect(
s.grid(page).getByRole('gridcell', { name: '4', exact: true }),
'Filtered value "4" should be visible'
).toBeVisible()
await expect(
s.grid(page).getByText('100'),
'Filtered value "100" should not be visible'
).not.toBeVisible()
// 5. Check auth schema
await page.getByTestId('schema-selector').click()
await page.getByRole('option', { name: 'auth' }).click()
// Wait for the tables list to be visible
await expect(
page.getByTestId('tables-list'),
'Tables list should be visible in auth schema'
).toBeVisible()
// search for users
await page.getByRole('textbox', { name: 'Search tables...' }).fill('users')
// Try to find the users table directly
const usersTable = page.getByRole('button', { name: 'View users' })
await expect(usersTable, 'Users table should be visible in auth schema').toBeVisible()
// go back to public schema
await page.getByTestId('schema-selector').click()
await page.getByRole('option', { name: 'public', exact: true }).click()
// wait for the tables list to be visible
await expect(
page.getByTestId('tables-list'),
'Tables list should be visible in public schema'
).toBeVisible()
})
})