Skip to content

Commit 7092cac

Browse files
authored
e2e: fk save shortcut (supabase#45804)
adds coverage for: - supabase#45761 which solved supabase#45759 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added test coverage for keyboard shortcut save workflow in the column editor with foreign-key relationships. [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45804) <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent e55411d commit 7092cac

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

e2e/studio/features/table-editor.spec.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,85 @@ testRunner('table editor', () => {
11951195
await expect(page.getByTestId('table-editor-side-panel')).not.toBeVisible()
11961196
})
11971197

1198+
test('shortcut saves fk before column update', async ({ page, ref }) => {
1199+
const runId = `${test.info().parallelIndex}_${test.info().repeatEachIndex}`
1200+
const sourceTableName = `pw_column_fk_shortcut_source_${runId}`
1201+
const targetTableName = `pw_column_fk_shortcut_target_${runId}`
1202+
const columnEditor = page.getByRole('dialog', {
1203+
name: `Update column ref_id from ${sourceTableName}`,
1204+
exact: true,
1205+
})
1206+
const foreignKeySchemaSelect = page.getByRole('combobox', { name: 'Select a schema' })
1207+
const foreignKeyLink = columnEditor.getByRole('link', {
1208+
name: `public.${targetTableName}`,
1209+
exact: true,
1210+
})
1211+
const openColumnEditor = async () => {
1212+
await page
1213+
.getByRole('columnheader', { name: 'ref_id' })
1214+
.getByRole('button', { name: 'Column ref_id actions' })
1215+
.click()
1216+
await page.getByRole('menuitem', { name: 'Edit column' }).click()
1217+
await expect(columnEditor).toBeVisible()
1218+
}
1219+
1220+
await using _ = await withSetupCleanup(
1221+
() =>
1222+
query(`
1223+
drop table if exists public.${sourceTableName} cascade;
1224+
drop table if exists public.${targetTableName} cascade;
1225+
1226+
create table public.${targetTableName} (
1227+
id text primary key
1228+
);
1229+
1230+
create table public.${sourceTableName} (
1231+
id bigint generated by default as identity primary key,
1232+
ref_id text
1233+
);
1234+
`),
1235+
async () => {
1236+
await dropTable(sourceTableName)
1237+
await dropTable(targetTableName)
1238+
}
1239+
)
1240+
1241+
await page.goto(toUrl(`/project/${ref}/editor?schema=public`))
1242+
await page.getByRole('button', { name: `View ${sourceTableName}`, exact: true }).click()
1243+
await page.waitForURL(/\/editor\/\d+\?schema=public$/)
1244+
1245+
await openColumnEditor()
1246+
1247+
await columnEditor.getByRole('button', { name: 'Add foreign key' }).click()
1248+
await expect(foreignKeySchemaSelect).toContainText('public')
1249+
1250+
const tableQueryPromise = waitForApiResponseWithTimeout(page, (response) =>
1251+
response.url().includes(`table-public-${targetTableName}`)
1252+
)
1253+
1254+
await page.getByRole('combobox', { name: 'Select a table to reference to' }).click()
1255+
await page.getByRole('option', { name: `public ${targetTableName}` }).click()
1256+
await tableQueryPromise
1257+
1258+
await page.getByRole('combobox', { name: `Column from public.${targetTableName}` }).click()
1259+
await page.getByRole('option', { name: 'id text' }).click()
1260+
1261+
await page.keyboard.press('ControlOrMeta+Enter')
1262+
1263+
await expect(foreignKeySchemaSelect).not.toBeVisible()
1264+
await expect(foreignKeyLink).toBeVisible()
1265+
1266+
const updateColumnPromise = waitForApiResponse(page, 'pg-meta', ref, 'query?key=column-update', {
1267+
method: 'POST',
1268+
})
1269+
await columnEditor.getByRole('button', { name: 'Save' }).click()
1270+
await updateColumnPromise
1271+
await expect(columnEditor).not.toBeVisible()
1272+
1273+
await openColumnEditor()
1274+
await expect(foreignKeyLink).toBeVisible()
1275+
})
1276+
11981277
test('CSV drag and drop imports data on empty table', async ({ page, ref }) => {
11991278
const tableName = 'pw_table_csv_drag_drop'
12001279

0 commit comments

Comments
 (0)