Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/e2e/supabase/features/logs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test.beforeAll(async ({ request }) => {
query: "select cron.schedule('test_cron', '5 seconds', $$SELECT auth.email()$$);"
}});

await new Promise(r => setTimeout(r, 10000))
await new Promise(r => setTimeout(r, 12000))
});

test('receives logs from API Gateway', async ({ page }) => {
Expand Down
51 changes: 38 additions & 13 deletions test/e2e/supabase/features/schema_modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import { test, expect, Page, Locator } from '@playwright/test';
import { searchLogs } from '../lib/utils';
import supabase from '../lib/supabase';

const LOG_WAIT_TIME = 8000;
let functionName = '';

test.beforeEach(async ({ browserName }) => {
test.beforeEach(async ({ page, browserName }) => {
functionName = `function_${Date.now()}_${browserName}`;

await supabase.functions.invoke(functionName, { body: { name: 'Functions' } });

await new Promise(r => setTimeout(r, 8000));
await page.waitForTimeout(LOG_WAIT_TIME);
});

test('copies correct log id and status to clipboard', async ({ page, browserName }) => {
test('verifies clipboard functionality for log detail fields (id, status, timestamp, method, path)', async ({ page, browserName }) => {
await page.goto('/project/default/logs/edge-logs');

await expect(page.locator('.recharts-surface')).toBeVisible();
Expand All @@ -24,14 +25,35 @@ test('copies correct log id and status to clipboard', async ({ page, browserName

await page.getByRole('gridcell', { name: functionName }).first().click();

const idSelection = page.getByTestId('log-selection-id');
await expectClipboardViaPaste(page, browserName, idSelection, 'Copy id');
const fieldsToTest = [
{ locator: () => page.getByTestId('log-selection-id'), label: 'Copy id' },
{ locator: () => page.getByTestId('log-selection').getByRole('button', { name: 'status' }), label: 'Copy status' },
{ locator: () => page.getByRole('button', { name: 'timestamp' }), label: 'Copy timestamp' },
{ locator: () => page.getByRole('button', { name: 'method POST' }), label: 'Copy method' },
{ locator: () => page.getByRole('button', { name: 'path /functions/v1/' }), label: 'Copy path' }
];

for (const field of fieldsToTest) {
await expectClipboardViaPaste(page, browserName, field.locator(), field.label);
}

const expandButton = page.getByRole('button', { name: 'Expand' });

await expandButton.click();

const metadata = page.getByText('[ { "request": [ { "headers').first();

await expect(metadata).toContainText('"method": "POST",');
await expect(metadata).toContainText(`"path": "/functions/v1/${functionName}",`);
await expect(metadata).toContainText('"status_code": 500');
});

async function expectClipboardViaPaste(page: Page, browserName: string, selection: Locator, menuItemName: string): Promise<void> {
const expectedText = (await selection.innerText()).split('\n').map(line => line.trim()).filter(Boolean).at(-1);
if (!expectedText) { throw new Error('No text found in selection') }

const expectedClipboard = menuItemName === 'Copy timestamp' ? parseToMicroseconds(expectedText) : expectedText;

await selection.click();

const menuItem = page.getByRole('menuitem', { name: menuItemName })
Expand All @@ -40,24 +62,27 @@ async function expectClipboardViaPaste(page: Page, browserName: string, selectio

switch(browserName) {
case 'chromium':
await chromiumClipboardReadText(page, expectedText);
await chromiumClipboardReadText(page, expectedClipboard);
break;

default:
await defaultClipboardReadText(page, expectedText);
await defaultClipboardReadText(page, expectedClipboard);
}
}

async function chromiumClipboardReadText(page: Page, expectedText: string) {
await expect(page.getByText('Copied to clipboard')).toBeVisible();

const clipboardText = await page.evaluate(async () => { return await navigator.clipboard.readText(); });
function parseToMicroseconds(dateStr: string): string {
const microseconds = new Date(dateStr).getTime() * 1000;
return microseconds.toString();
}

expect(clipboardText).toBe(expectedText);
async function chromiumClipboardReadText(page: Page, expectedText: string) {
await expect.poll(async () => {
return await page.evaluate(() => navigator.clipboard.readText());
}).toBe(expectedText);
}

async function defaultClipboardReadText(page: Page, expectedText: string) {
const pasteTarget = page.locator('input[placeholder="Search events"]');
const pasteTarget = page.getByRole('textbox', { name: 'Search collections...' });
await pasteTarget.fill('');
await pasteTarget.focus();

Expand Down
Loading