app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

status-copy.test.ts (4994B)


      1 import { describe, it, expect } from 'vitest';
      2 import {
      3   statusCopy,
      4   receiptCopy,
      5   type OperationFact
      6 } from '../../src/lib/presentation/status-copy';
      7 describe('finite evidence-specific presentation', () => {
      8   it('all target facts keep relay acceptance and exact readback distinct from person delivery or remote reading', () => {
      9     for (const role of ['public', 'recipient', 'archive'] as const)
     10       for (const outcome of [
     11         'pending',
     12         'accepted',
     13         'refused',
     14         'timed-out',
     15         'unknown'
     16       ] as const)
     17         for (const readback of [
     18           'confirmed',
     19           'not-observed',
     20           'unknown'
     21         ] as const) {
     22           const copy = receiptCopy({
     23             role,
     24             outcome,
     25             readback,
     26             eventId: 'event-A',
     27             destination: 'target-A'
     28           });
     29           expect(copy.text + ' ' + copy.readback).not.toMatch(
     30             /order placed|delivered to|person received|remote (?:seen|read)|guaranteed|complete sync/i
     31           );
     32           if (outcome !== 'accepted')
     33             expect(copy.text).not.toContain(' accepted the event.');
     34           if (outcome === 'accepted')
     35             expect(copy.text).toContain('relay accepted the event.');
     36           expect(copy.readback).toBe(
     37             readback === 'confirmed'
     38               ? 'Exact read-back is confirmed for this event and target.'
     39               : readback === 'not-observed'
     40                 ? 'Exact read-back was not observed for this event and target.'
     41                 : 'Exact read-back is unknown.'
     42           );
     43         }
     44   });
     45   it('never maps unsupported or unknown to success', () => {
     46     for (const state of ['unknown', 'new-future-state', null, undefined, 42])
     47       expect(statusCopy(state as OperationFact)).toEqual({
     48         tone: 'warning',
     49         text: 'The outcome is unknown. Keep the original operation for reconciliation.'
     50       });
     51   });
     52   it('maps local facts precisely', () => {
     53     expect(statusCopy('saved').text).toBe('Saved in this browser.');
     54     expect(statusCopy('encrypted-saved').text).toBe(
     55       'Saved encrypted in this browser.'
     56     );
     57     expect(statusCopy('unsaved').text).toContain('Unsent text is lost');
     58   });
     59   it('distinguishes each role and outcome', () => {
     60     for (const role of ['public', 'recipient', 'archive'] as const) {
     61       const values = [
     62         'accepted',
     63         'refused',
     64         'timed-out',
     65         'unknown',
     66         'pending'
     67       ] as const;
     68       const texts = values.map(
     69         (outcome) =>
     70           receiptCopy({
     71             role,
     72             outcome,
     73             readback: 'unknown',
     74             eventId: 'event-A',
     75             destination: 'target-A'
     76           }).text
     77       );
     78       expect(new Set(texts).size).toBe(values.length);
     79     }
     80     expect(
     81       receiptCopy({
     82         role: 'archive',
     83         outcome: 'accepted',
     84         readback: 'confirmed',
     85         eventId: 'event-A',
     86         destination: 'target-A'
     87       }).text
     88     ).toContain('sender archive');
     89     expect(
     90       receiptCopy({
     91         role: 'archive',
     92         outcome: 'accepted',
     93         readback: 'confirmed',
     94         eventId: 'event-A',
     95         destination: 'target-A'
     96       }).text
     97     ).not.toContain("recipient's inbox relay accepted");
     98   });
     99   it('does not promote exact readback into acceptance', () => {
    100     const copy = receiptCopy({
    101       role: 'recipient',
    102       outcome: 'unknown',
    103       readback: 'confirmed',
    104       eventId: 'event-A',
    105       destination: 'target-A'
    106     });
    107     expect(copy.text).toContain('could not confirm');
    108     expect(copy.readback).toContain('confirmed');
    109     expect(copy.tone).toBe('warning');
    110   });
    111   it('unknown runtime role/outcome/readback never crashes or becomes accepted', () => {
    112     expect(
    113       receiptCopy({
    114         role: 'future',
    115         outcome: 'future',
    116         readback: 'future',
    117         eventId: 'event-A',
    118         destination: 'target-A'
    119       } as never)
    120     ).toEqual({
    121       tone: 'warning',
    122       text: 'The target outcome is unknown.',
    123       readback: 'Exact read-back is unknown.'
    124     });
    125   });
    126   it('keeps input immutable and ignores unrelated seen metadata', () => {
    127     const fact = Object.freeze({
    128       role: 'recipient' as const,
    129       outcome: 'unknown' as const,
    130       readback: 'unknown' as const,
    131       eventId: 'event-A',
    132       destination: 'target-A',
    133       seenRelays: ['relay-A']
    134     });
    135     expect(receiptCopy(fact).text).toContain('could not confirm');
    136     expect(fact.outcome).toBe('unknown');
    137   });
    138   it('has no unsupported commercial or remote receipt promise', () => {
    139     for (const fact of [
    140       'saved',
    141       'save-failed',
    142       'unsaved',
    143       'encrypted-saved',
    144       'preparing',
    145       'sending',
    146       'partial',
    147       'extension-pending',
    148       'needs-action',
    149       'stopped',
    150       'local-read',
    151       'unknown'
    152     ] as const)
    153       expect(statusCopy(fact).text).not.toMatch(
    154         /order placed|delivered|remote read|reserved|guaranteed|permanent|global sync/i
    155       );
    156   });
    157 });