mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-31 06:42:03 +00:00
simplify the e2e tests
This commit is contained in:
146
apps/ui/tests/context/add-context-image.spec.ts
Normal file
146
apps/ui/tests/context/add-context-image.spec.ts
Normal file
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Add Context Image E2E Test
|
||||
*
|
||||
* Happy path: Import an image file to the context 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,
|
||||
waitForNetworkIdle,
|
||||
} from '../utils';
|
||||
|
||||
test.describe('Add Context Image', () => {
|
||||
let testImagePath: string;
|
||||
|
||||
test.beforeAll(async () => {
|
||||
// Create a simple test image (1x1 red PNG)
|
||||
const fixturePath = getFixturePath();
|
||||
testImagePath = path.join(fixturePath, '..', 'test-image.png');
|
||||
|
||||
// Create a minimal PNG (1x1 pixel red image)
|
||||
const pngHeader = Buffer.from([
|
||||
0x89,
|
||||
0x50,
|
||||
0x4e,
|
||||
0x47,
|
||||
0x0d,
|
||||
0x0a,
|
||||
0x1a,
|
||||
0x0a, // PNG signature
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0d, // IHDR chunk length
|
||||
0x49,
|
||||
0x48,
|
||||
0x44,
|
||||
0x52, // IHDR
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x01, // width: 1
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x01, // height: 1
|
||||
0x08,
|
||||
0x02, // bit depth: 8, color type: 2 (RGB)
|
||||
0x00,
|
||||
0x00,
|
||||
0x00, // compression, filter, interlace
|
||||
0x90,
|
||||
0x77,
|
||||
0x53,
|
||||
0xde, // IHDR CRC
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0c, // IDAT chunk length
|
||||
0x49,
|
||||
0x44,
|
||||
0x41,
|
||||
0x54, // IDAT
|
||||
0x08,
|
||||
0xd7,
|
||||
0x63,
|
||||
0xf8,
|
||||
0xcf,
|
||||
0xc0,
|
||||
0x00,
|
||||
0x00,
|
||||
0x01,
|
||||
0x01,
|
||||
0x01,
|
||||
0x00, // compressed data
|
||||
0x18,
|
||||
0xdd,
|
||||
0x8d,
|
||||
0xb4, // IDAT CRC
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00, // IEND chunk length
|
||||
0x49,
|
||||
0x45,
|
||||
0x4e,
|
||||
0x44, // IEND
|
||||
0xae,
|
||||
0x42,
|
||||
0x60,
|
||||
0x82, // IEND CRC
|
||||
]);
|
||||
|
||||
fs.writeFileSync(testImagePath, pngHeader);
|
||||
});
|
||||
|
||||
test.beforeEach(async () => {
|
||||
resetContextDirectory();
|
||||
});
|
||||
|
||||
test.afterEach(async () => {
|
||||
resetContextDirectory();
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
// Clean up test image
|
||||
if (fs.existsSync(testImagePath)) {
|
||||
fs.unlinkSync(testImagePath);
|
||||
}
|
||||
});
|
||||
|
||||
test('should import an image file to context', async ({ page }) => {
|
||||
await setupProjectWithFixture(page, getFixturePath());
|
||||
await page.goto('/');
|
||||
await waitForNetworkIdle(page);
|
||||
|
||||
await navigateToContext(page);
|
||||
|
||||
// Get the file input element and set the file
|
||||
const fileInput = page.locator('[data-testid="file-import-input"]');
|
||||
|
||||
// Use setInputFiles to upload the image
|
||||
await fileInput.setInputFiles(testImagePath);
|
||||
|
||||
// Wait for the file to appear in the list (filename should be the base name)
|
||||
const fileName = path.basename(testImagePath);
|
||||
await waitForContextFile(page, fileName, 15000);
|
||||
|
||||
// Verify the file appears in the list
|
||||
const fileButton = page.locator(`[data-testid="context-file-${fileName}"]`);
|
||||
await expect(fileButton).toBeVisible();
|
||||
|
||||
// Verify the file exists on disk
|
||||
const fixturePath = getFixturePath();
|
||||
const contextImagePath = path.join(fixturePath, '.automaker', 'context', fileName);
|
||||
await expect(async () => {
|
||||
expect(fs.existsSync(contextImagePath)).toBe(true);
|
||||
}).toPass({ timeout: 5000 });
|
||||
});
|
||||
});
|
||||
67
apps/ui/tests/context/context-file-management.spec.ts
Normal file
67
apps/ui/tests/context/context-file-management.spec.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Context File Management E2E Test
|
||||
*
|
||||
* Happy path: Create a markdown context file
|
||||
*/
|
||||
|
||||
import { test, expect } from '@playwright/test';
|
||||
import {
|
||||
resetContextDirectory,
|
||||
setupProjectWithFixture,
|
||||
getFixturePath,
|
||||
navigateToContext,
|
||||
waitForFileContentToLoad,
|
||||
switchToEditMode,
|
||||
waitForContextFile,
|
||||
clickElement,
|
||||
fillInput,
|
||||
getByTestId,
|
||||
waitForNetworkIdle,
|
||||
getContextEditorContent,
|
||||
} from '../utils';
|
||||
|
||||
test.describe('Context File Management', () => {
|
||||
test.beforeEach(async () => {
|
||||
resetContextDirectory();
|
||||
});
|
||||
|
||||
test.afterEach(async () => {
|
||||
resetContextDirectory();
|
||||
});
|
||||
|
||||
test('should create a new markdown context file', async ({ page }) => {
|
||||
await setupProjectWithFixture(page, getFixturePath());
|
||||
await page.goto('/');
|
||||
await waitForNetworkIdle(page);
|
||||
|
||||
await navigateToContext(page);
|
||||
|
||||
await clickElement(page, 'create-markdown-button');
|
||||
await page.waitForSelector('[data-testid="create-markdown-dialog"]', { timeout: 5000 });
|
||||
|
||||
await fillInput(page, 'new-markdown-name', 'test-context.md');
|
||||
const testContent = '# Test Context\n\nThis is test content';
|
||||
await fillInput(page, 'new-markdown-content', testContent);
|
||||
|
||||
await clickElement(page, 'confirm-create-markdown');
|
||||
|
||||
await page.waitForFunction(
|
||||
() => !document.querySelector('[data-testid="create-markdown-dialog"]'),
|
||||
{ timeout: 5000 }
|
||||
);
|
||||
|
||||
await waitForContextFile(page, 'test-context.md', 10000);
|
||||
|
||||
const fileButton = await getByTestId(page, 'context-file-test-context.md');
|
||||
await expect(fileButton).toBeVisible();
|
||||
|
||||
await fileButton.click();
|
||||
await waitForFileContentToLoad(page);
|
||||
await switchToEditMode(page);
|
||||
|
||||
await page.waitForSelector('[data-testid="context-editor"]', { timeout: 5000 });
|
||||
|
||||
const editorContent = await getContextEditorContent(page);
|
||||
expect(editorContent).toBe(testContent);
|
||||
});
|
||||
});
|
||||
75
apps/ui/tests/context/delete-context-file.spec.ts
Normal file
75
apps/ui/tests/context/delete-context-file.spec.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* 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,
|
||||
} 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 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, 10000);
|
||||
|
||||
// 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user