Fix test failures after 18f79f9796

This commit is contained in:
Dan Stillman 2018-10-06 01:38:32 -04:00
parent 7630a8a054
commit 1b9811c31d
3 changed files with 30 additions and 20 deletions

View file

@ -1228,20 +1228,19 @@ Zotero.Attachments = new function(){
// We reached the end of the queue // We reached the end of the queue
if (!current) { if (!current) {
// If all entries are resolved, we're done // If all entries are resolved, we're done
if (queue.every(x => x instanceof Zotero.Item || x.result === false)) { if (queue.every(x => x.result instanceof Zotero.Item || x.result === false)) {
resolve(); resolve();
return; return;
} }
// Otherwise, wait until the next time a pending request is ready to process // Otherwise, wait until the next time a pending request is ready to process
// and restart // and restart. If no pending requests, they're all in progress.
let nextStart = queue let nextStart = queue
.map(x => x.result === null && getDomainInfo(x.domain).nextRequestTime) .map(x => x.result === null && getDomainInfo(x.domain).nextRequestTime)
.filter(x => x) .filter(x => x)
.reduce((accumulator, currentValue) => { .reduce((accumulator, currentValue) => {
return currentValue < accumulator ? currentValue : accumulator; return currentValue < accumulator ? currentValue : accumulator;
}); });
i = 0; i = 0;
setTimeout(processNextItem, Math.max(0, nextStart - Date.now())); setTimeout(processNextItem, Math.max(0, nextStart - Date.now()));
return; return;

View file

@ -69,9 +69,14 @@ Zotero.ProgressQueueDialog = function (progressQueue) {
_showMinimize = show; _showMinimize = show;
}; };
function close() { this.close = function () {
// In case close() is called before open()
if (!_progressWindow) {
return;
}
_progressWindow.close(); _progressWindow.close();
} _progressQueue.cancel();
};
function _getImageByStatus(status) { function _getImageByStatus(status) {
if (status === Zotero.ProgressQueue.ROW_PROCESSING) { if (status === Zotero.ProgressQueue.ROW_PROCESSING) {
@ -140,20 +145,18 @@ Zotero.ProgressQueueDialog = function (progressQueue) {
_progressIndicator = _progressWindow.document.getElementById('progress-indicator'); _progressIndicator = _progressWindow.document.getElementById('progress-indicator');
_progressWindow.document.getElementById('cancel-button') _progressWindow.document.getElementById('cancel-button')
.addEventListener('command', function () { .addEventListener('command', () => {
close(); this.close();
_progressQueue.cancel();
}, false); }, false);
_progressWindow.document.getElementById('minimize-button') _progressWindow.document.getElementById('minimize-button')
.addEventListener('command', function () { .addEventListener('command', function () {
close(); _progressWindow.close();
}, false); }, false);
_progressWindow.document.getElementById('close-button') _progressWindow.document.getElementById('close-button')
.addEventListener('command', function () { .addEventListener('command', () => {
close(); this.close();
_progressQueue.cancel();
}, false); }, false);
_progressWindow.addEventListener('keypress', function (e) { _progressWindow.addEventListener('keypress', function (e) {
@ -162,7 +165,7 @@ Zotero.ProgressQueueDialog = function (progressQueue) {
if (_progressQueue.getTotal() === _progressQueue.getProcessedTotal()) { if (_progressQueue.getTotal() === _progressQueue.getProcessedTotal()) {
_progressQueue.cancel(); _progressQueue.cancel();
} }
close(); _progressWindow.close();
} }
}); });

View file

@ -583,6 +583,12 @@ describe("Zotero.Attachments", function() {
httpd.stop(() => resolve()); httpd.stop(() => resolve());
}); });
Zotero.Prefs.clear('findPDFs.resolvers'); Zotero.Prefs.clear('findPDFs.resolvers');
// Close progress dialog after each run
var queue = Zotero.ProgressQueues.get('findPDF');
if (queue) {
queue.getDialog().close();
}
}.bind(this)); }.bind(this));
after(() => { after(() => {
@ -751,8 +757,9 @@ describe("Zotero.Attachments", function() {
assert.isTrue(requestStub.calledTwice); assert.isTrue(requestStub.calledTwice);
assert.isAbove(requestStubCallTimes[1] - requestStubCallTimes[0], 1000); assert.isAbove(requestStubCallTimes[1] - requestStubCallTimes[0], 1000);
// Make sure there's an attachment for every item // Make sure both items have attachments
assert.lengthOf(attachments.filter(x => x), 2); assert.equal(item1.numAttachments(), 1);
assert.equal(item2.numAttachments(), 1);
}); });
it("should wait between requests that resolve to the same domain", async function () { it("should wait between requests that resolve to the same domain", async function () {
@ -793,9 +800,9 @@ describe("Zotero.Attachments", function() {
// 'website' requests should be a second apart // 'website' requests should be a second apart
assert.isAbove(requestStubCallTimes[5] - requestStubCallTimes[1], 1000); assert.isAbove(requestStubCallTimes[5] - requestStubCallTimes[1], 1000);
assert.instanceOf(attachments[0], Zotero.Item); assert.equal(item1.numAttachments(), 1);
assert.isFalse(attachments[1]); assert.equal(item2.numAttachments(), 0);
assert.instanceOf(attachments[2], Zotero.Item); assert.equal(item3.numAttachments(), 1);
}); });
it("should wait between requests to the same domain after a 429", async function () { it("should wait between requests to the same domain after a 429", async function () {
@ -818,8 +825,9 @@ describe("Zotero.Attachments", function() {
assert.equal(requestStub.getCall(1).args[1], pageURL9); assert.equal(requestStub.getCall(1).args[1], pageURL9);
assert.equal(requestStub.getCall(2).args[1], pageURL3); assert.equal(requestStub.getCall(2).args[1], pageURL3);
assert.isAbove(requestStubCallTimes[1] - requestStubCallTimes[0], 2000); assert.isAbove(requestStubCallTimes[1] - requestStubCallTimes[0], 2000);
// Make sure there's an attachment for every item // Make sure both items have attachments
assert.lengthOf(attachments.filter(x => x), 2); assert.equal(item1.numAttachments(), 1);
assert.equal(item2.numAttachments(), 1);
}); });
it("should handle a custom resolver in HTML mode", async function () { it("should handle a custom resolver in HTML mode", async function () {