Templates serve as a brand shield (showing the platform facilitates all kinds of messaging), not as a compose-flow form control. Remove them from the data model and compose page. Templates will live as branding elements on the landing page in a future commit. Backend: - Remove template field from Order entity (getter/setter removed) - Remove template from CreateOrderRequest DTO - Remove template from OrderResponse DTO - Remove template param from OrderService.createOrder() - Remove template passthrough in OrderController - Remove /api/templates permitAll from SecurityConfig - Edit V5 migration: remove template column from orders table - Edit V6 migration: remove template from seed data - Update OrderControllerTest (remove template from assertions/requests) - Update OrderServiceTest (remove template from createOrder calls) Frontend: - Remove template from Order interface in api/orders.ts - Remove template param from createOrder() function - Remove template display from OrdersPage.vue cards - Rewrite ComposePage.vue: remove template selector, keep textarea + preview + submit - Update ComposePage.spec.ts (remove template tests, add preview/GDPR tests) - Update OrdersPage.spec.ts (remove template from mock data and display test) - Update compose.spec.ts E2E (remove template selector interactions) - Update order-history.spec.ts E2E (remove template names test) - Fix unused import in Router.spec.ts - Also includes minor Prettier formatting in AppHeader.spec.ts, AdminPage.vue, authStore.ts
173 lines
5.3 KiB
TypeScript
173 lines
5.3 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest'
|
|
import { mount } from '@vue/test-utils'
|
|
import { createRouter, createMemoryHistory } from 'vue-router'
|
|
import { setActivePinia, createPinia } from 'pinia'
|
|
import AppHeader from '@/components/AppHeader.vue'
|
|
import { useAuthStore } from '@/stores/authStore'
|
|
|
|
function createTestRouter() {
|
|
return createRouter({
|
|
history: createMemoryHistory(),
|
|
routes: [
|
|
{ path: '/', name: 'home', component: { template: '<div>Home</div>' } },
|
|
{
|
|
path: '/logga-in',
|
|
name: 'login',
|
|
component: { template: '<div>Login</div>' },
|
|
},
|
|
{
|
|
path: '/registrera',
|
|
name: 'register',
|
|
component: { template: '<div>Register</div>' },
|
|
},
|
|
{
|
|
path: '/orders',
|
|
name: 'orders',
|
|
component: { template: '<div>Orders</div>' },
|
|
},
|
|
],
|
|
})
|
|
}
|
|
|
|
function makeJwt(payload: Record<string, unknown>): string {
|
|
const header = btoa(JSON.stringify({ alg: 'HS256', typ: 'JWT' }))
|
|
const body = btoa(JSON.stringify(payload))
|
|
const signature = 'test-sig'
|
|
return `${header}.${body}.${signature}`
|
|
}
|
|
|
|
describe('AppHeader', () => {
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia())
|
|
localStorage.clear()
|
|
})
|
|
|
|
it('renders the logo text', () => {
|
|
const router = createTestRouter()
|
|
const wrapper = mount(AppHeader, {
|
|
global: { plugins: [router, createPinia()] },
|
|
})
|
|
expect(wrapper.text()).toContain('BilHälsning')
|
|
})
|
|
|
|
it('has a link to home', () => {
|
|
const router = createTestRouter()
|
|
const wrapper = mount(AppHeader, {
|
|
global: { plugins: [router, createPinia()] },
|
|
})
|
|
const links = wrapper.findAll('a')
|
|
const homeLink = links.find((a) => a.attributes('href') === '/')
|
|
expect(homeLink).toBeTruthy()
|
|
})
|
|
|
|
describe('when not authenticated', () => {
|
|
it('shows login link', () => {
|
|
const router = createTestRouter()
|
|
const wrapper = mount(AppHeader, {
|
|
global: { plugins: [router, createPinia()] },
|
|
})
|
|
const links = wrapper.findAll('a')
|
|
const loginLink = links.find((a) => a.attributes('href') === '/logga-in')
|
|
expect(loginLink).toBeTruthy()
|
|
expect(loginLink?.text()).toBe('Logga in')
|
|
})
|
|
|
|
it('shows register link', () => {
|
|
const router = createTestRouter()
|
|
const wrapper = mount(AppHeader, {
|
|
global: { plugins: [router, createPinia()] },
|
|
})
|
|
const links = wrapper.findAll('a')
|
|
const registerLink = links.find(
|
|
(a) => a.attributes('href') === '/registrera',
|
|
)
|
|
expect(registerLink).toBeTruthy()
|
|
expect(registerLink?.text()).toBe('Registrera')
|
|
})
|
|
|
|
it('does not show logout button', () => {
|
|
const router = createTestRouter()
|
|
const wrapper = mount(AppHeader, {
|
|
global: { plugins: [router, createPinia()] },
|
|
})
|
|
expect(wrapper.find('button').exists()).toBe(false)
|
|
})
|
|
|
|
it('does not show user email', () => {
|
|
const router = createTestRouter()
|
|
const wrapper = mount(AppHeader, {
|
|
global: { plugins: [router, createPinia()] },
|
|
})
|
|
expect(wrapper.text()).not.toContain('@bilhalsning.se')
|
|
})
|
|
|
|
it('does not show orders link', () => {
|
|
const router = createTestRouter()
|
|
const wrapper = mount(AppHeader, {
|
|
global: { plugins: [router, createPinia()] },
|
|
})
|
|
const links = wrapper.findAll('a')
|
|
const ordersLink = links.find((a) => a.attributes('href') === '/orders')
|
|
expect(ordersLink).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
describe('when authenticated', () => {
|
|
function mountAuthenticated() {
|
|
const jwt = makeJwt({ sub: 'test@bilhalsning.se', role: 'user' })
|
|
localStorage.setItem('auth_token', jwt)
|
|
const pinia = createPinia()
|
|
setActivePinia(pinia)
|
|
const router = createTestRouter()
|
|
return mount(AppHeader, {
|
|
global: { plugins: [router, pinia] },
|
|
})
|
|
}
|
|
|
|
it('shows user email', () => {
|
|
const wrapper = mountAuthenticated()
|
|
expect(wrapper.text()).toContain('test@bilhalsning.se')
|
|
})
|
|
|
|
it('shows logout button', () => {
|
|
const wrapper = mountAuthenticated()
|
|
const logoutButton = wrapper.find('button')
|
|
expect(logoutButton.exists()).toBe(true)
|
|
expect(logoutButton.text()).toBe('Logga ut')
|
|
})
|
|
|
|
it('does not show login link', () => {
|
|
const wrapper = mountAuthenticated()
|
|
const links = wrapper.findAll('a')
|
|
const loginLink = links.find((a) => a.attributes('href') === '/logga-in')
|
|
expect(loginLink).toBeUndefined()
|
|
})
|
|
|
|
it('does not show register link', () => {
|
|
const wrapper = mountAuthenticated()
|
|
const links = wrapper.findAll('a')
|
|
const registerLink = links.find(
|
|
(a) => a.attributes('href') === '/registrera',
|
|
)
|
|
expect(registerLink).toBeUndefined()
|
|
})
|
|
|
|
it('shows orders link', () => {
|
|
const wrapper = mountAuthenticated()
|
|
const links = wrapper.findAll('a')
|
|
const ordersLink = links.find((a) => a.attributes('href') === '/orders')
|
|
expect(ordersLink).toBeTruthy()
|
|
expect(ordersLink?.text()).toBe('Mina beställningar')
|
|
})
|
|
|
|
it('calls logout when clicking logout button', async () => {
|
|
const wrapper = mountAuthenticated()
|
|
const auth = useAuthStore()
|
|
expect(auth.isAuthenticated).toBe(true)
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
|
|
expect(auth.isAuthenticated).toBe(false)
|
|
})
|
|
})
|
|
})
|