File size: 2,119 Bytes
cb43fbd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { systemNoticeDtoSchema } from './system-notice.schema';

import { describe, it, expect } from 'vitest';

describe('systemNoticeDtoSchema', () => {
  it('accepts a minimal notice (required fields only)', () => {
    const parsed = systemNoticeDtoSchema.parse({
      id: 'welcome',
      display: 'modal',
      severity: 'info',
      titleKey: 'notice.welcome.title',
      bodyKey: 'notice.welcome.body',
      dismissible: true,
    });
    expect(parsed.id).toBe('welcome');
  });

  it('accepts a rich notice with media, highlights and a nav CTA', () => {
    expect(
      systemNoticeDtoSchema.safeParse({
        id: 'release',
        display: 'banner',
        severity: 'warn',
        titleKey: 't',
        bodyKey: 'b',
        dismissible: false,
        bodyParams: { version: '3.1' },
        icon: 'sparkles',
        media: { src: '/img.png', altKey: 'alt', placement: 'hero' },
        highlights: [{ labelKey: 'h1', iconName: 'check' }],
        cta: { kind: 'nav', labelKey: 'open', href: '/whats-new' },
      }).success,
    ).toBe(true);
  });

  it('accepts an action CTA with the discriminated-union shape', () => {
    expect(
      systemNoticeDtoSchema.safeParse({
        id: 'x',
        display: 'toast',
        severity: 'critical',
        titleKey: 't',
        bodyKey: 'b',
        dismissible: true,
        cta: {
          kind: 'action',
          labelKey: 'do',
          actionId: 'reload',
          dismissOnAction: true,
        },
      }).success,
    ).toBe(true);
  });

  it('rejects an unknown display value and a malformed CTA', () => {
    expect(
      systemNoticeDtoSchema.safeParse({
        id: 'x',
        display: 'popup',
        severity: 'info',
        titleKey: 't',
        bodyKey: 'b',
        dismissible: true,
      }).success,
    ).toBe(false);
    expect(
      systemNoticeDtoSchema.safeParse({
        id: 'x',
        display: 'modal',
        severity: 'info',
        titleKey: 't',
        bodyKey: 'b',
        dismissible: true,
        cta: { kind: 'nav', labelKey: 'open' },
      }).success,
    ).toBe(false);
  });
});