Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/parity/src/collections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import { el, frameworks, render } from './harness.js';
const servers = Array.from({ length: 23 }, (_, index) => `server-${String(index + 1).padStart(2, '0')}`);
/** A paged source over the servers; `fail` makes the next request fail */
function serverSource() {
const state = { fail: false };
// `gate`: the answers wait until the test opens it (instead of 20 ms) – for states while loading
const state = { fail: false, gate: undefined as Promise<void> | undefined };
const getItems = vi.fn(async ({ page = 1, pageSize = 10, search = '' }: DataRequest) => {
await new Promise((done) => setTimeout(done, 20));
await (state.gate ?? new Promise((done) => setTimeout(done, 20)));
if (state.fail) throw new Error('offline');
const found = servers.filter((name) => name.includes(search));
return { items: found.slice((page - 1) * pageSize, page * pageSize), totalCount: found.length };
Expand Down Expand Up @@ -57,6 +58,9 @@ describe.each(frameworks)('%s', (framework) => {
it('shows placeholders while the first page loads, an error with a retry button', async () => {
const { source, state, getItems } = serverSource();
state.fail = true;
// The first answer waits – on a slow machine 20 ms were over before the placeholders were checked
let answer!: () => void;
state.gate = new Promise((done) => (answer = done));
await render(
framework,
el('DataView', {
Expand All @@ -68,6 +72,8 @@ describe.each(frameworks)('%s', (framework) => {
})
);
expect(screen.getByRole('list', { name: 'Server' })).toHaveAttribute('aria-busy', 'true');
state.gate = undefined;
answer();
const alert = await screen.findByRole('alert');
expect(alert).toHaveTextContent('The data could not be loaded.');
state.fail = false;
Expand Down
Loading