Initial release of Web Tools 0.0.5
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
moveCategoryBy,
|
||||
moveToolBy,
|
||||
moveToolToCategory,
|
||||
relocateTool,
|
||||
reorderCategory,
|
||||
} from '../src/lib/navigationOrder'
|
||||
import type { NavigationConfig } from '../src/types'
|
||||
|
||||
const navigation: NavigationConfig = {
|
||||
version: 1,
|
||||
categories: [
|
||||
{ id: 'one', tools: ['a', 'b', 'c'] },
|
||||
{ id: 'two', tools: ['d', 'e'] },
|
||||
{ id: 'three', tools: [] },
|
||||
],
|
||||
}
|
||||
|
||||
describe('navigation ordering', () => {
|
||||
it('moves categories upward and downward without mutating the input', () => {
|
||||
expect(moveCategoryBy(navigation, 0, 1).categories.map(({ id }) => id)).toEqual(['two', 'one', 'three'])
|
||||
expect(reorderCategory(navigation, 2, 0).categories.map(({ id }) => id)).toEqual(['three', 'one', 'two'])
|
||||
expect(navigation.categories.map(({ id }) => id)).toEqual(['one', 'two', 'three'])
|
||||
})
|
||||
|
||||
it('moves tools upward and downward within a category', () => {
|
||||
expect(moveToolBy(navigation, 0, 0, 1).categories[0].tools).toEqual(['b', 'a', 'c'])
|
||||
expect(moveToolBy(navigation, 0, 2, -1).categories[0].tools).toEqual(['a', 'c', 'b'])
|
||||
})
|
||||
|
||||
it('moves tools across categories and appends them at the end', () => {
|
||||
const crossList = relocateTool(navigation, { categoryIndex: 0, toolIndex: 1 }, { categoryIndex: 1, toolIndex: 1 })
|
||||
expect(crossList.categories[0].tools).toEqual(['a', 'c'])
|
||||
expect(crossList.categories[1].tools).toEqual(['d', 'b', 'e'])
|
||||
|
||||
const appended = moveToolToCategory(navigation, 'a', 0, 'three')
|
||||
expect(appended.categories[0].tools).toEqual(['b', 'c'])
|
||||
expect(appended.categories[2].tools).toEqual(['a'])
|
||||
})
|
||||
|
||||
it('clamps end insertion and ignores invalid source positions', () => {
|
||||
expect(relocateTool(navigation, { categoryIndex: 0, toolIndex: 0 }, { categoryIndex: 1, toolIndex: 99 }).categories[1].tools).toEqual(['d', 'e', 'a'])
|
||||
expect(relocateTool(navigation, { categoryIndex: 9, toolIndex: 0 }, { categoryIndex: 1, toolIndex: 0 })).toEqual(navigation)
|
||||
expect(moveCategoryBy(navigation, 0, -1)).toEqual(navigation)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user