#74 - Integration with Bookmarks core plugin and support for indirect drag & drop arrangement
- minor bugfix - incorrect detection if an item is already bookmarked
This commit is contained in:
parent
6e589b5a6e
commit
8e6c8ded98
|
@ -1063,3 +1063,106 @@ describe('cleanupBookmarkTreeFromTransparentEmptyGroups', () => {
|
|||
}))))
|
||||
})
|
||||
})
|
||||
|
||||
describe('findGroupForItemPathInBookmarks', () =>{
|
||||
it('should return undefined if the matching container does not exist - case: no sortspec container', () => {
|
||||
const items = consumeBkMock({})
|
||||
const plugin = getBookmarksMock(items)
|
||||
const parentFolder: BookmarkedParentFolder|undefined = _unitTests.findGroupForItemPathInBookmarks(
|
||||
'inbox',
|
||||
false,
|
||||
plugin,
|
||||
'sortspec'
|
||||
)
|
||||
expect(parentFolder).toBeUndefined()
|
||||
})
|
||||
it('should return undefined if the matching container does not exist - case: no 2nd level container', () => {
|
||||
const items = consumeBkMock({
|
||||
"sortspec": {
|
||||
"\\\\group l1.1": {
|
||||
"\\\\group l2.1": {
|
||||
"\\\\group l3.1": {
|
||||
"\\\\deepest 1": {}
|
||||
}
|
||||
},
|
||||
"\\\\group l2.2": {
|
||||
"\\\\deepest 2": {}
|
||||
}
|
||||
},
|
||||
"\\\\group l1.2": {
|
||||
"\\\\group l2.1": {
|
||||
"\\\\deepest 3": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
const plugin = getBookmarksMock(items)
|
||||
const parentFolder: BookmarkedParentFolder|undefined = _unitTests.findGroupForItemPathInBookmarks(
|
||||
'group l1.1/group l2.2/group l3.1/deepest 1',
|
||||
false,
|
||||
plugin,
|
||||
'sortspec'
|
||||
)
|
||||
expect(parentFolder).toBeUndefined()
|
||||
})
|
||||
it('should return the sortspec container for root level items', () => {
|
||||
const items = consumeBkMock({
|
||||
"sortspec": {}
|
||||
})
|
||||
const plugin = getBookmarksMock(items)
|
||||
const parentFolder: BookmarkedParentFolder|undefined = _unitTests.findGroupForItemPathInBookmarks(
|
||||
'inbox',
|
||||
false,
|
||||
plugin,
|
||||
'sortspec'
|
||||
)
|
||||
const expectedGroup = consumeBkMock({
|
||||
"sortspec": {}
|
||||
})
|
||||
const expected = {
|
||||
group: expectedGroup[0],
|
||||
items: expectedGroup[0].items,
|
||||
pathOfGroup: ''
|
||||
}
|
||||
expect(JSON.parse(JSON.stringify(parentFolder))).toEqual(JSON.parse(JSON.stringify(expected)))
|
||||
})
|
||||
it('should return the correct 2nd level container', () => {
|
||||
const items = consumeBkMock({
|
||||
"sortspec": {
|
||||
"\\\\group l1.1": {
|
||||
"\\\\group l2.1": {
|
||||
"\\\\group l3.1": {
|
||||
"\\\\deepest 1": {}
|
||||
}
|
||||
},
|
||||
"\\\\group l2.2": {
|
||||
"\\\\deepest 2": {}
|
||||
}
|
||||
},
|
||||
"\\\\group l1.2": {
|
||||
"\\\\group l2.1": {
|
||||
"\\\\deepest 3": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
const plugin = getBookmarksMock(items)
|
||||
const parentFolder: BookmarkedParentFolder|undefined = _unitTests.findGroupForItemPathInBookmarks(
|
||||
'group l1.2/group l2.1/deepest 3',
|
||||
false,
|
||||
plugin,
|
||||
'sortspec'
|
||||
)
|
||||
const expectedGroup = consumeBkMock({
|
||||
"\\\\group l2.1": {
|
||||
"\\\\deepest 3": {}
|
||||
}
|
||||
})
|
||||
const expected = {
|
||||
group: expectedGroup[0],
|
||||
items: expectedGroup[0].items,
|
||||
pathOfGroup: 'group l1.2/group l2.1'
|
||||
}
|
||||
expect(JSON.parse(JSON.stringify(parentFolder))).toEqual(JSON.parse(JSON.stringify(expected)))
|
||||
})
|
||||
})
|
||||
|
|
|
@ -450,28 +450,36 @@ const findGroupForItemPathInBookmarks = (itemPath: string, createIfMissing: bool
|
|||
}
|
||||
|
||||
let group: BookmarkedGroup|undefined = undefined
|
||||
let failed: boolean = false
|
||||
let firstItem: boolean = true
|
||||
|
||||
parentPathComponents.forEach((pathSegment, index) => {
|
||||
for (let pathSegment of parentPathComponents) {
|
||||
group = items.find((it) => it.type === 'group' && groupNameForPath(it.title||'') === pathSegment) as BookmarkedGroup
|
||||
if (!group) {
|
||||
if (createIfMissing) {
|
||||
const theSortingBookmarksContainerGroup = (bookmarksGroup && index === 0)
|
||||
const theSortingBookmarksContainerGroup = !!bookmarksGroup && firstItem
|
||||
const groupName: string = theSortingBookmarksContainerGroup ? pathSegment : groupNameTransparentForSorting(pathSegment)
|
||||
group = createBookmarkGroupEntry(groupName)
|
||||
items.push(group)
|
||||
} else {
|
||||
return undefined
|
||||
failed = true
|
||||
break
|
||||
}
|
||||
firstItem = false
|
||||
}
|
||||
|
||||
items = group.items
|
||||
})
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
return undefined
|
||||
} else {
|
||||
return {
|
||||
items: items,
|
||||
group: group,
|
||||
pathOfGroup: parentPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const CreateIfMissing = true
|
||||
|
|
Loading…
Reference in New Issue