Files
automaker/apps/ui/tests/context/delete-context-file.spec.ts
Test User 46caae05d2 feat: improve test setup and authentication handling
- Added `dev:test` script to package.json for streamlined testing without file watching.
- Introduced `kill-test-servers` script to ensure no existing servers are running on test ports before executing tests.
- Enhanced Playwright configuration to use mock agent for tests, ensuring consistent API responses and disabling rate limiting.
- Updated various test files to include authentication steps and handle login screens, improving reliability and reducing flakiness in tests.
- Added `global-setup` for e2e tests to ensure proper initialization before test execution.
2025-12-30 00:06:27 -05:00

78 lines
2.2 KiB
TypeScript

/**
* Delete Context File E2E Test
*
* Happy path: Delete a context file via the UI
*/
import { test, expect } from '@playwright/test';
import * as fs from 'fs';
import * as path from 'path';
import {
resetContextDirectory,
setupProjectWithFixture,
getFixturePath,
navigateToContext,
waitForContextFile,
selectContextFile,
deleteSelectedContextFile,
clickElement,
fillInput,
waitForNetworkIdle,
authenticateForTests,
} from '../utils';
test.describe('Delete Context File', () => {
test.beforeEach(async () => {
resetContextDirectory();
});
test.afterEach(async () => {
resetContextDirectory();
});
test('should delete a context file via the UI', async ({ page }) => {
const fileName = 'to-delete.md';
await setupProjectWithFixture(page, getFixturePath());
await authenticateForTests(page);
await page.goto('/');
await waitForNetworkIdle(page);
await navigateToContext(page);
// First create a context file to delete
await clickElement(page, 'create-markdown-button');
await page.waitForSelector('[data-testid="create-markdown-dialog"]', { timeout: 5000 });
await fillInput(page, 'new-markdown-name', fileName);
await fillInput(page, 'new-markdown-content', '# Test File\n\nThis file will be deleted.');
await clickElement(page, 'confirm-create-markdown');
await page.waitForFunction(
() => !document.querySelector('[data-testid="create-markdown-dialog"]'),
{ timeout: 5000 }
);
// Wait for the file to appear in the list
await waitForContextFile(page, fileName);
// Select the file
await selectContextFile(page, fileName);
// Delete the selected file
await deleteSelectedContextFile(page);
// Verify the file is no longer in the list
await expect(async () => {
const fileButton = page.locator(`[data-testid="context-file-${fileName}"]`);
expect(await fileButton.count()).toBe(0);
}).toPass({ timeout: 10000 });
// Verify the file is deleted from the filesystem
const fixturePath = getFixturePath();
const contextPath = path.join(fixturePath, '.automaker', 'context', fileName);
expect(fs.existsSync(contextPath)).toBe(false);
});
});