62 lines
2.3 KiB
TypeScript
62 lines
2.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { circuitsNamed, foldCrumbs, wayTo } from '../app/lib/nav'
|
|
|
|
describe('the way back in the top bar', () => {
|
|
const path = ['Adder 4', 'Full Adder', 'Half Adder', 'XOR']
|
|
|
|
it('shows a short way whole', () => {
|
|
expect(foldCrumbs(path.slice(0, 2), 3)).toEqual({ folded: [], shown: ['Adder 4', 'Full Adder'] })
|
|
expect(foldCrumbs([], 2)).toEqual({ folded: [], shown: [] })
|
|
})
|
|
|
|
it('folds the names before the last ones into the menu, in order', () => {
|
|
expect(foldCrumbs(path, 2)).toEqual({ folded: ['Adder 4', 'Full Adder'], shown: ['Half Adder', 'XOR'] })
|
|
expect(foldCrumbs(path, 3).folded).toEqual(['Adder 4'])
|
|
})
|
|
|
|
it('always keeps the circuit you are in', () => {
|
|
expect(foldCrumbs(path, 1)).toEqual({ folded: ['Adder 4', 'Full Adder', 'Half Adder'], shown: ['XOR'] })
|
|
expect(foldCrumbs(path, 0).shown).toEqual(['XOR'])
|
|
})
|
|
})
|
|
|
|
describe('getting to a circuit from the search box', () => {
|
|
it('starts anew at Main', () => {
|
|
expect(wayTo(['main', 'adder'], 'main', 'main')).toBe('main')
|
|
})
|
|
|
|
it('goes back to a circuit on the way here', () => {
|
|
// Main → Adder 4 → Full Adder, now in Half Adder: Adder 4 is step 1 of the way.
|
|
expect(wayTo(['main', 'adder', 'full'], 'main', 'adder')).toBe(1)
|
|
expect(wayTo(['main', 'adder', 'full'], 'main', 'full')).toBe(2)
|
|
})
|
|
|
|
it('opens any other one step further in', () => {
|
|
expect(wayTo(['main'], 'main', 'xor')).toBe('open')
|
|
expect(wayTo([], 'main', 'xor')).toBe('open')
|
|
})
|
|
})
|
|
|
|
describe('circuits found by name', () => {
|
|
const defs = [{ name: 'Main' }, { name: 'Half Adder' }, { name: 'Adder 4' }, { name: 'Full Adder' }, { name: 'XOR' }, { name: 'D Flip-Flop' }]
|
|
const names = (q: string, limit?: number) => circuitsNamed(defs, q, limit).map(d => d.name)
|
|
|
|
it('finds nothing before something is typed', () => {
|
|
expect(names('')).toEqual([])
|
|
expect(names(' ')).toEqual([])
|
|
})
|
|
|
|
it('puts the best match first: the start of the name, then a word in it', () => {
|
|
expect(names('adder')).toEqual(['Adder 4', 'Half Adder', 'Full Adder'])
|
|
expect(names('XOR')).toEqual(['XOR'])
|
|
})
|
|
|
|
it('finds a name by its letters in order', () => {
|
|
expect(names('dff')).toEqual(['D Flip-Flop'])
|
|
})
|
|
|
|
it('lists at most the limit', () => {
|
|
expect(names('a', 2)).toHaveLength(2)
|
|
})
|
|
})
|