feat(home): import messages open with a full-restoration or partial-recovery headline; BDR-040 recorded
This commit is contained in:
1 parent
de2bd0437e
commit
62b8a43e09
7 files changed
+106
-23
No files matched your search
@@ -16,6 +16,8 @@ const REQUIRED = [
|
||||
'home.import.error_generic',
|
||||
'home.import.error_attachment_stripped',
|
||||
'home.import.archive_ok',
|
||||
'home.import.complete',
|
||||
'home.import.degraded',
|
||||
'home.import.snapshot_reason.unsupported_envelope',
|
||||
'home.import.snapshot_reason.schema',
|
||||
'home.import.snapshot_reason.caps',
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
/**
|
||||
* T15 (STEP6 §7, §16): the home route on Step 6 archives, with
|
||||
* `importReportFromPdf` mocked. Same sheet: archive kept in the store and
|
||||
* mirrored, archive_ok alert. Other sheet: the report is rebased on the
|
||||
* `importReportFromPdf` mocked. Every alert opens with a headline: complete
|
||||
* restoration or partial recovery. Same sheet: archive kept in the store and
|
||||
* mirrored, complete + archive_ok. Other sheet: the report is rebased on the
|
||||
* loaded sheet (unresolved flags, labels from the archived snapshot, sheet
|
||||
* ref updated) and the alert says so with the count. Snapshot rejected: the
|
||||
* ref updated) and the alert says degraded with the count; a rebase that
|
||||
* resolved everything stays complete. Snapshot rejected: degraded with the
|
||||
* reason label. Attachment stripped: its error message.
|
||||
*/
|
||||
import {
|
||||
@@ -159,7 +161,9 @@ async function mountAndPickPdf(): Promise<void> {
|
||||
}
|
||||
|
||||
const alertMock = () => vi.mocked(window.alert)
|
||||
const alertText = () => alertMock().mock.calls[0]![0] as string
|
||||
/** The alert split on its blank lines: headline first, then the detail lines. */
|
||||
const alertLines = () =>
|
||||
(alertMock().mock.calls[0]![0] as string).split('\n\n')
|
||||
const errorText = () => screen.queryByText(/./, { selector: 'p.text-red-700' })
|
||||
|
||||
describe('HomeRoute import of a Step 6 archive', () => {
|
||||
@@ -176,7 +180,10 @@ describe('HomeRoute import of a Step 6 archive', () => {
|
||||
report.id,
|
||||
)
|
||||
expect(alertMock()).toHaveBeenCalledTimes(1)
|
||||
expect(alertText()).toBe(fr['home.import.archive_ok'])
|
||||
expect(alertLines()).toEqual([
|
||||
fr['home.import.complete'],
|
||||
fr['home.import.archive_ok'],
|
||||
])
|
||||
})
|
||||
|
||||
it('other sheet: rebases onto the loaded sheet, labels from the archived snapshot, alert with the count', async () => {
|
||||
@@ -200,12 +207,32 @@ describe('HomeRoute import of a Step 6 archive', () => {
|
||||
// The archive stays as exported, never rebased.
|
||||
expect(useReportStore.getState().archive).toEqual(archive)
|
||||
expect(alertMock()).toHaveBeenCalledTimes(1)
|
||||
expect(alertText()).toBe(
|
||||
[
|
||||
fr['home.import.archive_ok'],
|
||||
fr['home.import.rebased']!.replace('{count}', '2'),
|
||||
].join('\n\n'),
|
||||
)
|
||||
expect(alertLines()).toEqual([
|
||||
fr['home.import.degraded'],
|
||||
fr['home.import.archive_ok'],
|
||||
fr['home.import.rebased']!.replace('{count}', '2'),
|
||||
])
|
||||
})
|
||||
|
||||
it('other sheet, everything resolved: complete headline, the rebased line says 0', async () => {
|
||||
const report = minimalReport(sheet, {
|
||||
sheet: { ...sheet.sheet.ref, documentSha256: OTHER_SHA },
|
||||
observations: reportWithHip().observations,
|
||||
})
|
||||
const archive = archiveEnvelope(sheet, report)
|
||||
archive.sheetSnapshot.ref.documentSha256 = OTHER_SHA
|
||||
importMock.mockResolvedValue(archived(report, archive))
|
||||
await mountAndPickPdf()
|
||||
await screen.findByTestId('editor-route')
|
||||
const opened = useReportStore.getState().report!
|
||||
expect(opened.sheet).toEqual(sheet.sheet.ref)
|
||||
expect(opened.observations[0]!.zones[0]!.unresolved).toBeUndefined()
|
||||
expect(alertMock()).toHaveBeenCalledTimes(1)
|
||||
expect(alertLines()).toEqual([
|
||||
fr['home.import.complete'],
|
||||
fr['home.import.archive_ok'],
|
||||
fr['home.import.rebased']!.replace('{count}', '0'),
|
||||
])
|
||||
})
|
||||
|
||||
it('snapshot rejected: the report opens, the alert names the reason, no archive kept', async () => {
|
||||
@@ -219,12 +246,13 @@ describe('HomeRoute import of a Step 6 archive', () => {
|
||||
expect(useReportStore.getState().archive).toBeNull()
|
||||
expect(sessionStorage.getItem(ARCHIVE_KEY)).toBeNull()
|
||||
expect(alertMock()).toHaveBeenCalledTimes(1)
|
||||
expect(alertText()).toBe(
|
||||
expect(alertLines()).toEqual([
|
||||
fr['home.import.degraded'],
|
||||
fr['home.import.snapshot_rejected']!.replace(
|
||||
'{reason}',
|
||||
fr['home.import.snapshot_reason.caps']!,
|
||||
),
|
||||
)
|
||||
])
|
||||
})
|
||||
|
||||
it('attachment_stripped → its error message, nothing opened', async () => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* Step 6 Phase 0 characterisation of the import flow on the home route, with
|
||||
* `importReportFromPdf` mocked: the migration alert with its count, the three
|
||||
* ImportError kinds plus the generic error mapped to the FR messages, and
|
||||
* the navigation to /editor on success. Kept green unchanged by Step 6.
|
||||
* `importReportFromPdf` mocked: the migration alert (degraded headline, then
|
||||
* the count), the three ImportError kinds plus the generic error mapped to
|
||||
* the FR messages, and the navigation to /editor on success.
|
||||
*/
|
||||
import {
|
||||
describe,
|
||||
@@ -110,7 +110,7 @@ describe('HomeRoute import: success paths', () => {
|
||||
expect(alertMock()).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('alerts with the unresolved count (zones + findings) after a lossy migration', async () => {
|
||||
it('alerts "degraded" then the unresolved count (zones + findings) after a lossy migration', async () => {
|
||||
importMock.mockResolvedValue(
|
||||
outcome({ migrated: true, unresolvedZones: 1, unresolvedFindings: 1 }),
|
||||
)
|
||||
@@ -118,8 +118,11 @@ describe('HomeRoute import: success paths', () => {
|
||||
await screen.findByTestId('editor-route')
|
||||
expect(alertMock()).toHaveBeenCalledTimes(1)
|
||||
const message = alertMock().mock.calls[0]![0] as string
|
||||
expect(message).toBe(fr['home.import.migrated']!.replace('{count}', '2'))
|
||||
expect(message).toContain('2')
|
||||
const [headline, ...lines] = message.split('\n\n')
|
||||
expect(headline).toBe(fr['home.import.degraded'])
|
||||
expect(lines).toEqual([
|
||||
fr['home.import.migrated']!.replace('{count}', '2'),
|
||||
])
|
||||
})
|
||||
|
||||
it('stays silent on a migration that lost nothing', async () => {
|
||||
|
||||
Reference in new issue
Block a user