mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 01:15:03 +03:00
test(sql-editor): e2e coverage + delete jsdom test + merge Results.utils tests (Steps 5-6) (#48217)
## Summary Steps 5 and 6 of the SQL editor test refactor plan (the final two steps). **Step 5** — extends `e2e/studio/features/sql-editor.spec.ts` (real browser, zero mocks) with cases that need the real Monaco editor / full app render: - destructive-query warning modal: confirm actually re-runs the forced query (previously only `Cancel` was exercised) - debug button opens the AI Assistant with the query error pre-filled Deletes `apps/studio/tests/components/SQLEditor/SQLEditor.test.tsx` — its logic-level cases are now covered mock-free by the Step 4 hook tests, and its integration cases by e2e. Deleting rather than narrowing is the honest consequence of "no mocking": every remaining assertion it could make in jsdom requires a Monaco mock. **Step 6** — merges `apps/studio/tests/components/SQLEditor/Results.utils.test.ts` (`formatClipboardValue`/`formatCellValue`) into the colocated `apps/studio/components/interfaces/SQLEditor/UtilityPanel/Results.utils.test.ts` (`formatResults`/`convertResultsToMarkdown`/`convertResultsToJSON`/`getResultsHeaders`/`isLargeValue`/`convertResultsToCSV`) — both tested disjoint exports of the same source file. Deletes the `tests/` copy. This is the last step in the plan. ## Test plan - [x] `pnpm --filter studio typecheck` — no new errors in changed files - [x] `npx prettier --check` on all changed files - [x] Ran the new/changed e2e cases locally end-to-end against a live local stack — both pass - [x] `cd apps/studio && npx vitest run components/interfaces/SQLEditor/UtilityPanel/Results.utils.test.ts` — 42/42 passing after the merge <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added end-to-end coverage for destructive SQL query warning modal flow before forced execution. * Added end-to-end coverage for the AI Assistant debug flow when SQL execution fails. * Expanded unit test coverage for SQL editor results formatting utilities (clipboard and cell value formatting). * Removed the prior SQLEditor unit test suite and the older results-formatting unit tests. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
1 parent
e4f75bf74c
commit
0bef8e7d90
4 files changed
+122
-542
No files matched your search
@@ -406,6 +406,84 @@ test.describe('SQL Editor', () => {
|
||||
}
|
||||
})
|
||||
|
||||
test('destructive query warning modal: confirm re-runs the forced query', async ({ ref }) => {
|
||||
await expect(page.getByText('Loading...')).not.toBeVisible()
|
||||
await page.locator('.view-lines').click()
|
||||
await page.keyboard.press('ControlOrMeta+KeyA')
|
||||
await page.keyboard.type(`drop table pw_sql_editor_confirm_dne_e2e;`)
|
||||
|
||||
// Track whether the SQL editor dispatches this specific query to pg-meta
|
||||
let queryDispatched = false
|
||||
const listener = (request: any) => {
|
||||
if (
|
||||
request.url().includes('query?key=') &&
|
||||
request.method() === 'POST' &&
|
||||
request.postData()?.includes('drop table pw_sql_editor_confirm_dne_e2e')
|
||||
) {
|
||||
queryDispatched = true
|
||||
}
|
||||
}
|
||||
page.on('request', listener)
|
||||
|
||||
await page.getByTestId('sql-run-button').click()
|
||||
|
||||
// Destructive query -> confirmation modal, and no query is sent yet.
|
||||
await expect(page.getByRole('heading', { name: 'Potential issue detected' })).toBeVisible()
|
||||
expect(queryDispatched).toBe(false)
|
||||
|
||||
// Confirming forces the (same) destructive query to actually run.
|
||||
const sqlMutationPromise = waitForApiResponse(page, 'pg-meta', ref, 'query?key=', {
|
||||
method: 'POST',
|
||||
})
|
||||
await page.getByRole('button', { name: 'Run query' }).click()
|
||||
await sqlMutationPromise
|
||||
expect(queryDispatched).toBe(true)
|
||||
|
||||
page.removeListener('request', listener)
|
||||
|
||||
// clear SQL snippet
|
||||
if (!isCLI()) {
|
||||
await deleteSqlSnippet(page, ref, newSqlSnippetName)
|
||||
} else {
|
||||
await page.reload()
|
||||
}
|
||||
})
|
||||
|
||||
test('debug button opens the AI Assistant with the query error pre-filled', async ({ ref }) => {
|
||||
await expect(page.getByText('Loading...')).not.toBeVisible()
|
||||
await page.locator('.view-lines').click()
|
||||
await page.keyboard.press('ControlOrMeta+KeyA')
|
||||
await page.keyboard.type(`select * from pw_sql_editor_missing_table_e2e;`)
|
||||
|
||||
const sqlMutationPromise = waitForApiResponse(page, 'pg-meta', ref, 'query?key=', {
|
||||
method: 'POST',
|
||||
})
|
||||
await page.getByTestId('sql-run-button').click()
|
||||
await sqlMutationPromise
|
||||
|
||||
const debugButton = page.getByRole('button', { name: 'Debug with Assistant' })
|
||||
await expect(debugButton, 'Debug button should appear once the query errors').toBeVisible()
|
||||
await debugButton.click()
|
||||
|
||||
await expect(
|
||||
page.getByRole('button', { name: 'Close Assistant' }),
|
||||
'AI Assistant panel should open'
|
||||
).toBeVisible()
|
||||
await expect(
|
||||
page.getByRole('button', { name: 'Debug SQL snippet' }),
|
||||
'Assistant chat should be pre-named for the debug flow'
|
||||
).toBeVisible()
|
||||
|
||||
await page.getByRole('button', { name: 'Close Assistant' }).click()
|
||||
|
||||
// clear SQL snippet
|
||||
if (!isCLI()) {
|
||||
await deleteSqlSnippet(page, ref, newSqlSnippetName)
|
||||
} else {
|
||||
await page.reload()
|
||||
}
|
||||
})
|
||||
|
||||
test('should not show warning modal for safe alter database statement', async ({ ref }) => {
|
||||
await expect(page.getByText('Loading...')).not.toBeVisible()
|
||||
await page.locator('.view-lines').click()
|
||||
|
||||
Reference in new issue
Block a user