LibreChat/e2e/specs/mock/scenarios/assistant-delete-dialog.spec.ts
Danny Avila 876d212e1a
Some checks failed
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Backend Unit Tests / backend (push) Blocked by required conditions
Codegraph E2E Vote Gate / Gate (push) Waiting to run
Codegraph E2E Votes / vote (shard 1/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 10/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 2/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 3/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 4/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 5/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 6/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 7/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 8/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 9/10) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/chat (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Frontend Unit Tests / frontend (push) Blocked by required conditions
Playwright E2E Tests / Codegraph select (push) Waiting to run
Playwright E2E Tests / e2e () (push) Blocked by required conditions
Playwright E2E Tests / MCP list_changed (replica count 1) (push) Blocked by required conditions
Playwright E2E Tests / MCP list_changed (replica count 2) (push) Blocked by required conditions
Playwright E2E Tests / MCP Apps (browser and server) (push) Waiting to run
Playwright E2E Tests / e2e (push) Blocked by required conditions
Channel Gateway / gateway (push) Has been cancelled
Main Promotion Policy Tests / Main promotion denial and fast-forward tests (push) Has been cancelled
🧪 test: Keep Handlers Answering When a Mock Spec Removes a Route (#18069)
2026-11-11 19:17:26 -05:00

168 lines
6.1 KiB
TypeScript

import { expect, test } from '@playwright/test';
import type { Locator, Page } from '@playwright/test';
import { getAccessToken, requestJson } from '../helpers';
import { openSidebar } from './sidebar';
import { unroute } from '../fixtures';
/**
* The Assistant Builder's delete control confirms through the shared `OGDialog` template.
* The trigger is a named button, the dialog carries its title and warning, Cancel and Escape
* leave the assistant in place, Delete removes it, and a failed delete keeps it listed while
* telling the user.
*/
type CreatedAssistant = { id: string };
type AssistantList = { data: { id: string }[] };
const ASSISTANT_NAME = 'E2E delete dialog assistant';
const ENDPOINT_QUERY = 'endpoint=assistants&model=gpt-4o-mini';
async function createAssistant(page: Page): Promise<CreatedAssistant> {
await page.goto('/c/new', { timeout: 10000 });
const token = await getAccessToken(page);
return requestJson<CreatedAssistant>(page, {
path: '/api/assistants/v2',
token,
method: 'POST',
body: { endpoint: 'assistants', model: 'gpt-4o-mini', name: ASSISTANT_NAME },
});
}
async function assistantExists(page: Page, assistantId: string): Promise<boolean> {
const token = await getAccessToken(page);
const list = await requestJson<AssistantList>(page, {
path: `/api/assistants/v2?${ENDPOINT_QUERY}`,
token,
});
return list.data.some((assistant) => assistant.id === assistantId);
}
async function deleteAssistant(page: Page, assistantId: string) {
if (!(await assistantExists(page, assistantId))) {
return;
}
const token = await getAccessToken(page);
await requestJson(page, {
path: `/api/assistants/v2/${encodeURIComponent(assistantId)}?${ENDPOINT_QUERY}`,
token,
method: 'DELETE',
body: { endpoint: 'assistants' },
});
}
async function openDeleteTrigger(page: Page): Promise<Locator> {
await page.goto(`/c/new?${ENDPOINT_QUERY}`, { timeout: 10000 });
await openSidebar(page);
/** The mobile drawer opens on chat history; its panels are items of the Control Panel menu. */
const controlPanel = page.getByRole('button', { name: 'Control Panel' });
if (await controlPanel.isVisible()) {
await controlPanel.click();
await page.getByRole('menuitemcheckbox', { name: 'Assistant Builder' }).click();
} else {
await page.getByRole('button', { name: 'Assistant Builder' }).first().click();
}
await expect(
page.getByTestId('select-dropdown-button').first().getByText(ASSISTANT_NAME, { exact: true }),
).toBeVisible();
const trigger = page.getByRole('button', { name: 'Delete Assistant', exact: true });
await expect(trigger).toBeVisible();
return trigger;
}
async function expectConfirmDialog(page: Page): Promise<Locator> {
const dialog = page.getByRole('dialog', { name: 'Delete Assistant' });
await expect(dialog).toBeVisible();
await expect(
dialog.getByText('Are you sure you want to delete this Assistant? This cannot be undone.'),
).toBeVisible();
return dialog;
}
test.describe('assistant delete confirmation', () => {
test('confirming the dialog deletes the assistant @scenario:assistant-delete-dialog-confirm', async ({
page,
}) => {
test.setTimeout(60000);
const assistant = await createAssistant(page);
try {
const trigger = await openDeleteTrigger(page);
await trigger.click();
const dialog = await expectConfirmDialog(page);
await dialog.getByRole('button', { name: 'Delete', exact: true }).click();
await expect(dialog).toBeHidden();
await expect(page.getByText('Successfully deleted assistant', { exact: true })).toBeVisible();
await expect.poll(() => assistantExists(page, assistant.id)).toBe(false);
} finally {
await deleteAssistant(page, assistant.id);
}
});
test('Cancel and Escape keep the assistant and return focus @scenario:assistant-delete-dialog-dismiss', async ({
page,
isMobile,
}) => {
test.setTimeout(60000);
const assistant = await createAssistant(page);
try {
const trigger = await openDeleteTrigger(page);
await trigger.focus();
await page.keyboard.press('Enter');
let dialog = await expectConfirmDialog(page);
await dialog.getByRole('button', { name: 'Cancel', exact: true }).click();
await expect(dialog).toBeHidden();
await expect(trigger).toBeFocused();
await page.keyboard.press('Enter');
dialog = await expectConfirmDialog(page);
await page.keyboard.press('Escape');
await expect(dialog).toBeHidden();
/** The dialog takes the Escape, so on mobile the drawer it was opened from stays open
* and the trigger is there to take focus back (berry-13/LibreChat#428). */
await expect(trigger).toBeFocused();
if (isMobile) {
await expect(
page.getByRole('button', { name: 'Close sidebar' }).filter({ visible: true }).first(),
).toBeVisible();
}
expect(await assistantExists(page, assistant.id)).toBe(true);
} finally {
await deleteAssistant(page, assistant.id);
}
});
test('a failed delete keeps the assistant and reports the error @scenario:assistant-delete-dialog-error', async ({
page,
}) => {
test.setTimeout(60000);
const assistant = await createAssistant(page);
const deleteUrl = (url: URL) =>
url.pathname.startsWith('/api/assistants/') && url.pathname.endsWith(assistant.id);
try {
const trigger = await openDeleteTrigger(page);
await page.route(deleteUrl, (route) =>
route.request().method() === 'DELETE'
? route.fulfill({ status: 500, json: { message: 'delete failed' } })
: route.fallback(),
);
await trigger.click();
const dialog = await expectConfirmDialog(page);
await dialog.getByRole('button', { name: 'Delete', exact: true }).click();
await expect(
page.getByText('There was an error deleting the assistant', { exact: true }),
).toBeVisible();
await unroute(page, deleteUrl);
expect(await assistantExists(page, assistant.id)).toBe(true);
} finally {
await unroute(page, deleteUrl);
await deleteAssistant(page, assistant.id);
}
});
});