FileHandlers tests: Wait for notifier instead of _setState() call

_setState() doesn't await setAttachmentLastPageIndex(), so the setting
sometimes won't be updated in the cache by the time we call
getAttachmentLastPageIndex() below. Notifier event should work every
time (and is a lot simpler).
This commit is contained in:
Abe Jellinek 2024-02-29 11:05:12 -08:00
parent 9e78957c72
commit ea63780600

View file

@ -34,20 +34,12 @@ describe("Zotero.FileHandlers", () => {
let reader = Zotero.Reader.getByTabID(win.Zotero_Tabs.selectedID);
assert.ok(reader);
// Wait for _setState() (is there an easier way to do this?)
let stub = sinon.stub(reader, '_setState');
let setStatePromise = new Promise((resolve) => {
stub.callsFake(async (...args) => {
await stub.wrappedMethod.apply(reader, args);
resolve();
});
});
let notifierPromise = waitForNotifierEvent('add', 'setting');
await reader._waitForReader();
await setStatePromise;
await notifierPromise;
// Check that the reader navigated to the correct page
assert.equal(pdf.getAttachmentLastPageIndex(), 2);
stub.restore();
});
it("should open a PDF in a new window when no handler is set and openInWindow is passed", async function () {