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/packages/ui/test/palette-match.test.ts

27 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { matchItems, type PaletteItem } from '../src/palette-match'
const items: PaletteItem[] = [
{ id: 'nav:dash', label: 'Dashboard', group: 'Go to' },
{ id: 'nav:clients', label: 'Clients', group: 'Go to' },
{ id: 'act:newdoc', label: 'New document', group: 'Actions', hint: 'quotation proforma invoice' },
{ id: 'client:1', label: 'CL-0007 · Hamiltel', group: 'Clients' },
]
describe('matchItems', () => {
it('returns everything (to limit) for an empty query', () => {
expect(matchItems(items, '').map((i) => i.id)).toEqual(['nav:dash', 'nav:clients', 'act:newdoc', 'client:1'])
expect(matchItems(items, '', 2)).toHaveLength(2)
})
it('matches case-insensitively on label', () => {
expect(matchItems(items, 'hamil').map((i) => i.id)).toEqual(['client:1'])
})
it('matches on hint text too', () => {
expect(matchItems(items, 'proforma').map((i) => i.id)).toEqual(['act:newdoc'])
})
it('matches every whitespace-separated term (AND)', () => {
expect(matchItems(items, 'new doc').map((i) => i.id)).toEqual(['act:newdoc'])
expect(matchItems(items, 'new xyz')).toHaveLength(0)
})
})