Fix attachment icon remains after deleting attachment. Fix #3779

This commit is contained in:
Tom Najdek 2024-03-08 15:21:31 +01:00
parent d0299a1acc
commit 16fa1ac893
No known key found for this signature in database
GPG key ID: EEC61A7B4C667D77
2 changed files with 22 additions and 1 deletions

View file

@ -2744,7 +2744,7 @@ Zotero.Item.prototype._updateAttachmentStates = function (exists) {
return;
}
if (item._bestAttachmentState?.key && this.key === item._bestAttachmentState.key) {
if (!this.deleted && item._bestAttachmentState?.key && this.key === item._bestAttachmentState.key) {
item._bestAttachmentState.exists = exists;
}
else {

View file

@ -1280,6 +1280,27 @@ describe("Zotero.Item", function () {
{ type: 'image', exists: true, key: childItem.key }
);
});
it("should update best attachment state when attachment is trashed", async function () {
var parentItem = await createDataObject('item');
var file = getTestDataDirectory();
file.append('test.png');
var childItem = await Zotero.Attachments.importFromFile({
file,
parentItemID: parentItem.id
});
await parentItem.getBestAttachmentState();
childItem._updateAttachmentStates(true);
assert.deepEqual(
parentItem.getBestAttachmentStateCached(),
{ type: 'image', exists: true, key: childItem.key }
);
await Zotero.Items.trashTx([childItem.id]);
childItem._updateAttachmentStates(true);
assert.deepEqual(parentItem.getBestAttachmentStateCached(), { type: null });
});
});