Clarify Settings preparation messages #81
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@hledger-reports/web': patch
|
||||
---
|
||||
|
||||
Keep the saved-report warning distinct from queue status and retry availability in Settings. Messages and preparation behavior are unchanged.
|
||||
@@ -4,11 +4,10 @@
|
||||
import type { PageProps } from './$types';
|
||||
|
||||
let { data, form }: Pick<PageProps, 'data' | 'form'> = $props();
|
||||
const canPrepare = $derived(
|
||||
data.preparation !== 'unavailable' &&
|
||||
data.preparation !== 'pending' &&
|
||||
data.preparation !== 'running'
|
||||
);
|
||||
const queueStatus = $derived(data.preparation);
|
||||
const savedUpdateFailed = $derived(data.failedUpdate !== null);
|
||||
const preparationInProgress = $derived(queueStatus === 'pending' || queueStatus === 'running');
|
||||
const canPrepare = $derived(queueStatus !== 'unavailable' && !preparationInProgress);
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -31,30 +30,32 @@
|
||||
{/if}
|
||||
<h2 class="section-title">Report preparation</h2>
|
||||
<section class="preparation-status" aria-label="Preparation status">
|
||||
{#if data.preparation === 'pending'}
|
||||
{#if queueStatus === 'pending'}
|
||||
<p>Report preparation is queued. Waiting for the worker.</p>
|
||||
{:else if data.preparation === 'running'}
|
||||
{:else if queueStatus === 'running'}
|
||||
<p>Preparing reports.</p>
|
||||
{:else if data.preparation === 'canceled'}
|
||||
{:else if queueStatus === 'canceled'}
|
||||
<p>The queue marked this request canceled.</p>
|
||||
{:else if data.preparation === 'failed' && !data.failedUpdate}
|
||||
<p role="alert">
|
||||
The preparation job did not complete. Check the journal and worker, then try again.
|
||||
</p>
|
||||
{:else if data.preparation === 'status-unreadable'}
|
||||
{:else if queueStatus === 'status-unreadable'}
|
||||
<p role="alert">
|
||||
Preparation status couldn't be read. Reload status or try Prepare reports again.
|
||||
</p>
|
||||
{:else if data.preparation === 'unavailable'}
|
||||
{:else if queueStatus === 'unavailable'}
|
||||
<p role="alert">
|
||||
The job queue is unavailable, so reports cannot be prepared. Reload status to check again.
|
||||
If the problem persists, ask the server operator to check the queue and restart the web
|
||||
service.
|
||||
</p>
|
||||
{:else if !data.failedUpdate}
|
||||
<p>No preparation is currently running.</p>
|
||||
{:else if !savedUpdateFailed}
|
||||
{#if queueStatus === 'failed'}
|
||||
<p role="alert">
|
||||
The preparation job did not complete. Check the journal and worker, then try again.
|
||||
</p>
|
||||
{:else if queueStatus === 'idle'}
|
||||
<p>No preparation is currently running.</p>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if data.failedUpdate}
|
||||
{#if savedUpdateFailed}
|
||||
<p role="alert">
|
||||
The last failed update didn’t replace the saved report.
|
||||
{#if canPrepare}Choose Prepare reports to try again.{/if}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { render } from 'svelte/server';
|
||||
import { expect, it, vi } from 'vitest';
|
||||
import Settings from './+page.svelte';
|
||||
import type { PageProps } from './$types';
|
||||
|
||||
vi.mock('$app/paths', () => ({
|
||||
resolve: (route: string) => route.replace('/(protected)', '')
|
||||
@@ -87,21 +88,64 @@ it.each([
|
||||
expect(text).toContain('Last recorded strict check Could not validate');
|
||||
});
|
||||
|
||||
it('explains the queue outage and disables Prepare reports', () => {
|
||||
const { body } = render(Settings, {
|
||||
function renderPreparation(
|
||||
preparation: PageProps['data']['preparation'],
|
||||
failedUpdate: PageProps['data']['failedUpdate'] = null
|
||||
) {
|
||||
return render(Settings, {
|
||||
props: {
|
||||
data: {
|
||||
...layoutData,
|
||||
accountSidebar: null,
|
||||
reportStatus: 'missing',
|
||||
preparation: 'unavailable',
|
||||
reportStatus: 'ready',
|
||||
preparation,
|
||||
failedUpdate,
|
||||
journalSummary: null,
|
||||
validation: null,
|
||||
validationReadFailed: false
|
||||
},
|
||||
form: null
|
||||
}
|
||||
});
|
||||
expect(body).toContain('The job queue is unavailable, so reports cannot be prepared.');
|
||||
}).body;
|
||||
}
|
||||
|
||||
const failedUpdate = { asOf: '2026-04-16' };
|
||||
const savedReportWarning = 'didn’t replace the saved report';
|
||||
|
||||
it('keeps browsing and the saved-report warning available while a retry is queued', () => {
|
||||
const body = renderPreparation('pending', failedUpdate);
|
||||
expect(body).toContain('Report preparation is queued.');
|
||||
expect(body).toContain('<a href="/registers/cash">Browse reports</a>');
|
||||
expect(body).toContain(savedReportWarning);
|
||||
expect(body).not.toContain('Choose Prepare reports to try again.');
|
||||
expect(body).toMatch(/<button [^>]*disabled[^>]*>Prepare reports<\/button>/);
|
||||
});
|
||||
|
||||
it.each(['failed', 'idle'] as const)(
|
||||
'uses the saved-report warning instead of a generic %s notice and offers a retry',
|
||||
(preparation) => {
|
||||
const body = renderPreparation(preparation, failedUpdate);
|
||||
expect(body).toContain(savedReportWarning);
|
||||
expect(body).not.toMatch(
|
||||
/The preparation job did not complete|No preparation is currently running/
|
||||
);
|
||||
expect(body).toContain('Choose Prepare reports to try again.');
|
||||
expect(body).toMatch(/<button (?![^>]*\bdisabled\b)[^>]*>Prepare reports<\/button>/);
|
||||
}
|
||||
);
|
||||
|
||||
it('keeps browsing and the saved-report warning available during a queue outage', () => {
|
||||
const body = renderPreparation('unavailable', failedUpdate);
|
||||
expect(body).toContain('The job queue is unavailable');
|
||||
expect(body).toContain('<a href="/registers/cash">Browse reports</a>');
|
||||
expect(body).toContain(savedReportWarning);
|
||||
expect(body).not.toContain('Choose Prepare reports to try again.');
|
||||
expect(body).toMatch(/<button [^>]*disabled[^>]*>Prepare reports<\/button>/);
|
||||
});
|
||||
|
||||
it('does not infer a failed update when queue status is unreadable', () => {
|
||||
const body = renderPreparation('status-unreadable');
|
||||
expect(body).toContain("Preparation status couldn't be read");
|
||||
expect(body).not.toContain(savedReportWarning);
|
||||
expect(body).toContain('<a href="/registers/cash">Browse reports</a>');
|
||||
expect(body).toMatch(/<button (?![^>]*\bdisabled\b)[^>]*>Prepare reports<\/button>/);
|
||||
});
|
||||
Reference in new issue
Block a user