diff --git a/frontend/e2e/datatable.spec.ts b/frontend/e2e/datatable.spec.ts index f1be2d2fb2..31a264f861 100644 --- a/frontend/e2e/datatable.spec.ts +++ b/frontend/e2e/datatable.spec.ts @@ -1,6 +1,6 @@ -import { test, expect } from '@playwright/test' +import { test, expect, Page } from '@playwright/test' -test('create new data table with custom instance', async ({ page }) => { +async function setupNewDataTable(page: Page): Promise<{ datatableId: string }> { // Generate unique ID with timestamp const timestamp = Date.now() const datatableId = `datatable_${timestamp}` @@ -67,4 +67,86 @@ test('create new data table with custom instance', async ({ page }) => { // Verify success toast appears const saveSuccessToast = page.locator('text=saved successfully') await expect(saveSuccessToast).toBeVisible({ timeout: 10000 }) + + return { datatableId } +} + +test('create new data table, add a new table, CRUD rows and delete the table', async ({ page }) => { + let { datatableId } = await setupNewDataTable(page) + const table = page.locator('table') + const lastRow = table.locator('tr').nth(-2) + lastRow.locator('button:has-text("Manage")').click() + + // Wait for DB Manager drawer to appear + const dbManager = page.locator('#db-manager-drawer') + await expect(dbManager).toBeVisible() + await dbManager.locator('button:has-text("New table")').click() + const tableEditor = page.locator('#db-table-editor-drawer') + await expect(tableEditor).toBeVisible() + + const nameInput = page.locator('label:has-text("Name")').locator('input') + await nameInput.fill('friend') + + const columnsTable = page.locator('#columns-section table') + const addColumnButton = columnsTable.locator('button:has-text("Add")') + await addColumnButton.click() + + const newColRow = columnsTable.locator('tr').nth(-2) + const newColNameInput = newColRow.locator('td').nth(0).locator('input') + await newColNameInput.fill('name') + + const newColTypeSelect = newColRow.locator('td').nth(1).locator('input') + await newColTypeSelect.click() + + await page.locator('li:has-text("TEXT")').first().click() + + await page.locator('button:has-text("Create table")').click() + + await page.locator('#db-table-editor-confirmation-modal button:has-text("Create")').click() + + // Verify success toast appears + const saveSuccessToast = page.locator('text=friend created!') + await expect(saveSuccessToast).toBeVisible({ timeout: 10000 }) + + const friendTableKey = page.locator('.db-manager-table-key', { hasText: 'friend' }) + await expect(friendTableKey).toBeVisible({ timeout: 10000 }) + await friendTableKey.click() + + // Add a new row + await dbManager.locator('button:has-text("Insert")').click() + let insertRowDrawer = page.locator('#insert-row-drawer') + await expect(insertRowDrawer).toBeVisible({ timeout: 10000 }) + await insertRowDrawer.locator('textarea').fill('Alice', { force: true }) // Not sure why force is needed here + await insertRowDrawer.locator('button:has-text("Insert")').click() + + const rowInsertedToast = page.locator('text=Row inserted') + await expect(rowInsertedToast).toBeVisible({ timeout: 10000 }) + + const insertedRow = dbManager.locator('.ag-cell-value', { hasText: 'Alice' }) + await expect(insertedRow).toBeVisible({ timeout: 10000 }) + + // Edit the row + await insertedRow.dblclick() + const cellEditor = dbManager.locator('.ag-cell-editor input') + await cellEditor.fill('Bob') + await cellEditor.press('Enter') + + const rowUpdatedToast = page.locator('text=Value updated') + await expect(rowUpdatedToast).toBeVisible({ timeout: 10000 }) + const updatedRow = dbManager.locator('.ag-cell-value', { hasText: 'Bob' }) + await expect(updatedRow).toBeVisible({ timeout: 10000 }) + + const actionsBtn = dbManager.locator('#db-manager-table-actions-friend') + await actionsBtn.click() + + await page.locator('button:has-text("Delete table")').click() + + let deletePermanentlyBtn = page.locator( + '#db-manager-delete-table-confirmation-modal button:has-text("Delete")' + ) + await deletePermanentlyBtn.click() + + await expect(page.locator("text=Table 'friend' deleted successfully")).toBeVisible({ + timeout: 10000 + }) }) diff --git a/frontend/src/lib/components/DBManager.svelte b/frontend/src/lib/components/DBManager.svelte index 393277f7f7..b75df41af3 100644 --- a/frontend/src/lib/components/DBManager.svelte +++ b/frontend/src/lib/components/DBManager.svelte @@ -1,14 +1,6 @@ @@ -20,6 +21,7 @@