#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,29 +450,37 @@ const findGroupForItemPathInBookmarks = (itemPath: string, createIfMissing: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
let group: BookmarkedGroup|undefined = undefined
|
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
|
group = items.find((it) => it.type === 'group' && groupNameForPath(it.title||'') === pathSegment) as BookmarkedGroup
|
||||||
if (!group) {
|
if (!group) {
|
||||||
if (createIfMissing) {
|
if (createIfMissing) {
|
||||||
const theSortingBookmarksContainerGroup = (bookmarksGroup && index === 0)
|
const theSortingBookmarksContainerGroup = !!bookmarksGroup && firstItem
|
||||||
const groupName: string = theSortingBookmarksContainerGroup ? pathSegment : groupNameTransparentForSorting(pathSegment)
|
const groupName: string = theSortingBookmarksContainerGroup ? pathSegment : groupNameTransparentForSorting(pathSegment)
|
||||||
group = createBookmarkGroupEntry(groupName)
|
group = createBookmarkGroupEntry(groupName)
|
||||||
items.push(group)
|
items.push(group)
|
||||||
} else {
|
} else {
|
||||||
return undefined
|
failed = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
firstItem = false
|
||||||
}
|
}
|
||||||
|
|
||||||
items = group.items
|
items = group.items
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if (failed) {
|
||||||
|
return undefined
|
||||||
|
} else {
|
||||||
return {
|
return {
|
||||||
items: items,
|
items: items,
|
||||||
group: group,
|
group: group,
|
||||||
pathOfGroup: parentPath
|
pathOfGroup: parentPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const CreateIfMissing = true
|
const CreateIfMissing = true
|
||||||
const DontCreateIfMissing = false
|
const DontCreateIfMissing = false
|
||||||
|
|
Loading…
Reference in New Issue