Files
pulse/tests/ui/pages.ui.js
T

139 lines
6.6 KiB
JavaScript
Raw Permalink Normal View History

'use strict';
const { test, expect } = require('./fixtures');
const PAGES = [
{ path: '/', title: 'Dashboard', heading: 'Dashboard' },
{ path: '/workers', title: 'Workers', heading: 'Workers' },
{ path: '/workflows', title: 'Workflows', heading: 'Workflows' },
{ path: '/executions', title: 'Executions', heading: 'Executions' },
{ path: '/quick', title: 'Quick Command', heading: 'Quick Command' },
{ path: '/scheduler', title: 'Scheduler', heading: 'Scheduler' },
];
for (const p of PAGES) {
test(`${p.path} loads without errors`, async ({ page }) => {
await page.goto(p.path);
await expect(page).toHaveTitle(`${p.title} | PULSE`);
await expect(page.getByRole('heading', { level: 1, name: p.heading })).toBeVisible();
await page.waitForLoadState('networkidle');
});
}
test('dashboard counts the three online workers', async ({ page }) => {
await page.goto('/');
await expect(page.locator('#dash-stat-total-val')).toHaveText('3');
await expect(page.locator('#dash-stat-online-val')).toHaveText('3');
await expect(page.locator('#dash-stat-offline-val')).toHaveText('0');
for (const n of ['node-01', 'node-02', 'node-03']) {
await expect(page.locator('#dash-workers-wrap').getByText(n, { exact: true })).toBeVisible();
}
});
test('workers page lists each worker as online', async ({ page }) => {
await page.goto('/workers');
const grid = page.locator('#wk-grid');
for (const n of ['node-01', 'node-02', 'node-03']) {
await expect(grid.getByText(n, { exact: true })).toBeVisible();
}
await expect(grid.getByText(/^online$/i)).toHaveCount(3);
});
test('workers page shows the commit each worker runs (#40)', async ({ page }) => {
const head = require('child_process').execFileSync('git', ['rev-parse', 'HEAD']).toString().trim();
await page.goto('/workers');
const versions = page.locator('#wk-grid [data-wk-version] a.wk-version');
await expect(versions).toHaveCount(3);
for (const v of await versions.all()) {
await expect(v).toHaveText(head.slice(0, 7));
await expect(v).toHaveAttribute('href', `https://code.lotusguild.org/LotusGuild/pulse/commit/${head}`);
}
});
test('quick command offers every online worker', async ({ page }) => {
await page.goto('/quick');
await expect(page.locator('#qc-worker option', { hasText: 'online' })).toHaveCount(3);
});
test('no page shows an em or en dash (house style)', async ({ page }) => {
for (const p of PAGES) {
await page.goto(p.path);
await page.waitForLoadState('networkidle');
const text = await page.evaluate(() => document.title + '\n' + document.body.innerText);
// En and em dash, built from char codes so this file itself stays dash-free.
const dash = new RegExp('[' + String.fromCharCode(0x2013, 0x2014) + ']');
const hits = text.split('\n').filter(l => dash.test(l));
expect(hits, `${p.path} shows dashes`).toEqual([]);
}
});
test.describe('first visit in a session', () => {
test('the boot screen names the app without a dash', async ({ page }) => {
await page.addInitScript(() => { try { sessionStorage.removeItem('lt_boot'); } catch (e) { /* ignore */ } });
await page.goto('/');
await expect(page.locator('#lt-boot-text')).toContainText('ALL SYSTEMS NOMINAL: PULSE', { timeout: 15_000 });
});
});
2026-11-23 14:08:30 -05:00
test('empty states say what to do next (#33)', async ({ page }) => {
for (const path of ['/api/workers', '/api/scheduled-commands', '/api/workflows']) {
await page.route(u => u.pathname === path, r => r.fulfill({ json: [] }));
}
await page.goto('/workers');
await expect(page.locator('#wk-grid')).toContainText('WORKER_API_KEY');
await expect(page.getByRole('link', { name: 'Worker setup guide' })).toHaveAttribute('href', /#pulse-worker-setup$/);
await page.goto('/scheduler');
await page.locator('#sc-wrap').getByRole('button', { name: '+ New Schedule' }).click();
await expect(page.locator('#sc-create-modal')).toBeVisible();
await page.keyboard.press('Escape');
await page.goto('/quick');
await page.locator('#qc-mode-multi').check(); // the checkbox list is the multi-worker picker
2026-11-23 14:08:30 -05:00
await expect(page.locator('#qc-worker-list').getByRole('link', { name: 'Workers' })).toHaveAttribute('href', '/workers');
await page.goto('/workflows');
await expect(page.getByRole('link', { name: 'Step types and examples' })).toHaveAttribute('href', /#workflows$/);
});
test('a schedule can be created with cron, edited, run now, and its runs found (#19)', async ({ page, problems }) => {
const name = `UI sched ${Date.now()}`;
await page.goto('/scheduler');
await page.locator('[data-action="sc:create-open"]').first().click(); // header button or empty state
const modal = page.locator('#sc-create-modal');
await modal.locator('#sc-name').fill(name);
await modal.locator('#sc-command').fill('echo first');
await modal.locator('input[name="sc-worker-cb"]').first().check();
await modal.locator('#sc-type').selectOption('cron');
await modal.locator('#sc-value').fill('0 9 * * 1-5');
// The preview lists the next three runs and the server's time zone.
await expect(modal.locator('#sc-preview li')).toHaveCount(3);
await expect(modal.locator('#sc-preview')).toContainText("server's time zone");
// A bad expression says so, without leaving the dialog.
await modal.locator('#sc-value').fill('0 99 * * *');
await expect(modal.locator('#sc-preview')).toContainText('Invalid schedule');
expect(problems.every(p => /400/.test(p))).toBe(true); // that preview's 400 is expected
problems.length = 0;
await modal.locator('#sc-value').fill('0 9 * * 1-5');
await modal.getByRole('button', { name: 'Create Schedule' }).click();
const row = page.locator('#sc-wrap tr', { hasText: name });
await expect(row).toContainText('Cron: 0 9 * * 1-5');
// Edit in place.
await row.getByRole('button', { name: /Edit/ }).click();
await expect(modal.locator('#sc-create-title')).toHaveText('Edit Scheduled Command');
await expect(modal.locator('#sc-value')).toHaveValue('0 9 * * 1-5');
await modal.locator('#sc-command').fill('echo edited-run');
await modal.getByRole('button', { name: 'Save Changes' }).click();
await expect(row).toContainText('echo edited-run');
// Run now, then follow Runs to the Automated tab, filtered to this schedule.
await row.getByRole('button', { name: /Run now/ }).click();
await page.waitForTimeout(1500);
await row.getByRole('link', { name: 'Runs' }).click();
await expect(page).toHaveURL(/view=automated/);
await expect(page.locator('#ex-search')).toHaveValue(`scheduler:${name}`);
const runs = page.locator('#ex-list-automated .ex-row');
await expect(runs).toHaveCount(1);
await expect(runs.first()).toContainText('echo edited-run');
});