@asteby/metacore-runtime-react 53.4.0 → 53.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +73 -0
- package/dist/display-value.d.ts +11 -0
- package/dist/display-value.d.ts.map +1 -1
- package/dist/display-value.js +26 -1
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +17 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/setup/addon-config-surface.d.ts +110 -0
- package/dist/setup/addon-config-surface.d.ts.map +1 -0
- package/dist/setup/addon-config-surface.js +553 -0
- package/dist/setup/connector-form-model.d.ts +40 -0
- package/dist/setup/connector-form-model.d.ts.map +1 -0
- package/dist/setup/connector-form-model.js +76 -0
- package/dist/setup/flow-model.d.ts +49 -0
- package/dist/setup/flow-model.d.ts.map +1 -0
- package/dist/setup/flow-model.js +124 -0
- package/dist/setup/health-card.d.ts +25 -0
- package/dist/setup/health-card.d.ts.map +1 -0
- package/dist/setup/health-card.js +21 -0
- package/dist/setup/index.d.ts +11 -0
- package/dist/setup/index.d.ts.map +1 -0
- package/dist/setup/index.js +13 -0
- package/dist/setup/messages.d.ts +15 -0
- package/dist/setup/messages.d.ts.map +1 -0
- package/dist/setup/messages.js +249 -0
- package/dist/setup/records-table.d.ts +24 -0
- package/dist/setup/records-table.d.ts.map +1 -0
- package/dist/setup/records-table.js +80 -0
- package/dist/setup/setup-flow.d.ts +30 -0
- package/dist/setup/setup-flow.d.ts.map +1 -0
- package/dist/setup/setup-flow.js +277 -0
- package/dist/setup/setup-form-step.d.ts +20 -0
- package/dist/setup/setup-form-step.d.ts.map +1 -0
- package/dist/setup/setup-form-step.js +173 -0
- package/dist/setup/step-status-badge.d.ts +12 -0
- package/dist/setup/step-status-badge.d.ts.map +1 -0
- package/dist/setup/step-status-badge.js +21 -0
- package/dist/setup/tone.d.ts +8 -0
- package/dist/setup/tone.d.ts.map +1 -0
- package/dist/setup/tone.js +33 -0
- package/dist/setup/types.d.ts +130 -0
- package/dist/setup/types.d.ts.map +1 -0
- package/dist/setup/types.js +1 -0
- package/package.json +5 -1
- package/src/__tests__/addon-config-surface.test.tsx +248 -0
- package/src/__tests__/image-stack.test.tsx +58 -1
- package/src/__tests__/setup-components.test.tsx +147 -0
- package/src/__tests__/setup-flow-model.test.ts +117 -0
- package/src/__tests__/setup-flow.test.tsx +424 -0
- package/src/display-value.tsx +30 -1
- package/src/dynamic-columns.tsx +21 -5
- package/src/index.ts +25 -0
- package/src/setup/addon-config-surface.tsx +1262 -0
- package/src/setup/connector-form-model.ts +115 -0
- package/src/setup/flow-model.ts +156 -0
- package/src/setup/health-card.tsx +131 -0
- package/src/setup/index.ts +23 -0
- package/src/setup/messages.ts +263 -0
- package/src/setup/records-table.tsx +186 -0
- package/src/setup/setup-flow.tsx +562 -0
- package/src/setup/setup-form-step.tsx +342 -0
- package/src/setup/step-status-badge.tsx +47 -0
- package/src/setup/tone.ts +44 -0
- package/src/setup/types.ts +147 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
4
|
+
|
|
5
|
+
const lang = { current: 'es' }
|
|
6
|
+
vi.mock('react-i18next', () => {
|
|
7
|
+
const t = (k: string, o?: { defaultValue?: string }) => o?.defaultValue ?? k
|
|
8
|
+
return { useTranslation: () => ({ t, i18n: { language: lang.current, exists: () => true } }) }
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
import { StepStatusBadge } from '../setup/step-status-badge'
|
|
12
|
+
import { RecordsTable, copyText } from '../setup/records-table'
|
|
13
|
+
import { HealthCard } from '../setup/health-card'
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
cleanup()
|
|
17
|
+
lang.current = 'es'
|
|
18
|
+
vi.restoreAllMocks()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
describe('StepStatusBadge', () => {
|
|
22
|
+
it.each([
|
|
23
|
+
['pending', 'Pendiente'],
|
|
24
|
+
['running', 'En curso'],
|
|
25
|
+
['ok', 'Listo'],
|
|
26
|
+
['warn', 'Con avisos'],
|
|
27
|
+
['error', 'Con error'],
|
|
28
|
+
['blocked', 'Bloqueado'],
|
|
29
|
+
] as const)('%s renders a text label (not colour alone)', (status, text) => {
|
|
30
|
+
render(<StepStatusBadge status={status} />)
|
|
31
|
+
expect(screen.getByText(text)).toBeTruthy()
|
|
32
|
+
})
|
|
33
|
+
it('speaks English when the language is en', () => {
|
|
34
|
+
lang.current = 'en-US'
|
|
35
|
+
render(<StepStatusBadge status='blocked' />)
|
|
36
|
+
expect(screen.getByText('Blocked')).toBeTruthy()
|
|
37
|
+
})
|
|
38
|
+
it('compact keeps the label for screen readers only', () => {
|
|
39
|
+
render(<StepStatusBadge status='ok' compact />)
|
|
40
|
+
expect(screen.getByText('Listo').className).toContain('sr-only')
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
describe('copyText', () => {
|
|
45
|
+
it('uses the Clipboard API when available', async () => {
|
|
46
|
+
const writeText = vi.fn().mockResolvedValue(undefined)
|
|
47
|
+
Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true })
|
|
48
|
+
expect(await copyText('abc')).toBe(true)
|
|
49
|
+
expect(writeText).toHaveBeenCalledWith('abc')
|
|
50
|
+
})
|
|
51
|
+
it('falls back to execCommand when the Clipboard API rejects', async () => {
|
|
52
|
+
Object.defineProperty(navigator, 'clipboard', { value: { writeText: vi.fn().mockRejectedValue(new Error('denied')) }, configurable: true })
|
|
53
|
+
const exec = vi.fn().mockReturnValue(true)
|
|
54
|
+
;(document as any).execCommand = exec
|
|
55
|
+
expect(await copyText('abc')).toBe(true)
|
|
56
|
+
expect(exec).toHaveBeenCalledWith('copy')
|
|
57
|
+
expect(document.querySelector('textarea')).toBeNull() // cleaned up
|
|
58
|
+
})
|
|
59
|
+
it('reports failure when nothing works', async () => {
|
|
60
|
+
Object.defineProperty(navigator, 'clipboard', { value: undefined, configurable: true })
|
|
61
|
+
;(document as any).execCommand = vi.fn().mockReturnValue(false)
|
|
62
|
+
expect(await copyText('abc')).toBe(false)
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
describe('RecordsTable', () => {
|
|
67
|
+
const records = [
|
|
68
|
+
{ type: 'TXT', name: '_dmarc.acme.test', value: 'v=DMARC1; p=none', status: 'ok' as const },
|
|
69
|
+
{ type: 'MX', name: 'acme.test', value: 'mx.acme.test', status: 'wrong_value' as const, found: 'old.mx.test', diagnostic: { message: 'El MX apunta a otro servidor', fix: { label: 'Corregir', action: 'apply_dns' } } },
|
|
70
|
+
{ type: 'TXT', name: 'acme.test', value: 'v=spf1 -all', status: 'propagating' as const, diagnostic: 'Puede tardar unos minutos' },
|
|
71
|
+
]
|
|
72
|
+
it('shows type, name, value, status and diagnostics per row', () => {
|
|
73
|
+
render(<RecordsTable records={records} caption='DNS' />)
|
|
74
|
+
expect(screen.getByRole('table')).toBeTruthy()
|
|
75
|
+
expect(screen.getByText('_dmarc.acme.test')).toBeTruthy()
|
|
76
|
+
expect(screen.getByText('Correcto')).toBeTruthy()
|
|
77
|
+
expect(screen.getByText('Valor distinto')).toBeTruthy()
|
|
78
|
+
expect(screen.getByText('Propagando')).toBeTruthy()
|
|
79
|
+
expect(screen.getByText('Encontrado: old.mx.test')).toBeTruthy()
|
|
80
|
+
expect(screen.getByText('El MX apunta a otro servidor')).toBeTruthy()
|
|
81
|
+
expect(screen.getByText('Puede tardar unos minutos')).toBeTruthy()
|
|
82
|
+
})
|
|
83
|
+
it('copies a value and confirms it', async () => {
|
|
84
|
+
const writeText = vi.fn().mockResolvedValue(undefined)
|
|
85
|
+
Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true })
|
|
86
|
+
render(<RecordsTable records={records} />)
|
|
87
|
+
fireEvent.click(screen.getAllByLabelText('Copiar valor')[0])
|
|
88
|
+
await waitFor(() => expect(screen.getByText('Copiado')).toBeTruthy())
|
|
89
|
+
expect(writeText).toHaveBeenCalledWith('v=DMARC1; p=none')
|
|
90
|
+
})
|
|
91
|
+
it('tells the person when copy fails', async () => {
|
|
92
|
+
Object.defineProperty(navigator, 'clipboard', { value: undefined, configurable: true })
|
|
93
|
+
;(document as any).execCommand = vi.fn().mockReturnValue(false)
|
|
94
|
+
render(<RecordsTable records={records} />)
|
|
95
|
+
fireEvent.click(screen.getAllByLabelText('Copiar nombre')[0])
|
|
96
|
+
await waitFor(() => expect(screen.getByText(/No se pudo copiar/)).toBeTruthy())
|
|
97
|
+
})
|
|
98
|
+
it('row fix calls onFix with the fix and the record', () => {
|
|
99
|
+
const onFix = vi.fn()
|
|
100
|
+
render(<RecordsTable records={records} onFix={onFix} />)
|
|
101
|
+
fireEvent.click(screen.getByText('Corregir'))
|
|
102
|
+
expect(onFix).toHaveBeenCalledWith({ label: 'Corregir', action: 'apply_dns' }, records[1])
|
|
103
|
+
})
|
|
104
|
+
it('empty list shows a message and recheck fires', () => {
|
|
105
|
+
const onRecheck = vi.fn()
|
|
106
|
+
const { rerender } = render(<RecordsTable records={[]} />)
|
|
107
|
+
expect(screen.getByText('No hay registros por mostrar.')).toBeTruthy()
|
|
108
|
+
rerender(<RecordsTable records={records} onRecheck={onRecheck} />)
|
|
109
|
+
fireEvent.click(screen.getByText('Verificar ahora'))
|
|
110
|
+
expect(onRecheck).toHaveBeenCalled()
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
describe('HealthCard', () => {
|
|
115
|
+
it('renders status, metrics with tone and issues with fix', () => {
|
|
116
|
+
const onFix = vi.fn()
|
|
117
|
+
const onContinue = vi.fn()
|
|
118
|
+
render(
|
|
119
|
+
<HealthCard
|
|
120
|
+
title='Correo'
|
|
121
|
+
status='warn'
|
|
122
|
+
summary='Falta un registro'
|
|
123
|
+
progress={{ done: 2, total: 4 }}
|
|
124
|
+
metrics={[
|
|
125
|
+
{ key: 'q', label: 'En cola', value: 12, tone: 'warn' },
|
|
126
|
+
{ key: 's', label: 'Entregados', value: '98', unit: '%', tone: 'good' },
|
|
127
|
+
]}
|
|
128
|
+
issues={[{ severity: 'error', message: 'DKIM no publicado', fix: { label: 'Ver registros', step: 'dns' } }]}
|
|
129
|
+
onFix={onFix}
|
|
130
|
+
onContinue={onContinue}
|
|
131
|
+
/>,
|
|
132
|
+
)
|
|
133
|
+
expect(screen.getByText('Requiere atención')).toBeTruthy()
|
|
134
|
+
expect(screen.getByText('2 de 4 pasos')).toBeTruthy()
|
|
135
|
+
expect(screen.getByRole('progressbar').getAttribute('aria-valuenow')).toBe('50')
|
|
136
|
+
expect(screen.getByText('12').closest('[data-metric-tone]')?.getAttribute('data-metric-tone')).toBe('warn')
|
|
137
|
+
fireEvent.click(screen.getByText('Ver registros'))
|
|
138
|
+
expect(onFix).toHaveBeenCalledWith({ label: 'Ver registros', step: 'dns' }, expect.objectContaining({ message: 'DKIM no publicado' }))
|
|
139
|
+
fireEvent.click(screen.getByText('Continuar configuración'))
|
|
140
|
+
expect(onContinue).toHaveBeenCalled()
|
|
141
|
+
})
|
|
142
|
+
it('says there are no issues when the list is empty and unknown status degrades', () => {
|
|
143
|
+
render(<HealthCard status={'weird' as any} issues={[]} />)
|
|
144
|
+
expect(screen.getByText('Sin datos')).toBeTruthy()
|
|
145
|
+
expect(screen.getByText('Sin avisos.')).toBeTruthy()
|
|
146
|
+
})
|
|
147
|
+
})
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
effectiveStatus,
|
|
4
|
+
flowProgress,
|
|
5
|
+
mergeAnswer,
|
|
6
|
+
nextPollDelayMs,
|
|
7
|
+
normalizeState,
|
|
8
|
+
pickActiveStep,
|
|
9
|
+
safeUrl,
|
|
10
|
+
unmetDependencies,
|
|
11
|
+
} from '../setup/flow-model'
|
|
12
|
+
import type { SetupStepDef, SetupStepState } from '../setup/types'
|
|
13
|
+
|
|
14
|
+
const defs: SetupStepDef[] = [
|
|
15
|
+
{ key: 'domain', kind: 'form', title: 'Domain' },
|
|
16
|
+
{ key: 'dns', kind: 'records', title: 'DNS', depends_on: ['domain'] },
|
|
17
|
+
{ key: 'test', kind: 'action', title: 'Test', depends_on: ['dns'] },
|
|
18
|
+
{ key: 'extras', kind: 'action', title: 'Extras', optional: true },
|
|
19
|
+
]
|
|
20
|
+
const st = (key: string, status: SetupStepState['status'], extra: Partial<SetupStepState> = {}): SetupStepState => ({ key, status, ...extra })
|
|
21
|
+
const map = (...s: SetupStepState[]) => Object.fromEntries(s.map((x) => [x.key, x]))
|
|
22
|
+
|
|
23
|
+
describe('normalizeState', () => {
|
|
24
|
+
it('accepts array and by-key map', () => {
|
|
25
|
+
expect(normalizeState({ steps: [st('a', 'ok')] }).a.status).toBe('ok')
|
|
26
|
+
expect(normalizeState({ steps: { a: { status: 'warn' } as SetupStepState } }).a).toMatchObject({ key: 'a', status: 'warn' })
|
|
27
|
+
expect(normalizeState(undefined)).toEqual({})
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('effectiveStatus / depends_on', () => {
|
|
32
|
+
it('blocks a step whose dependency is not satisfied', () => {
|
|
33
|
+
const s = map(st('domain', 'pending'))
|
|
34
|
+
expect(effectiveStatus(defs[1], s)).toBe('blocked')
|
|
35
|
+
expect(unmetDependencies(defs[1], s)).toEqual(['domain'])
|
|
36
|
+
})
|
|
37
|
+
it('unblocks when the dependency is ok, warn or skipped', () => {
|
|
38
|
+
expect(effectiveStatus(defs[1], map(st('domain', 'ok')))).toBe('pending')
|
|
39
|
+
expect(effectiveStatus(defs[1], map(st('domain', 'warn')))).toBe('pending')
|
|
40
|
+
expect(effectiveStatus(defs[1], map(st('domain', 'pending', { skipped: true })))).toBe('pending')
|
|
41
|
+
})
|
|
42
|
+
it('an error dependency keeps dependants blocked', () => {
|
|
43
|
+
expect(effectiveStatus(defs[1], map(st('domain', 'error')))).toBe('blocked')
|
|
44
|
+
})
|
|
45
|
+
it('keeps running/ok from the server and reads skipped as ok', () => {
|
|
46
|
+
expect(effectiveStatus(defs[1], map(st('dns', 'running')))).toBe('running')
|
|
47
|
+
expect(effectiveStatus(defs[3], map(st('extras', 'pending', { skipped: true })))).toBe('ok')
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
describe('pickActiveStep / flowProgress', () => {
|
|
52
|
+
it('resumes at the first step that is not satisfied and not blocked', () => {
|
|
53
|
+
expect(pickActiveStep(defs, map(st('domain', 'ok'), st('dns', 'error')))).toBe('dns')
|
|
54
|
+
expect(pickActiveStep(defs, map())).toBe('domain')
|
|
55
|
+
})
|
|
56
|
+
it('falls to the last step when everything is satisfied', () => {
|
|
57
|
+
expect(pickActiveStep(defs, map(st('domain', 'ok'), st('dns', 'ok'), st('test', 'ok'), st('extras', 'ok')))).toBe('extras')
|
|
58
|
+
})
|
|
59
|
+
it('optional steps do not hold completion back', () => {
|
|
60
|
+
const p = flowProgress(defs, map(st('domain', 'ok'), st('dns', 'ok'), st('test', 'ok')))
|
|
61
|
+
expect(p).toEqual({ done: 3, total: 3, percent: 100, complete: true })
|
|
62
|
+
})
|
|
63
|
+
it('an error step is not progress', () => {
|
|
64
|
+
const p = flowProgress(defs, map(st('domain', 'ok'), st('dns', 'error')))
|
|
65
|
+
expect(p.complete).toBe(false)
|
|
66
|
+
expect(p.done).toBe(1)
|
|
67
|
+
})
|
|
68
|
+
it('honours the server verdict', () => {
|
|
69
|
+
expect(flowProgress(defs, {}, true)).toMatchObject({ complete: true, percent: 100 })
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe('nextPollDelayMs', () => {
|
|
74
|
+
it('backs off exponentially up to the cap', () => {
|
|
75
|
+
expect(nextPollDelayMs(0)).toBe(2000)
|
|
76
|
+
expect(nextPollDelayMs(1)).toBe(3200)
|
|
77
|
+
expect(nextPollDelayMs(2)).toBe(5120)
|
|
78
|
+
expect(nextPollDelayMs(50)).toBe(30000)
|
|
79
|
+
})
|
|
80
|
+
it('retry_after_s wins, clamped to 1s..5min', () => {
|
|
81
|
+
expect(nextPollDelayMs(5, 45)).toBe(45000)
|
|
82
|
+
expect(nextPollDelayMs(0, 0.1)).toBe(1000) // floor 1s
|
|
83
|
+
expect(nextPollDelayMs(0, -3)).toBe(2000) // unusable hint → backoff
|
|
84
|
+
expect(nextPollDelayMs(0, 1)).toBe(1000)
|
|
85
|
+
expect(nextPollDelayMs(0, 99999)).toBe(300000)
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
describe('safeUrl', () => {
|
|
90
|
+
it('allows http(s) and app-relative, refuses the rest', () => {
|
|
91
|
+
expect(safeUrl('/settings')).toBe('/settings')
|
|
92
|
+
expect(safeUrl('https://x.test/a')).toBe('https://x.test/a')
|
|
93
|
+
expect(safeUrl('javascript:alert(1)')).toBeNull()
|
|
94
|
+
expect(safeUrl('//evil.test')).toBeNull()
|
|
95
|
+
expect(safeUrl('data:text/html,hi')).toBeNull()
|
|
96
|
+
})
|
|
97
|
+
it('refuses relative paths that browsers resolve to another host', () => {
|
|
98
|
+
expect(safeUrl('/\\evil.com/x')).toBeNull()
|
|
99
|
+
expect(safeUrl('/\t/evil.com')).toBeNull()
|
|
100
|
+
expect(safeUrl('/\n/evil.com')).toBeNull()
|
|
101
|
+
expect(safeUrl('\\\\evil.com')).toBeNull()
|
|
102
|
+
expect(safeUrl(' //evil.com ')).toBeNull()
|
|
103
|
+
expect(safeUrl(' javascript:alert(1)')).toBeNull()
|
|
104
|
+
expect(safeUrl('/ok/path?x=1#h')).toBe('/ok/path?x=1#h')
|
|
105
|
+
expect(safeUrl(' /padded ')).toBe('/padded')
|
|
106
|
+
expect(safeUrl('')).toBeNull()
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
describe('mergeAnswer', () => {
|
|
111
|
+
it('merges a step answer, replaces on a flow answer, refetches on void', () => {
|
|
112
|
+
const cur = map(st('a', 'pending'))
|
|
113
|
+
expect(mergeAnswer(cur, 'a', st('a', 'ok')).next.a.status).toBe('ok')
|
|
114
|
+
expect(mergeAnswer(cur, 'a', { steps: [st('b', 'ok')] }).next).toEqual({ b: st('b', 'ok') })
|
|
115
|
+
expect(mergeAnswer(cur, 'a', undefined).needsRefetch).toBe(true)
|
|
116
|
+
})
|
|
117
|
+
})
|