Moves formBuilder types, formValidation, useConditionalLogic, useFormSteps, and formatFieldValue from apps/portal/src to packages/form-schema/src. Adds @form-schema path alias to both apps/portal and apps/app. Vue field components remain per-app to allow independent visual evolution. Behavior-neutral: all 35 Vitest tests green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
81 lines
2.5 KiB
TypeScript
81 lines
2.5 KiB
TypeScript
import { mount } from '@vue/test-utils'
|
|
import { describe, expect, it } from 'vitest'
|
|
import DuplicateSubmissionHint from '@/components/public-form/DuplicateSubmissionHint.vue'
|
|
import type { PublicFormSubmissionDuplicate } from '@form-schema/types/formBuilder'
|
|
|
|
function mountHint(data: PublicFormSubmissionDuplicate | null) {
|
|
return mount(DuplicateSubmissionHint, {
|
|
props: { data },
|
|
global: {
|
|
stubs: {
|
|
VAlert: {
|
|
name: 'VAlert',
|
|
props: ['type', 'variant', 'prominent'],
|
|
template: '<div class="v-alert-stub" :data-type="type" :data-variant="variant"><slot/></div>',
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
describe('DuplicateSubmissionHint', () => {
|
|
it('renders nothing when data is null', () => {
|
|
const w = mountHint(null)
|
|
|
|
expect(w.find('.v-alert-stub').exists()).toBe(false)
|
|
})
|
|
|
|
it('prefers the backend title and body when provided', () => {
|
|
const w = mountHint({
|
|
count: 1,
|
|
first_submitted_at: '2026-04-22T10:00:00+00:00',
|
|
title: 'Je hebt je eerder al aangemeld',
|
|
body: 'Op 22 april 2026 heb je dit formulier ook al ingevuld.',
|
|
})
|
|
|
|
expect(w.text()).toContain('Je hebt je eerder al aangemeld')
|
|
expect(w.text()).toContain('Op 22 april 2026')
|
|
})
|
|
|
|
it('falls back to singular copy when the backend body is missing (count=1)', () => {
|
|
const w = mountHint({
|
|
count: 1,
|
|
first_submitted_at: '2026-04-22T10:00:00+00:00',
|
|
title: '',
|
|
body: '',
|
|
})
|
|
|
|
// Fallback title + body.
|
|
expect(w.text()).toContain('Je hebt je eerder al aangemeld')
|
|
expect(w.text()).toMatch(/Op\s+22\s+april\s+2026.*ook al ingevuld/)
|
|
expect(w.text()).toContain('De organisator ziet beide aanmeldingen')
|
|
})
|
|
|
|
it('falls back to plural copy with count when the backend body is missing', () => {
|
|
const w = mountHint({
|
|
count: 3,
|
|
first_submitted_at: '2026-04-22T10:00:00+00:00',
|
|
title: '',
|
|
body: '',
|
|
})
|
|
|
|
expect(w.text()).toContain('3 keer eerder ingevuld')
|
|
expect(w.text()).toContain('22 april 2026')
|
|
expect(w.text()).toContain('De organisator ziet alle aanmeldingen')
|
|
})
|
|
|
|
it('renders as a warning-typed tonal VAlert', () => {
|
|
const w = mountHint({
|
|
count: 1,
|
|
first_submitted_at: '2026-04-22T10:00:00+00:00',
|
|
title: 'x',
|
|
body: 'y',
|
|
})
|
|
|
|
const alert = w.find('.v-alert-stub')
|
|
expect(alert.exists()).toBe(true)
|
|
expect(alert.attributes('data-type')).toBe('warning')
|
|
expect(alert.attributes('data-variant')).toBe('tonal')
|
|
})
|
|
})
|