mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
feat(packing): sort the packing list A to Z
A switch at the end of the list's tab row shows every list's items in name order, so checking whether something is already on the list no longer means reading all of it. The order follows the reader's language (accents beside their letter, "Shirt 2" before "Shirt 10") and the empty list stand-in stays at the bottom. Sorting only changes what is shown: the manual order stays stored and comes back with a second click. While sorted the drag grips step aside, the box keeps its column, and the choice is remembered per browser.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { katColor, itemWeight, bagFillPct, bagTotalWeight, countsTowardsMyLoad, isMarkdownList, parseCsvLine, parseImportLines, unassignedTotalWeight } from './packingListPanel.helpers'
|
||||
import { katColor, itemWeight, bagFillPct, bagTotalWeight, countsTowardsMyLoad, isMarkdownList, parseCsvLine, parseImportLines, sortItemsByName, unassignedTotalWeight } from './packingListPanel.helpers'
|
||||
import { KAT_COLORS } from './packingListPanel.constants'
|
||||
|
||||
describe('packingListPanel.helpers', () => {
|
||||
@@ -219,4 +219,26 @@ describe('packingListPanel.helpers', () => {
|
||||
expect(unassignedTotalWeight(undefined, [])).toBe(0)
|
||||
})
|
||||
})
|
||||
describe('sortItemsByName', () => {
|
||||
const names = (items: { name: string }[]) => items.map(i => i.name)
|
||||
|
||||
it('orders by name, ignoring case and accents the way the language does', () => {
|
||||
const items = [{ name: 'shirt' }, { name: 'Éponge' }, { name: 'adapter' }, { name: 'Zahnbürste' }, { name: 'Bag' }]
|
||||
expect(names(sortItemsByName(items, 'en'))).toEqual(['adapter', 'Bag', 'Éponge', 'shirt', 'Zahnbürste'])
|
||||
})
|
||||
|
||||
it('reads numbers as numbers', () => {
|
||||
expect(names(sortItemsByName([{ name: 'Shirt 10' }, { name: 'Shirt 2' }], 'en'))).toEqual(['Shirt 2', 'Shirt 10'])
|
||||
})
|
||||
|
||||
it('keeps the placeholder of an empty list at the bottom', () => {
|
||||
expect(names(sortItemsByName([{ name: '...' }, { name: 'Zip bag' }, { name: 'Adapter' }], 'en'))).toEqual(['Adapter', 'Zip bag', '...'])
|
||||
})
|
||||
|
||||
it('leaves the array it was given in its manual order', () => {
|
||||
const items = [{ name: 'b' }, { name: 'a' }]
|
||||
sortItemsByName(items, 'en')
|
||||
expect(names(items)).toEqual(['b', 'a'])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user