Files
supabase/e2e/studio/features/index-advisor.spec.ts
Gildas Garcia 8ff22d7f0f fix: table editor columns cannot be selected nor advisor icon clicked (#44931)
## Problem

Since the drag & drop refactor, users cannot double click to select the
column name in the columns headers of the table editor. Besides, the
advisor button cannot be clicked either.

## Solution

- Add a delay constraint on the drag & drop operation, allowing click
events to trigger
- Add e2e tests to prevent future reggressions

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
  * Double-click column headers to copy column names to clipboard
  * Index Advisor warnings now accessible in the Table Editor

* **Improvements**
* Improved drag start timing and tolerance for smoother column dragging
  * Better screen reader announcement for index suggestion actions
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-16 15:12:39 +02:00

106 lines
3.5 KiB
TypeScript

import { expect } from '@playwright/test'
import { query } from '../utils/db/client.js'
import { createTable, dropTable } from '../utils/db/queries.js'
import { releaseFileOnceCleanup, withFileOnceSetup } from '../utils/once-per-file.js'
import { test, withSetupCleanup } from '../utils/test.js'
import { toUrl } from '../utils/to-url.js'
test.describe('Index Advisor', () => {
test.beforeAll(async () => {
await withFileOnceSetup(import.meta.url, async () => {
await query(`
create schema if not exists extensions;
create extension if not exists hypopg schema extensions cascade;
create extension if not exists index_advisor schema extensions cascade;
`)
})
})
test.afterAll(async () => {
await releaseFileOnceCleanup(import.meta.url)
})
test('should show Index Advisor filter after Index Advisor is enabled', async ({ page, ref }) => {
// Go to Query Performance page
await page.goto(toUrl(`/project/${ref}/observability/query-performance`))
await page.waitForLoadState('networkidle')
// Wait patiently for the Index Advisor button to appear
// Extensions may need time to initialize, so use a generous timeout
const indexAdvisorButton = page.getByRole('button', { name: /Index Advisor/i })
await expect(
indexAdvisorButton,
'Index Advisor filter button should be visible when Index Advisor is enabled'
).toBeVisible({ timeout: 30000 })
})
test('should show Index Advisor warnings in Query Performance', async ({ page, ref }) => {
const TEST_TABLE_NAME = 'pw_test_index_advisor'
await using _ = await withSetupCleanup(
async () => {
await createTable(TEST_TABLE_NAME, 'name', [
{
name: 'test',
},
{
name: 'demo',
},
{
name: 'test',
},
])
},
async () => {
await dropTable(TEST_TABLE_NAME)
}
)
// Run query that need indexes
await query(`SELECT * FROM ${TEST_TABLE_NAME} WHERE name = 'test';`)
// Navigate to Query Performance page
await page.goto(toUrl(`/project/${ref}/observability/query-performance`))
await page.waitForLoadState('networkidle')
// Wait for Index Advisor button and click to enable the filter
const indexAdvisorButton = page.getByRole('button', { name: /Index Advisor/i })
await expect(indexAdvisorButton, 'Index Advisor filter should be visible').toBeVisible({
timeout: 30000,
})
})
test('should show Index Advisor warnings in Table Editor', async ({ page, ref }) => {
const TEST_TABLE_NAME = 'pw_test_index_advisor_editor'
await using _ = await withSetupCleanup(
async () => {
await createTable(TEST_TABLE_NAME, 'name', [
{
name: 'test',
},
{
name: 'demo',
},
{
name: 'test',
},
])
},
async () => {
await dropTable(TEST_TABLE_NAME)
}
)
// Run query that need indexes
await query(`SELECT * FROM ${TEST_TABLE_NAME} WHERE name = 'test';`)
// Navigate to table editor page
await page.goto(toUrl(`/project/${ref}/editor?schema=public`))
await page.getByLabel(`View ${TEST_TABLE_NAME}`).click()
await expect(page.getByText('demo')).toBeVisible()
await page.waitForLoadState('networkidle')
await page.getByRole('button', { name: `View name index suggestion`, exact: true }).click()
await expect(page.getByRole('dialog', { name: 'Index Recommendation' })).toBeVisible()
})
})