Fix updating of deleted collections in Libraries & Collections (#4324)
- listen to 'collection' notifier events and re-render the section if a relevant collection is moved to trash or modified. That way, a deleted collection will be removed, a restored collection will be added back, and renaming a collection will update the name. - fixed a bug where a restored collection would not be added into item._collections cache. Fixed false-positive test for it. - do not add deleted collections into items. _collections cache in Zotero.Items._loadCollections. Otherwise, deleted collections will appear in librariesCollectionsBox after the app is restarted.
This commit is contained in:
parent
680a175a32
commit
2401a34031
5 changed files with 90 additions and 6 deletions
|
@ -394,6 +394,60 @@ describe("Item pane", function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe("Libraries and collections pane", function () {
|
||||
var item, collectionParent, collectionChild, section;
|
||||
|
||||
// Fresh setup of an item belonging to 2 collections - parent and child - for each test
|
||||
beforeEach(async function () {
|
||||
collectionParent = await createDataObject('collection');
|
||||
collectionChild = await createDataObject('collection', { parentID: collectionParent.id });
|
||||
item = await createDataObject('item', { collections: [collectionParent.id, collectionChild.id] });
|
||||
await ZoteroPane.selectItem(item.id);
|
||||
section = ZoteroPane.itemPane._itemDetails.getPane("libraries-collections");
|
||||
});
|
||||
|
||||
it("should update collection's name after rename", async function () {
|
||||
collectionChild.name = "Updated collection name";
|
||||
collectionChild.saveTx();
|
||||
|
||||
await waitForNotifierEvent('modify', 'collection');
|
||||
|
||||
let collectionRow = section.querySelector(`.row[data-id="C${collectionChild.id}"]`);
|
||||
assert.equal(collectionRow.innerText, collectionChild.name);
|
||||
});
|
||||
|
||||
it("should remove collection that has been trashed", async function () {
|
||||
collectionChild.deleted = true;
|
||||
collectionChild.saveTx();
|
||||
|
||||
await waitForNotifierEvent('trash', 'collection');
|
||||
|
||||
let rowIDs = [...section.querySelectorAll(".row")].map(node => node.dataset.id);
|
||||
assert.deepEqual(rowIDs, [`L${item.libraryID}`, `C${collectionParent.id}`]);
|
||||
});
|
||||
|
||||
it("should bring back collection restored from trash", async function () {
|
||||
collectionChild.deleted = true;
|
||||
collectionChild.saveTx();
|
||||
|
||||
await waitForNotifierEvent('trash', 'collection');
|
||||
|
||||
// Make sure the collection is actually gone
|
||||
let rowIDs = [...section.querySelectorAll(".row")].map(node => node.dataset.id);
|
||||
assert.deepEqual(rowIDs, [`L${item.libraryID}`, `C${collectionParent.id}`]);
|
||||
|
||||
// Restore the collection from trash
|
||||
collectionChild.deleted = false;
|
||||
collectionChild.saveTx();
|
||||
|
||||
await waitForNotifierEvent('modify', 'collection');
|
||||
|
||||
// The collection row should appear again
|
||||
rowIDs = [...section.querySelectorAll(".row")].map(node => node.dataset.id);
|
||||
assert.deepEqual(rowIDs, [`L${item.libraryID}`, `C${collectionParent.id}`, `C${collectionChild.id}`]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Attachments pane", function () {
|
||||
let paneID = "attachments";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue