Skip to content

Commit 308c9e2

Browse files
authored
chore: use API for table setup and drops on database.spec.ts (supabase#42627)
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Database.spec.ts uses API based solution to create tables and drop when setting up runners <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Improved test infrastructure for database operations by transitioning from UI-based setup and teardown to API-based operations, resulting in more reliable and efficient test execution. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 3fd5854 commit 308c9e2

1 file changed

Lines changed: 16 additions & 52 deletions

File tree

e2e/studio/features/database.spec.ts

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { expect, Page } from '@playwright/test'
2+
23
import { env } from '../env.config.js'
4+
import { dropTable, query } from '../utils/db/index.js'
35
import { test } from '../utils/test.js'
46
import { toUrl } from '../utils/to-url.js'
57
import {
@@ -26,68 +28,30 @@ const databaseFunctionName = 'pw_database_function'
2628
const databaseFunctionNameUpdated = 'pw_database_function_updated'
2729
const databaseRoleName = 'pw_database_role'
2830

29-
const createTable = async (page: Page, tableName: string, newColumnName: string) => {
30-
await page.getByRole('button', { name: 'New table', exact: true }).click()
31-
await page.getByTestId('table-name-input').fill(tableName)
32-
await page.getByTestId('created_at-extra-options').click()
33-
await page.getByText('Is Nullable').click()
34-
await page.getByTestId('created_at-extra-options').click({ force: true })
35-
36-
await page.getByRole('button', { name: 'Add column' }).click()
37-
await page.getByRole('textbox', { name: 'column_name' }).fill(newColumnName)
38-
await page.getByText('Choose a column type...').click()
39-
await page.getByRole('option', { name: 'text Variable-length' }).click()
40-
41-
await page.getByRole('button', { name: 'Save' }).click()
42-
43-
await expect(
44-
page.getByText(`Table ${tableName} is good to go!`),
45-
'Success toast should be visible after table creation'
46-
).toBeVisible({
47-
timeout: 50000,
48-
})
49-
50-
await expect(
51-
page.getByRole('button', { name: `View ${tableName}`, exact: true }),
52-
'Table should be visible after creation'
53-
).toBeVisible()
54-
}
55-
56-
const deleteTable = async (page: Page, tableName: string) => {
57-
await page.getByLabel(`View ${tableName}`, { exact: true }).nth(0).click()
58-
await page.getByLabel(`View ${tableName}`, { exact: true }).getByRole('button').nth(1).click()
59-
await page.getByText('Delete table').click()
60-
await page.getByRole('checkbox', { name: 'Drop table with cascade?' }).click()
61-
await page.getByRole('button', { name: 'Delete' }).click()
62-
await expect(
63-
page.getByText(`Successfully deleted table "${tableName}"`),
64-
'Delete confirmation toast should be visible'
65-
).toBeVisible({ timeout: 50000 })
66-
}
67-
6831
test.describe.serial('Database', () => {
6932
let page: Page
7033

7134
test.beforeAll(async ({ browser, ref }) => {
35+
// Create the shared test table via API
36+
await dropTable(databaseTableName) // Clean up if exists
37+
await query(`
38+
CREATE TABLE IF NOT EXISTS ${databaseTableName} (
39+
id bigint generated always as identity not null primary key,
40+
created_at timestamptz default now(),
41+
${databaseColumnName} text
42+
)
43+
`)
44+
7245
page = await browser.newPage()
7346
const wait = createApiResponseWaiter(page, 'pg-meta', ref, 'query?key=entity-types-public-0')
7447
await page.goto(toUrl(`/project/${ref}/editor`))
7548
await wait
76-
77-
if ((await page.getByRole('button', { name: `View ${databaseTableName}` }).count()) > 0) {
78-
await deleteTable(page, databaseTableName)
79-
}
80-
81-
await createTable(page, databaseTableName, databaseColumnName)
8249
})
8350

84-
test.afterAll(async ({ ref }) => {
85-
const wait = createApiResponseWaiter(page, 'pg-meta', ref, 'query?key=entity-types-public-0')
86-
await page.goto(toUrl(`/project/${ref}/editor`))
87-
await wait
88-
if ((await page.getByRole('button', { name: `View ${databaseTableName}` }).count()) > 0) {
89-
await deleteTable(page, databaseTableName)
90-
}
51+
test.afterAll(async () => {
52+
// Clean up via API
53+
await dropTable(databaseTableName)
54+
await page.close()
9155
})
9256

9357
test.describe('Schema Visualizer', () => {

0 commit comments

Comments
 (0)