fix(ui): keep proposals visible during background refresh
Quality / check (pull_request) Successful in 3m9s
Quality / check (pull_request) Successful in 3m9s
(cherry picked from commit 7334f659fd14f68186f009279dc6cda4c4cd56fd)
This commit is contained in:
1 parent
f6eff43ca4
commit
2e9d14412e
2 files changed
+124
-7
No files matched your search
@@ -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);
|
||||
};
|
||||
@@ -15,14 +15,19 @@ import { useLiveResource } from "@/stores/session";
|
||||
import { kindLabel, proposalTone, STATES } from "./state";
|
||||
|
||||
const state = ref<ProposalState>("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<Proposal>[] = [
|
||||
{ id: "title", label: "Proposal", fixed: true, width: "auto", sort: (p) => p.title },
|
||||
@@ -42,11 +47,11 @@ const columns: DataTableColumn<Proposal>[] = [
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
</PageHeader>
|
||||
<ReadError v-if="error" :message="error" retry-label="Retry" @retry="reload" />
|
||||
<div v-else-if="!data" role="status" aria-label="Loading proposals" class="space-y-2"><Skeleton class="h-10 w-full" /><Skeleton class="h-10 w-full" /></div>
|
||||
<Empty v-else-if="!data.length"><EmptyHeader><EmptyTitle>No proposals</EmptyTitle></EmptyHeader></Empty>
|
||||
<ReadError v-if="error" :class="data && 'mb-2'" :message="error" retry-label="Retry" @retry="reload" />
|
||||
<div v-if="!data && !error" role="status" aria-label="Loading proposals" class="space-y-2"><Skeleton class="h-10 w-full" /><Skeleton class="h-10 w-full" /></div>
|
||||
<Empty v-else-if="data && !data.length"><EmptyHeader><EmptyTitle>No proposals</EmptyTitle></EmptyHeader></Empty>
|
||||
<DataTable
|
||||
v-else
|
||||
v-else-if="data"
|
||||
:columns="columns"
|
||||
:rows="data"
|
||||
:row-key="(p) => p.id"
|
||||
|
||||
Reference in new issue
Block a user