import { mount } from '@vue/test-utils' import { describe, expect, it } from 'vitest' import DuplicateSubmissionHint from '@/components/public-form/DuplicateSubmissionHint.vue' import type { PublicFormSubmissionDuplicate } from '@/types/formBuilder' function mountHint(data: PublicFormSubmissionDuplicate | null) { return mount(DuplicateSubmissionHint, { props: { data }, global: { stubs: { VAlert: { name: 'VAlert', props: ['type', 'variant', 'prominent'], template: '
', }, }, }, }) } 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') }) })