zotero/test/tests/notifierTest.js
Dan Stillman 1694056956 Support multiple library tabs (#6035)
Additional library tabs can be opened via File → New Library Tab
(Cmd/Ctrl-T), a collection's context menu, or Duplicate Tab, and each
holds its own live library view. Library tabs share layout settings
(pane sizes, stacked or standard layout, and columns) and tag selector
display options, and a tab picks up the current ones when it's shown.
Closed library tabs reopen with their collections, selected items,
searches, and tag selection.

Every library tab can be closed, including the window's first one, so
a window can have no library view at all. Closing a window's last tab
closes the window, except for the last tab of the last window on
Windows and Linux, which stays open so that closing a tab doesn't quit
Zotero.

For backward compatibility with plugins, the window's first library
view keeps the original element ids. Other views append their tab's id
to each element id (e.g., zotero-items-tree-tab-k3Xq9TzA).

The onMainWindowLoad and onMainWindowUnload plugin hooks now follow a
window's library views rather than the window itself. Since a main
window might not have a library view, code that iterates
Zotero.getMainWindows() should check ZoteroPane.libraryView.
2026-11-06 20:58:05 -05:00

114 lines
3.1 KiB
JavaScript

"use strict";
describe("Zotero.Notifier", function () {
describe("#trigger()", function () {
it("should trigger add events before modify events", async function () {
var events = [];
var observer = {
notify: (action, type, ids) => {
events.push(action);
}
};
// Only item events, since a window closed by a previous test can still be closing its
// tabs
var id = Zotero.Notifier.registerObserver(observer, ['item'], 'test_trigger');
await Zotero.DB.executeTransaction(async function () {
var item = new Zotero.Item('book');
item.setField('title', 'A');
await item.save();
item.setField('title', 'B');
await item.save();
Zotero.Notifier.queue('unknown', 'item', item.id);
});
assert.lengthOf(events, 3);
assert.equal(events[0], 'add');
assert.equal(events[1], 'modify');
assert.equal(events[2], 'unknown');
Zotero.Notifier.unregisterObserver(id);
});
it("should add events to passed queue", async function () {
var collection = await createDataObject('collection');
var didNotify = false;
var observer = {
notify: () => didNotify = true
};
// Only item events, since a window closed by a previous test can still be closing its
// tabs
var id = Zotero.Notifier.registerObserver(observer, ['item'], 'test_trigger');
var queue = new Zotero.Notifier.Queue;
var item = createUnsavedDataObject('item');
item.setCollections([collection.id]);
await item.saveTx({
notifierQueue: queue
});
assert.isFalse(didNotify);
assert.equal(queue.size, 2);
await Zotero.Notifier.commit(queue);
assert.isTrue(didNotify);
Zotero.Notifier.unregisterObserver(id);
});
});
describe("#queue", function () {
it("should handle notification after DB timeout from another transaction", async function () {
var promise1 = Zotero.DB.executeTransaction(async function () {
var item = createUnsavedDataObject('item');
await item.save();
await Zotero.Promise.delay(2000);
Zotero.Notifier.queue('refresh', 'item', item.id);
}.bind(this));
var promise2 = Zotero.DB.executeTransaction(async function () {
var item = createUnsavedDataObject('item');
await item.save();
}.bind(this), { waitTimeout: 1000 });
await promise1;
assert.ok(await getPromiseError(promise2));
});
});
describe("Queue", function () {
describe("#commit()", function () {
it("should add options from queue to extraData", async function () {
var called = false;
var data;
var notifierID = Zotero.Notifier.registerObserver({
notify: (event, type, ids, extraData) => {
called = true;
data = extraData;
}
});
var notifierQueue = new Zotero.Notifier.Queue({
skipAutoSync: true
});
var item = createUnsavedDataObject('item');
await item.saveTx({
notifierQueue
});
assert.isFalse(called);
await Zotero.Notifier.commit(notifierQueue);
assert.isTrue(called);
assert.propertyVal(data, 'skipAutoSync', true);
Zotero.Notifier.unregisterObserver(notifierID);
});
});
});
});