Skip to content

Commit 37748b5

Browse files
authored
chore: add E2E tests for simulating a drag and drop CSV (supabase#42658)
## 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? Chore: test drag and drop on table editor follow up for supabase#42655 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added comprehensive end-to-end test for CSV drag-and-drop import functionality that validates the complete import workflow: drag-drop detection on empty tables, import dialog display with accurate row counts, and successful data import to the grid. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 997d2c3 commit 37748b5

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

apps/studio/components/grid/components/grid/Grid.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ export const Grid = memo(
230230

231231
return (
232232
<div
233+
data-testid="table-editor-grid-container"
233234
className={cn('flex flex-col relative transition-colors', containerClass)}
234235
style={{ width: width || '100%', height: height || '50vh' }}
235236
onDragOver={onDragOver}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
id,pw_column
2+
1,drag drop value 1
3+
2,drag drop value 2
4+
3,drag drop value 3

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect, Page } from '@playwright/test'
22
import fs from 'fs'
33
import path from 'path'
4+
import { createTable as dbCreateTable, dropTable } from '../utils/db/index.js'
45
import { env } from '../env.config.js'
56
import { releaseFileOnceCleanup, withFileOnceSetup } from '../utils/once-per-file.js'
67
import { resetLocalStorage } from '../utils/reset-local-storage.js'
@@ -1172,4 +1173,65 @@ testRunner('table editor', () => {
11721173
await deleteTable(page, ref, sourceTableName)
11731174
await deleteTable(page, ref, targetTableName)
11741175
})
1176+
1177+
test('CSV drag and drop imports data on empty table', async ({ page, ref }) => {
1178+
const tableName = 'pw_table_csv_drag_drop'
1179+
1180+
await dropTable(tableName)
1181+
await dbCreateTable(tableName, columnName)
1182+
1183+
const loadPromise = waitForTableToLoad(page, ref)
1184+
await page.goto(toUrl(`/project/${ref}/editor?schema=public`))
1185+
await loadPromise
1186+
1187+
await page.getByRole('button', { name: `View ${tableName}`, exact: true }).click()
1188+
await page.waitForURL(/\/editor\/\d+\?schema=public$/)
1189+
1190+
await expect(
1191+
page.getByText('or drag and drop a CSV file here'),
1192+
'Empty table should show drag and drop hint'
1193+
).toBeVisible()
1194+
1195+
const csvFilePath = path.join(import.meta.dirname, 'files', 'table-editor-drag-drop.csv')
1196+
const csvBuffer = fs.readFileSync(csvFilePath)
1197+
1198+
// Synthesize a DataTransfer with the CSV file to simulate a browser file drag-and-drop
1199+
const dataTransfer = await page.evaluateHandle((csvBase64: string) => {
1200+
const dt = new DataTransfer()
1201+
const bytes = Uint8Array.from(atob(csvBase64), (c) => c.charCodeAt(0))
1202+
const file = new File([bytes], 'table-editor-drag-drop.csv', { type: 'text/csv' })
1203+
dt.items.add(file)
1204+
return dt
1205+
}, csvBuffer.toString('base64'))
1206+
1207+
const gridContainer = page.getByTestId('table-editor-grid-container')
1208+
1209+
await gridContainer.dispatchEvent('dragover', { dataTransfer })
1210+
await expect(
1211+
page.getByText('Drop your CSV file here'),
1212+
'Drag feedback should show when CSV is dragged over'
1213+
).toBeVisible()
1214+
1215+
await gridContainer.dispatchEvent('drop', { dataTransfer })
1216+
1217+
await expect(
1218+
page.getByText('A total of 3 rows will be'),
1219+
'Import dialog should show correct row count from CSV'
1220+
).toBeVisible({ timeout: 10_000 })
1221+
1222+
const waitForCsvInsert = createApiResponseWaiter(page, 'pg-meta', ref, 'query?key=', {
1223+
method: 'POST',
1224+
})
1225+
await page.getByRole('button', { name: 'Import data' }).click()
1226+
await waitForCsvInsert
1227+
await waitForGridDataToLoad(page, ref)
1228+
1229+
await expect(
1230+
page.getByText('3 records'),
1231+
'Table should show 3 records after drag and drop import'
1232+
).toBeVisible()
1233+
await expect(page.getByRole('gridcell', { name: 'drag drop value 1' })).toBeVisible()
1234+
1235+
await dropTable(tableName)
1236+
})
11751237
})

0 commit comments

Comments
 (0)