You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sims-hq/apps/hq/test/template-accent.test.ts

43 lines
2.5 KiB
TypeScript

// apps/hq/test/template-accent.test.ts
import { describe, it, expect } from 'vitest'
import { documentHtml } from '../src/templates'
const base = {
id: 'd1', docType: 'INVOICE', docNo: 'INV/26-27-0001', fy: '2026-27', clientId: 'c1',
docDate: '2026-07-13', status: 'draft', refDocId: null, taxablePaise: 10_000_00,
cgstPaise: 900_00, sgstPaise: 900_00, igstPaise: 0, roundOffPaise: 0, payablePaise: 11_800_00,
payload: { lines: [{ itemId: 'm1', name: 'POS', hsn: '998313', qty: 1, unitCode: 'NOS',
unitPricePaise: 10_000_00, grossPaise: 10_000_00, discountPaise: 0, taxablePaise: 10_000_00,
taxRateBp: 1800, cgstPaise: 900_00, sgstPaise: 900_00, igstPaise: 0, cessPaise: 0, lineTotalPaise: 11_800_00 }], totals: {} },
} as never
const client = { id: 'c1', code: 'CL1', name: 'Acme', stateCode: '32', address: 'Kochi', gstin: '32ABCDE1234F1Z9', contacts: [], status: 'active', notes: '' } as never
describe('template.accent (validated hex, single source of truth)', () => {
it('defaults to slate-indigo #334155 when unset', () => {
const html = documentHtml(base, client, { 'company.name': 'SiMS' })
expect(html).toContain('--accent:#334155')
})
it('applies a valid hex accent verbatim (6- and 3-digit)', () => {
expect(documentHtml(base, client, { 'company.name': 'X', 'template.accent': '#0ea5e9' }))
.toContain('--accent:#0ea5e9')
expect(documentHtml(base, client, { 'company.name': 'X', 'template.accent': '#fff' }))
.toContain('--accent:#fff')
})
it('falls back to the default for a non-hex / injection value (never injects raw setting into CSS)', () => {
const html = documentHtml(base, client, { 'company.name': 'X', 'template.accent': 'red; } body{display:none' })
expect(html).toContain('--accent:#334155')
expect(html).not.toContain('body{display:none')
})
it('prints the accent through puppeteer via print-color-adjust:exact', () => {
expect(documentHtml(base, client, { 'company.name': 'X' })).toContain('print-color-adjust:exact')
})
it('renders a DRAFT chip (literal DRAFT) for an un-issued doc, real number otherwise', () => {
const draft = { ...(base as object), docNo: null } as never
const dh = documentHtml(draft, client, { 'company.name': 'X' })
expect(dh).toContain('<span class="chip-draft">DRAFT</span>')
const issued = documentHtml(base, client, { 'company.name': 'X' })
expect(issued).not.toContain('class="chip-draft"') // CSS defines .chip-draft, but issued docs never emit the chip
expect(issued).toContain('INV/26-27-0001')
})
})