Scaffold: Support the detectedItemType
test field (#3023)
This commit is contained in:
parent
0ba81a1a92
commit
b1595cdd1d
2 changed files with 41 additions and 33 deletions
|
@ -1316,6 +1316,12 @@ var Scaffold = new function () {
|
||||||
_writeToEditor(_editors.tests, _stringifyTests(tests));
|
_writeToEditor(_editors.tests, _stringifyTests(tests));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _confirmCreateExpectedFailTest() {
|
||||||
|
return Services.prompt.confirm(null,
|
||||||
|
'Detection Failed',
|
||||||
|
'Add test ensuring that detection always fails on this page?');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mimics most of the behavior of Zotero.Item#fromJSON. Most importantly,
|
* Mimics most of the behavior of Zotero.Item#fromJSON. Most importantly,
|
||||||
* extracts valid fields from item.extra and inserts invalid fields into
|
* extracts valid fields from item.extra and inserts invalid fields into
|
||||||
|
@ -1532,7 +1538,7 @@ var Scaffold = new function () {
|
||||||
|
|
||||||
if (level < 2 && value.items) {
|
if (level < 2 && value.items) {
|
||||||
// Test object. Arrange properties in set order
|
// Test object. Arrange properties in set order
|
||||||
let order = ['type', 'url', 'input', 'defer', 'items'];
|
let order = ['type', 'url', 'input', 'defer', 'detectedItemType', 'items'];
|
||||||
for (let i = 0; i < order.length; i++) {
|
for (let i = 0; i < order.length; i++) {
|
||||||
let val = processRow(order[i], value[order[i]]);
|
let val = processRow(order[i], value[order[i]]);
|
||||||
if (val === undefined) continue;
|
if (val === undefined) continue;
|
||||||
|
@ -1639,14 +1645,16 @@ var Scaffold = new function () {
|
||||||
_translatorProvider
|
_translatorProvider
|
||||||
);
|
);
|
||||||
return new Promise(
|
return new Promise(
|
||||||
(resolve, reject) => tester.newTest(input, function (obj, newTest) { // "done" handler for do
|
(resolve, reject) => tester.newTest(input,
|
||||||
if (newTest) {
|
(obj, newTest) => { // "done" handler for do
|
||||||
resolve(_sanitizeItemsInTest(newTest));
|
if (newTest) {
|
||||||
}
|
resolve(_sanitizeItemsInTest(newTest));
|
||||||
else {
|
}
|
||||||
reject(new Error('Creation failed'));
|
else {
|
||||||
}
|
reject(new Error('Creation failed'));
|
||||||
})
|
}
|
||||||
|
},
|
||||||
|
_confirmCreateExpectedFailTest)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (type == "import" || type == "search") {
|
else if (type == "import" || type == "search") {
|
||||||
|
@ -1976,13 +1984,11 @@ var Scaffold = new function () {
|
||||||
var test = this.testsToUpdate.shift();
|
var test = this.testsToUpdate.shift();
|
||||||
_logOutput("Updating test " + (this.numTestsTotal - this.testsToUpdate.length));
|
_logOutput("Updating test " + (this.numTestsTotal - this.testsToUpdate.length));
|
||||||
|
|
||||||
var me = this;
|
|
||||||
|
|
||||||
if (test.type == 'web') {
|
if (test.type == 'web') {
|
||||||
_logOutput("Loading web page from " + test.url);
|
_logOutput("Loading web page from " + test.url);
|
||||||
var hiddenBrowser = Zotero.HTTP.loadDocuments(
|
var hiddenBrowser = Zotero.HTTP.loadDocuments(
|
||||||
test.url,
|
test.url,
|
||||||
function (doc) {
|
(doc) => {
|
||||||
_logOutput("Page loaded");
|
_logOutput("Page loaded");
|
||||||
if (test.defer) {
|
if (test.defer) {
|
||||||
_logOutput("Waiting " + (Zotero_TranslatorTester.DEFER_DELAY / 1000)
|
_logOutput("Waiting " + (Zotero_TranslatorTester.DEFER_DELAY / 1000)
|
||||||
|
@ -1990,32 +1996,34 @@ var Scaffold = new function () {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Zotero.setTimeout(
|
Zotero.setTimeout(
|
||||||
function () {
|
() => {
|
||||||
doc = hiddenBrowser.contentDocument;
|
doc = hiddenBrowser.contentDocument;
|
||||||
if (doc.location.href != test.url) {
|
if (doc.location.href != test.url) {
|
||||||
_logOutput("Page URL differs from test. Will be updated. " + doc.location.href);
|
_logOutput("Page URL differs from test. Will be updated. " + doc.location.href);
|
||||||
}
|
}
|
||||||
me.tester.newTest(doc, function (obj, newTest) {
|
this.tester.newTest(doc,
|
||||||
Zotero.Browser.deleteHiddenBrowser(hiddenBrowser);
|
(obj, newTest) => {
|
||||||
if (test.defer) {
|
Zotero.Browser.deleteHiddenBrowser(hiddenBrowser);
|
||||||
newTest.defer = true;
|
if (test.defer) {
|
||||||
}
|
newTest.defer = true;
|
||||||
newTest = _sanitizeItemsInTest(newTest);
|
}
|
||||||
me.newTests.push(newTest);
|
newTest = _sanitizeItemsInTest(newTest);
|
||||||
me.testDoneCallback(newTest);
|
this.newTests.push(newTest);
|
||||||
me._updateTests();
|
this.testDoneCallback(newTest);
|
||||||
});
|
this._updateTests();
|
||||||
|
},
|
||||||
|
_confirmCreateExpectedFailTest);
|
||||||
},
|
},
|
||||||
test.defer ? Zotero_TranslatorTester.DEFER_DELAY : 0,
|
test.defer ? Zotero_TranslatorTester.DEFER_DELAY : 0,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
function (e) {
|
(e) => {
|
||||||
Zotero.logError(e);
|
Zotero.logError(e);
|
||||||
me.newTests.push(false);
|
this.newTests.push(false);
|
||||||
me.testDoneCallback(false);
|
this.testDoneCallback(false);
|
||||||
me._updateTests();
|
this._updateTests();
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
@ -2033,15 +2041,15 @@ var Scaffold = new function () {
|
||||||
|
|
||||||
// Re-runs the test.
|
// Re-runs the test.
|
||||||
// TranslatorTester doesn't handle these correctly, so we do it manually
|
// TranslatorTester doesn't handle these correctly, so we do it manually
|
||||||
_run(methods[test.type], test.input, null, function (obj, item) {
|
_run(methods[test.type], test.input, null, (obj, item) => {
|
||||||
if (item) {
|
if (item) {
|
||||||
test.items.push(Zotero_TranslatorTester._sanitizeItem(item));
|
test.items.push(Zotero_TranslatorTester._sanitizeItem(item));
|
||||||
}
|
}
|
||||||
}, null, function () {
|
}, null, () => {
|
||||||
if (!test.items.length) test = false;
|
if (!test.items.length) test = false;
|
||||||
me.newTests.push(test);
|
this.newTests.push(test);
|
||||||
me.testDoneCallback(test);
|
this.testDoneCallback(test);
|
||||||
me._updateTests();
|
this._updateTests();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6a9270c992e39998389267810ec21b8cd735730e
|
Subproject commit fcb7b8ae9500be2c7c29e4306400f82fe21c5656
|
Loading…
Add table
Add a link
Reference in a new issue