const { test, expect } = require('@playwright/test');
test.use({
baseURL: 'http://localhost:8080',
});
test.describe('Interstellar WASM Graph Database', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
await expect(page.locator('#status')).toHaveText('Ready', { timeout: 10000 });
});
test('should initialize WASM module successfully', async ({ page }) => {
const status = page.locator('#status');
await expect(status).toHaveClass(/ready/);
await expect(status).toHaveText('Ready');
await expect(page.locator('#vertexCount')).toHaveText('0');
await expect(page.locator('#edgeCount')).toHaveText('0');
});
test('should create sample graph successfully', async ({ page }) => {
await page.click('#btnCreateSample');
await expect(page.locator('#vertexCount')).toHaveText('7', { timeout: 5000 });
await expect(page.locator('#edgeCount')).toHaveText('8');
});
test('should run query via console', async ({ page }) => {
await page.click('#btnCreateSample');
await expect(page.locator('#vertexCount')).toHaveText('7');
const queryInput = page.locator('#queryInput');
await queryInput.fill("graph.V().hasLabel('person').values('name').toList()");
await page.click('#btnRunQuery');
const output = page.locator('#consoleOutput');
await expect(output).toContainText('Alice');
await expect(output).toContainText('Bob');
await expect(output).toContainText('Carol');
});
test('should run query with keyboard shortcut', async ({ page }) => {
await page.click('#btnCreateSample');
await expect(page.locator('#vertexCount')).toHaveText('7');
const queryInput = page.locator('#queryInput');
await queryInput.fill("graph.V().toCount()");
await queryInput.press('Enter');
const output = page.locator('#consoleOutput');
await expect(output).toContainText('graph.V().toCount()');
await expect(output.locator('.output-entry').last().locator('.output-result')).toHaveText('7');
});
test('should use query examples dropdown', async ({ page }) => {
const dropdown = page.locator('#queryExamples');
await dropdown.selectOption({ label: 'Count vertices' });
const queryInput = page.locator('#queryInput');
await expect(queryInput).toHaveValue('graph.V().toCount()');
});
test('should filter by age predicate', async ({ page }) => {
await page.click('#btnCreateSample');
await expect(page.locator('#vertexCount')).toHaveText('7');
const queryInput = page.locator('#queryInput');
await queryInput.fill("graph.V().hasLabel('person').hasWhere('age', P.gte(25n)).values('name').toList()");
await page.click('#btnRunQuery');
const output = page.locator('#consoleOutput');
await expect(output).toContainText('Alice');
await expect(output).toContainText('Bob');
await expect(output).toContainText('Carol');
await expect(output).toContainText('David');
await expect(output).not.toContainText('"Eve"');
});
test('should navigate to visualization tab', async ({ page }) => {
await page.click('#btnCreateSample');
await expect(page.locator('#vertexCount')).toHaveText('7');
await page.click('.tab[data-tab="visualization"]');
await expect(page.locator('#visualization-tab')).toHaveClass(/active/);
await expect(page.locator('#graphCanvas')).toBeVisible();
await expect(page.locator('#graphCanvas .node')).toHaveCount(7, { timeout: 10000 });
});
test('should clear graph', async ({ page }) => {
await page.click('#btnCreateSample');
await expect(page.locator('#vertexCount')).toHaveText('7');
await page.click('#btnClearGraph');
await expect(page.locator('#vertexCount')).toHaveText('0');
await expect(page.locator('#edgeCount')).toHaveText('0');
});
test('should clear console output', async ({ page }) => {
const queryInput = page.locator('#queryInput');
await queryInput.fill("graph.V().toCount()");
await page.click('#btnRunQuery');
const output = page.locator('#consoleOutput');
await expect(output).toContainText('toCount');
await page.click('#btnClearOutput');
await expect(output).toBeEmpty();
});
test('should handle query errors gracefully', async ({ page }) => {
const queryInput = page.locator('#queryInput');
await queryInput.fill('invalidFunction()');
await page.click('#btnRunQuery');
const output = page.locator('#consoleOutput');
await expect(output).toContainText('Error');
});
test('should add vertex via mutation query', async ({ page }) => {
const queryInput = page.locator('#queryInput');
await queryInput.fill("graph.V().addV('test').property('name', 'TestNode').toList()");
await page.click('#btnRunQuery');
await expect(page.locator('#vertexCount')).toHaveText('1');
});
});