Files
accounted/components/dashboard/__tests__/nav-prefetch.test.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

34 lines
1.4 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import fs from 'node:fs'
import path from 'node:path'
import { shouldWarmNavRoute } from '../nav-prefetch'
describe('shouldWarmNavRoute', () => {
it('warms other internal routes, ignoring query and hash', () => {
expect(shouldWarmNavRoute('/invoices', '/transactions')).toBe(true)
expect(shouldWarmNavRoute('/invoices?status=draft', '/transactions')).toBe(true)
expect(shouldWarmNavRoute('/reports#top', '/transactions')).toBe(true)
})
it('does not warm the current route or non-routes', () => {
expect(shouldWarmNavRoute('/invoices', '/invoices')).toBe(false)
expect(shouldWarmNavRoute('/invoices?x=1', '/invoices')).toBe(false)
expect(shouldWarmNavRoute('https://example.com', '/')).toBe(false)
expect(shouldWarmNavRoute('//evil.example', '/')).toBe(false)
expect(shouldWarmNavRoute('#section', '/')).toBe(false)
})
it('warms when the pathname is unknown (first render)', () => {
expect(shouldWarmNavRoute('/invoices', null)).toBe(true)
})
})
describe('DashboardNav uses NavLink for every link', () => {
it('has no bare next/link usage left, so no nav link prefetches on viewport', () => {
const source = fs.readFileSync(path.resolve(__dirname, '..', 'DashboardNav.tsx'), 'utf8')
expect(source).not.toMatch(/from 'next\/link'/)
expect(source).not.toMatch(/<Link[\s>]/)
expect(source).toMatch(/<NavLink[\s>]/)
})
})