diff --git a/e2e/checks/proposals-refresh.cjs b/e2e/checks/proposals-refresh.cjs new file mode 100644 index 000000000..9b53e0827 --- /dev/null +++ b/e2e/checks/proposals-refresh.cjs @@ -0,0 +1,112 @@ +const assert = require('node:assert/strict'); + +const waiting = { + id: '00000000-0000-4000-8000-000000000001', + title: 'Correct the workflow', + kind: 'workflow_change', + state: 'pending', + needs: 'owner', + actions: [], + created_at: '2026-01-01T00:00:00Z', +}; + +// Keep the last successful result and protect its tab from competing reads. +module.exports = async ({ page, go, shot, tolerate }) => { + const now = new Date(); + await page.clock.install({ time: now }); + await page.clock.pauseAt(new Date(now.getTime() + 60_000)); + tolerate(/503.*\/api\/proposals/); + + const pendingURL = '**/api/proposals?state=pending'; + let current = waiting; + let failNext; + await page.route(pendingURL, async route => { + if (failNext) { + const failing = failNext; + failNext = undefined; + await failing; + await route.fulfill({ status: 503, contentType: 'application/problem+json', json: { detail: 'Could not refresh proposals' } }); + return; + } + await route.fulfill({ json: [current] }); + }); + + await go('/proposals'); + const proposal = page.getByRole('link', { name: waiting.title, exact: true }); + const sort = page.getByRole('columnheader', { name: 'Proposal', exact: true }); + await proposal.waitFor(); + await sort.getByRole('button').press('Enter'); + await proposal.focus(); + + const failure = Promise.withResolvers(); + failNext = failure.promise; + const refresh = page.waitForRequest(pendingURL); + await page.clock.runFor(5000); + await refresh; + assert.equal(await proposal.isVisible(), true, 'the row should stay visible during a refresh'); + failure.resolve(); + + const error = page.getByRole('alert').filter({ hasText: 'Could not refresh proposals' }); + await error.waitFor(); + assert.equal(await proposal.isVisible(), true, 'a failed refresh must not replace the table'); + assert.equal(await sort.getAttribute('aria-sort'), 'ascending', 'the table should keep the operator’s sort'); + assert.equal(await proposal.evaluate(link => link === document.activeElement), true, 'the row should keep keyboard focus'); + await shot('failed-refresh-retains-table'); + + current = { ...waiting, title: 'Workflow correction updated' }; + await error.getByRole('button', { name: 'Retry' }).click(); + await page.getByRole('link', { name: current.title, exact: true }).waitFor(); + await error.waitFor({ state: 'hidden' }); + assert.equal(await sort.getAttribute('aria-sort'), 'ascending'); + + // A failed read belongs to its filter, not to the newly selected tab. + failNext = Promise.resolve(); + await page.clock.runFor(5000); + await error.waitFor(); + const published = Promise.withResolvers(); + await page.route('**/api/proposals?state=published', async route => { + await published.promise; + await route.fulfill({ json: [] }); + }); + const publishedTab = page.getByRole('tab', { name: 'Published' }); + await publishedTab.click(); + const loading = page.getByRole('status', { name: 'Loading proposals' }); + assert.equal(await loading.isVisible(), true, 'a new tab must not inherit the previous tab’s error'); + assert.equal(await error.isVisible(), false); + assert.equal(await page.getByRole('table').count(), 0, 'rows from the previous tab must not appear'); + published.resolve(); + const empty = page.getByText('No proposals', { exact: true }); + await empty.waitFor(); + + // A slow read must still take effect after a background poll ticks. + const slow = Promise.withResolvers(); + const stale = Promise.withResolvers(); + let first = true; + await page.route(pendingURL, async route => { + const read = first ? slow : stale; + first = false; + await read.promise; + await route.fulfill({ json: [waiting] }); + }); + const switched = page.waitForRequest(pendingURL); + await page.getByRole('tab', { name: 'Waiting' }).click(); + await switched; + await page.clock.runFor(5000); + slow.resolve(); + await proposal.waitFor({ timeout: 3000 }).catch(() => { + assert.fail('a slow read must render its result even after a background poll ticks'); + }); + + // A late response for Waiting cannot replace the Published result. + const nextPoll = page.waitForRequest(pendingURL); + await page.clock.runFor(5000); + await nextPoll; + await publishedTab.click(); + await empty.waitFor(); + const response = page.waitForResponse(pendingURL); + stale.resolve(); + await (await response).finished(); + await page.clock.runFor(50); + assert.equal(await proposal.isVisible(), false, 'a response for the previous tab must not replace the current one'); + assert.equal(await empty.isVisible(), true); +}; diff --git a/ui/src/proposals/ProposalsPage.vue b/ui/src/proposals/ProposalsPage.vue index b86a4ba4f..8eab0a990 100644 --- a/ui/src/proposals/ProposalsPage.vue +++ b/ui/src/proposals/ProposalsPage.vue @@ -15,14 +15,19 @@ import { useLiveResource } from "@/stores/session"; import { kindLabel, proposalTone, STATES } from "./state"; const state = ref("pending"); -const { data, error, reload } = useRead(() => api.proposals(state.value)); +const { data, error, loading, reload } = useRead(() => api.proposals(state.value)); onMounted(reload); watch(state, () => { data.value = undefined; + error.value = ""; void reload(); }); -useLiveResource(null, () => void reload()); -usePoll(reload); +// A background refresh must not supersede a slow read for the same tab. +function refresh(): void { + if (!loading.value) void reload(); +} +useLiveResource(null, refresh); +usePoll(refresh); const columns: DataTableColumn[] = [ { id: "title", label: "Proposal", fixed: true, width: "auto", sort: (p) => p.title }, @@ -42,11 +47,11 @@ const columns: DataTableColumn[] = [ - -
- No proposals + +
+ No proposals