diff --git a/frontend/src/__tests__/HomePage.spec.ts b/frontend/src/__tests__/HomePage.spec.ts index 4ba77df..0664b4d 100644 --- a/frontend/src/__tests__/HomePage.spec.ts +++ b/frontend/src/__tests__/HomePage.spec.ts @@ -1,8 +1,10 @@ -import { describe, it, expect, vi } from 'vitest' +import { describe, it, expect, vi, beforeEach } from 'vitest' import { mount } from '@vue/test-utils' +import { createPinia, setActivePinia } from 'pinia' import { createRouter, createMemoryHistory } from 'vue-router' import HomePage from '@/pages/HomePage.vue' import ComposePage from '@/pages/ComposePage.vue' +import GuestCheckoutPage from '@/pages/GuestCheckoutPage.vue' vi.mock('@/api/vehicles', () => ({ lookupVehicle: vi.fn(), @@ -17,6 +19,11 @@ function createTestRouter() { routes: [ { path: '/', name: 'home', component: HomePage }, { path: '/compose', name: 'compose', component: ComposePage }, + { + path: '/gast-bestallning', + name: 'guest-checkout', + component: GuestCheckoutPage, + }, ], }) } @@ -28,6 +35,12 @@ function mountHome(router: ReturnType) { } describe('HomePage', () => { + beforeEach(() => { + setActivePinia(createPinia()) + localStorage.removeItem('auth_token') + vi.clearAllMocks() + }) + it('renders headline', () => { const router = createTestRouter() const wrapper = mountHome(router) @@ -88,7 +101,7 @@ describe('HomePage', () => { expect(cta.text()).toBe('Fortsätt till brevet') }) - it('CTA links to compose page with plate query param', async () => { + it('CTA links to guest checkout with plate query param when unauthenticated', async () => { mockLookupVehicle.mockResolvedValue({ make: 'Volvo', model: 'V70', @@ -107,6 +120,6 @@ describe('HomePage', () => { const cta = wrapper.find('.btn--primary') const href = cta.attributes('href') - expect(href).toBe('/compose?plate=ABC123') + expect(href).toBe('/gast-bestallning?plate=ABC123') }) }) diff --git a/frontend/src/pages/GuestCheckoutPage.vue b/frontend/src/pages/GuestCheckoutPage.vue index 8a625fa..2f98efa 100644 --- a/frontend/src/pages/GuestCheckoutPage.vue +++ b/frontend/src/pages/GuestCheckoutPage.vue @@ -1,11 +1,12 @@