From 52d78f15215d1aaa87e63d4553cb5e10e7ac977e Mon Sep 17 00:00:00 2001 From: "chris.dumas" Date: Mon, 26 Oct 2026 22:43:59 +0000 Subject: [PATCH] Add comprehensive portal UI coverage --- e2e/portal.spec.js | 169 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) diff --git a/e2e/portal.spec.js b/e2e/portal.spec.js index 2fca669..bd5ad5c 100644 --- a/e2e/portal.spec.js +++ b/e2e/portal.spec.js @@ -58,6 +58,27 @@ test.describe('ComfyUI Portal browser flow', () => { const overflow = await page.evaluate(() => document.documentElement.scrollWidth > window.innerWidth + 1); expect(overflow, 'mobile layout should not create horizontal scrolling').toBe(false); }); + + test('requires both credentials before submitting the sign-in form', async ({ page }) => { + await expect(page.getByLabel('Username')).toHaveAttribute('required', ''); + await expect(page.getByLabel('Password')).toHaveAttribute('required', ''); + await page.getByRole('button', { name: 'Sign in' }).click(); + await expect(page).toHaveURL(/\/login/); + }); + + test('submits the remember-me preference without contacting a real login endpoint', async ({ page }) => { + let payload = null; + await page.route('**/api/login', async route => { + payload = JSON.parse(route.request().postData() || '{}'); + await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ user: adminUser }) }); + }); + await page.getByLabel('Username').fill('test-user'); + await page.getByLabel('Password').fill('test-password'); + await page.getByLabel('Remember me').uncheck(); + await page.getByRole('button', { name: 'Sign in' }).click(); + await expect(page).toHaveURL(/\/jobs/); + await expect.poll(() => payload).toMatchObject({ username: 'test-user', password: 'test-password', remember: false }); + }); }); const adminUser = { id: 'user_admin', username: 'admin', displayName: 'Admin', role: 'admin' }; @@ -438,4 +459,152 @@ test.describe('ComfyUI Portal read-only UI states', () => { await expect(page.getByText('Node C')).toBeVisible(); await expect(page.getByText('Permission denied')).toBeVisible(); }); + + test('redirects to sign in when an authenticated session expires on reload', async ({ page }) => { + await mockReadOnlyApi(page); + await page.goto('/jobs'); + await page.unroute('**/api/**'); + await page.route('**/api/**', async route => { + if (new URL(route.request().url()).pathname === '/api/me') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ user: null }) }); + return route.continue(); + }); + await page.reload(); + await expect(page).toHaveURL(/\/login/); + await expect(page.getByRole('heading', { name: 'Sign in' })).toBeVisible(); + }); + + test('refreshes persistent model statistics after a newly discovered job', async ({ page }) => { + let refreshCount = 0; + await mockReadOnlyApi(page); + await page.unroute('**/api/**'); + await page.route('**/api/**', async route => { + const pathname = new URL(route.request().url()).pathname; + if (pathname === '/api/me') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ user: adminUser }) }); + if (pathname === '/api/model-stats') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(refreshCount ? { totalJobs: 4, totalModels: 3, models: [...modelStats.models, { name: 'new.safetensors', jobCount: 1 }] } : modelStats) }); + if (pathname === '/api/jobs') { refreshCount += 1; return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ jobs: [], running: null }) }); } + if (pathname === '/api/server-status') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ status: connectedServer }) }); + if (pathname === '/api/comfy/manager') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(managerInfo) }); + return route.continue(); + }); + await page.goto('/jobs'); + await expect(page.getByText('3 tracked jobs · 2 models')).toBeVisible(); + await page.getByRole('button', { name: 'Refresh' }).click(); + await expect(page.getByText('4 tracked jobs · 3 models')).toBeVisible(); + await expect(page.getByText('new.safetensors')).toBeVisible(); + }); + + test('does not duplicate a job when the same prompt is returned again', async ({ page }) => { + const jobs = [{ promptId: 'stable-id', title: 'Stable job', status: 'completed', queuedAt: 1000, durationMs: 1000, outputCount: 0, assets: [], models: [{ nodeId: '1', type: 'Checkpoint', name: 'same.safetensors' }], progress: null }]; + await mockReadOnlyApi(page, { jobs, stats: { totalJobs: 1, totalModels: 1, models: [{ name: 'same.safetensors', jobCount: 1 }] } }); + await page.goto('/jobs'); + await page.getByRole('button', { name: 'Refresh' }).click(); + await expect(page.locator('.job')).toHaveCount(1); + await expect(page.getByText('1 tracked jobs · 1 models')).toBeVisible(); + }); + + test('renders unknown job statuses without losing the job card', async ({ page }) => { + const jobs = [{ promptId: 'unknown-status', title: 'Future status', status: 'paused', queuedAt: null, durationMs: null, outputCount: 0, assets: [], models: [], progress: null }]; + await mockReadOnlyApi(page, { jobs }); + await page.goto('/jobs'); + await expect(page.getByRole('heading', { name: 'Future status' })).toBeVisible(); + await expect(page.getByText('paused', { exact: true })).toBeVisible(); + await expect(page.getByText('Duration Unavailable')).toBeVisible(); + }); + + test('does not overflow with a long title and model name', async ({ page }) => { + const title = 'A very long job title that should remain readable without breaking the monitor layout'; + const model = 'a-very-long-model-name-that-should-be-truncated-safely.safetensors'; + const jobs = [{ promptId: 'long-content', title, status: 'completed', queuedAt: 1000, durationMs: 1000, outputCount: 0, assets: [], models: [{ nodeId: '1', type: 'CheckpointLoader', name: model }], progress: null }]; + await page.setViewportSize({ width: 768, height: 800 }); + await mockReadOnlyApi(page, { jobs }); + await page.goto('/jobs'); + await expect(page.getByRole('heading', { name: title })).toBeVisible(); + const overflow = await page.evaluate(() => document.documentElement.scrollWidth > window.innerWidth + 1); + expect(overflow).toBe(false); + }); + + test('recovers the server connection after a refresh', async ({ page }) => { + let statusRequests = 0; + await mockReadOnlyApi(page); + await page.unroute('**/api/**'); + await page.route('**/api/**', async route => { + const pathname = new URL(route.request().url()).pathname; + if (pathname === '/api/me') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ user: adminUser }) }); + if (pathname === '/api/server-status') { statusRequests += 1; if (statusRequests === 1) return route.fulfill({ status: 502, contentType: 'application/json', body: JSON.stringify({ error: 'offline' }) }); return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ status: connectedServer }) }); } + if (pathname === '/api/model-stats') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(modelStats) }); + if (pathname === '/api/jobs') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ jobs: [], running: null }) }); + if (pathname === '/api/comfy/manager') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(managerInfo) }); + return route.continue(); + }); + await page.goto('/jobs'); + await expect(page.getByText('Unavailable', { exact: true })).toBeVisible(); + await page.getByRole('button', { name: 'Refresh' }).click(); + await expect(page.getByText('Connected', { exact: true })).toBeVisible(); + }); + + test('keeps persistent stats visible when jobs are temporarily unavailable', async ({ page }) => { + await mockReadOnlyApi(page, { jobs: 'unavailable' }); + await page.goto('/jobs'); + await expect(page.getByText('Unable to load jobs.')).toBeVisible(); + await expect(page.getByText('3 tracked jobs · 2 models')).toBeVisible(); + }); + + test('repeated refreshes do not duplicate rendered job cards', async ({ page }) => { + const jobs = [{ promptId: 'one-card', title: 'One card', status: 'completed', queuedAt: 1000, durationMs: 1000, outputCount: 0, assets: [], models: [], progress: null }]; + await mockReadOnlyApi(page, { jobs }); + await page.goto('/jobs'); + await page.getByRole('button', { name: 'Refresh' }).click(); + await page.getByRole('button', { name: 'Refresh' }).click(); + await expect(page.locator('.job')).toHaveCount(1); + }); + + test('rejects a mocked switch-version request and re-enables controls', async ({ page }) => { + await mockReadOnlyApi(page); + await page.route('**/api/comfy/switch-version', async route => route.fulfill({ status: 400, contentType: 'application/json', body: JSON.stringify({ error: 'Version is unavailable' }) })); + await page.goto('/jobs'); + await page.locator('select').selectOption('0.2.9'); + page.once('dialog', dialog => dialog.accept()); + await page.getByRole('button', { name: 'Switch version' }).click(); + await expect(page.getByText('Version is unavailable')).toBeVisible(); + await expect(page.getByRole('button', { name: 'Switch version' })).toBeEnabled(); + }); + + test('renders intermediate mocked update progress counts', async ({ page }) => { + await mockReadOnlyApi(page); + await page.route('**/api/comfy/update-all', async route => route.fulfill({ status: 202, contentType: 'application/json', body: JSON.stringify({ message: 'started' }) })); + await page.route('**/api/comfy/update-status', async route => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ status: { total_count: 5, done_count: 2, in_progress_count: 1, is_processing: true }, progress: { target: 'Node C', uiTarget: 'Node C', totalCount: 5, doneCount: 2 }, result: null }) })); + await page.goto('/jobs'); + page.once('dialog', dialog => dialog.accept()); + await page.getByRole('button', { name: 'Update all' }).click(); + await page.waitForTimeout(5200); + await expect(page.getByText('Update all in progress: 2 of 5 tasks complete. Current task: Node C.')).toBeVisible(); + await expect(page.getByRole('button', { name: 'Updating everything…' })).toBeDisabled(); + }); + + test('exposes the monitor controls with accessible names and keyboard focus', async ({ page }) => { + await mockReadOnlyApi(page); + await page.goto('/jobs'); + await expect(page.getByRole('button', { name: 'Refresh' })).toBeVisible(); + await expect(page.getByRole('button', { name: 'Sign out' })).toBeVisible(); + await page.getByRole('button', { name: 'Refresh' }).focus(); + await expect(page.getByRole('button', { name: 'Refresh' })).toBeFocused(); + }); + + test('maintains tablet layout without horizontal overflow', async ({ page }) => { + await page.setViewportSize({ width: 768, height: 1024 }); + await mockReadOnlyApi(page); + await page.goto('/jobs'); + const overflow = await page.evaluate(() => document.documentElement.scrollWidth > window.innerWidth + 1); + expect(overflow).toBe(false); + }); + + test('keeps long output filenames inside their asset caption', async ({ page }) => { + const filename = 'very-long-output-filename-that-must-remain-contained-within-the-card.png'; + const jobs = [{ promptId: 'long-file', title: 'Long filename', status: 'completed', queuedAt: 1000, durationMs: 1000, outputCount: 1, assets: [{ filename, url: `/api/assets?filename=${encodeURIComponent(filename)}&subfolder=&type=output`, type: 'image' }], models: [], progress: null }]; + await mockReadOnlyApi(page, { jobs }); + await page.goto('/jobs'); + await expect(page.getByText(filename)).toBeVisible(); + const overflow = await page.evaluate(() => document.documentElement.scrollWidth > window.innerWidth + 1); + expect(overflow).toBe(false); + }); });