import { describe, it, expect } from 'vitest' import { mount, flushPromises } from '@vue/test-utils' import { createRouter, createMemoryHistory } from 'vue-router' import { setActivePinia, createPinia } from 'pinia' import ConfirmEmailChangePage from '@/pages/ConfirmEmailChangePage.vue' function createTestRouter() { return createRouter({ history: createMemoryHistory(), routes: [ { path: '/bekrafta-epost', name: 'confirm-email-change', component: ConfirmEmailChangePage, }, ], }) } async function mountPage(initialPath: string) { const pinia = createPinia() setActivePinia(pinia) const router = createTestRouter() await router.push(initialPath) await router.isReady() const wrapper = mount(ConfirmEmailChangePage, { global: { plugins: [router, pinia] }, }) await flushPromises() return { wrapper, router } } describe('ConfirmEmailChangePage', () => { it('shows password form when token is present', async () => { const { wrapper } = await mountPage('/bekrafta-epost?token=test-token') expect(wrapper.text()).toContain('Bekräfta e-postadress') expect(wrapper.text()).toContain('Ange ditt lösenord') expect(wrapper.find('#password').exists()).toBe(true) expect(wrapper.find('button[type="submit"]').text()).toBe( 'Bekräfta ny e-postadress', ) }) it('shows error when token is missing', async () => { const { wrapper } = await mountPage('/bekrafta-epost') expect(wrapper.text()).toContain('Bekräftelselänken saknar en giltig kod.') }) })