56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
import Admin from '../views/Admin.vue'
|
|
|
|
test('Admin categoryTree groups flat "/"-joined category paths into a tree', () => {
|
|
const categories = [
|
|
'Electronics',
|
|
'Electronics/Passives',
|
|
'Electronics/Passives/Resistors',
|
|
'Electronics/Actives',
|
|
'Tools',
|
|
]
|
|
|
|
const categoryTree = Admin.computed.categoryTree.call({categories})
|
|
|
|
expect(categoryTree).toEqual([
|
|
{
|
|
id: 'Electronics', name: 'Electronics', children: [
|
|
{id: 'Electronics/Actives', name: 'Actives', children: []},
|
|
{
|
|
id: 'Electronics/Passives', name: 'Passives', children: [
|
|
{id: 'Electronics/Passives/Resistors', name: 'Resistors', children: []},
|
|
]
|
|
},
|
|
]
|
|
},
|
|
{id: 'Tools', name: 'Tools', children: []},
|
|
])
|
|
})
|
|
|
|
test('Admin storageLocationTree groups locations by their real parent id', () => {
|
|
const storage_locations = [
|
|
{id: 3, name: 'Shelf B', parent: 1},
|
|
{id: 1, name: 'Garage', parent: null},
|
|
{id: 5, name: 'Attic', parent: null},
|
|
{id: 2, name: 'Shelf A', parent: 1},
|
|
{id: 4, name: 'Drawer 1', parent: 3},
|
|
// A location whose parent was deleted/isn't in this owner's own list falls back to root.
|
|
{id: 6, name: 'Orphan Box', parent: 99},
|
|
]
|
|
|
|
const storageLocationTree = Admin.computed.storageLocationTree.call({storage_locations})
|
|
|
|
expect(storageLocationTree).toEqual([
|
|
{id: 5, name: 'Attic', children: []},
|
|
{
|
|
id: 1, name: 'Garage', children: [
|
|
{id: 2, name: 'Shelf A', children: []},
|
|
{
|
|
id: 3, name: 'Shelf B', children: [
|
|
{id: 4, name: 'Drawer 1', children: []},
|
|
]
|
|
},
|
|
]
|
|
},
|
|
{id: 6, name: 'Orphan Box', children: []},
|
|
])
|
|
})
|