Test for subsequent updates providing stale changed object data

From #5297
This commit is contained in:
Tom Najdek 2025-05-16 20:40:44 +02:00 • committed by Dan Stillman
parent ded8dca668
commit ee35361608
2 changed files with 16 additions and 3 deletions

View file

@ -1190,6 +1190,8 @@ Zotero.DataObject.prototype._postSave = function (env) {
let rel = env.relationsToUnregister[i];
Zotero.Relations.unregister(this._objectType, this.id, rel[0], rel[1]);
}
this._changed = {};
this._previousData = {};
};

View file

@ -2000,15 +2000,26 @@ describe("Zotero.Item", function () {
});
it("should include changed field data in notifier extraData", async function () {
var item = await createDataObject('item', { title: 'old value' });
var item = await createDataObject('item', { title: 'first' });
var promise = waitForNotifierEvent('modify', 'item');
item.setField('title', 'new value');
item.setField('title', 'second');
item.setField('extra', 'extra');
await item.saveTx();
var { ids, extraData } = await promise;
assert.deepPropertyVal(extraData[ids[0]], 'changed', { title: 'old value' });
// "first" -> "second", old value is "first" and "extra" was empty
assert.deepPropertyVal(extraData[ids[0]], 'changed', { title: 'first', extra: false });
var promise = waitForNotifierEvent('modify', 'item');
item.setField('title', 'third');
await item.saveTx();
var { ids, extraData } = await promise;
// "second" -> "third", old value is "second", and we don't notify about "extra" because it's not changed this time
assert.deepPropertyVal(extraData[ids[0]], 'changed', { title: 'second' });
});
// 'deleted' and 'tags' use a different, newer mechanism for marking changes