Rename Zotero.Items::keepParents() to keepTopLevel()

So that it works for more than two levels of items

Also fix a bug where the parent item could be returned more than once if
multiple child items were selected.
This commit is contained in:
Dan Stillman 2022-08-25 05:15:40 -04:00
parent 497d6376c8
commit 39e45221b1
2 changed files with 28 additions and 10 deletions

View file

@ -1234,6 +1234,17 @@ describe("Zotero.Items", function () {
[item1, item4, item6].map(item => item.id)
);
});
it("shouldn't return parent item more than once when two child items are selected", async function () {
var item1 = await createDataObject('item');
var item2 = await createDataObject('item', { itemType: 'note', parentItemID: item1.id });
var item3 = await createDataObject('item', { itemType: 'note', parentItemID: item1.id });
var items = Zotero.Items.keepParents([item2, item3]);
assert.sameMembers(
items.map(item => item.id),
[item2.id, item3.id]
)
});
});
describe("#_loadChildItems()", function () {