Fix attachment tests that depend on HTML indexing

HTML files are now indexed instead of read directly, and indexing was
previous skipped in tests and otherwise performed on a delay, so set a
flag in the affected tests that triggers inline indexing.
This commit is contained in:
Dan Stillman 2023-04-15 00:19:27 -04:00
parent d1ae009f57
commit 2796e6c80a
3 changed files with 22 additions and 8 deletions

View file

@ -719,7 +719,7 @@ Zotero.Attachments = new function(){
await Zotero.Notifier.commit(notifierQueue);
}
Zotero.Fulltext.queueItem(attachmentItem);
await Zotero.FullText.queueItem(attachmentItem);
return attachmentItem;
};
@ -952,11 +952,11 @@ Zotero.Attachments = new function(){
attachmentItem.attachmentPath = 'storage:' + fileName;
var itemID = await attachmentItem.save(saveOptions);
Zotero.Fulltext.queueItem(attachmentItem);
destDir = this.getStorageDirectory(attachmentItem).path;
await OS.File.move(tmpDir, destDir);
}.bind(this));
yield Zotero.FullText.queueItem(attachmentItem);
}
catch (e) {
Zotero.debug(e, 1);
@ -1047,10 +1047,10 @@ Zotero.Attachments = new function(){
saveOptions
});
Zotero.Fulltext.queueItem(attachmentItem);
destDirectory = this.getStorageDirectory(attachmentItem).path;
await OS.File.move(tmpDirectory, destDirectory);
await Zotero.FullText.queueItem(attachmentItem);
}
catch (e) {
Zotero.debug(e, 1);

View file

@ -549,9 +549,17 @@ Zotero.Fulltext = Zotero.FullText = new function(){
var _nextIndexTime;
var _indexDelay = 5000;
var _indexInterval = 500;
this.queueItem = function (item) {
// Don't index files in the background during tests
if (Zotero.test) return;
var _indexNextInTest = false;
this.queueItem = async function (item) {
// Index files immediately during tests that enable it
if (Zotero.test) {
if (_indexNextInTest) {
_indexNextInTest = false;
await this.indexItems([item.id]);
}
return;
}
_queue.push(item.id);
_nextIndexTime = Date.now() + _indexDelay;
@ -560,6 +568,10 @@ Zotero.Fulltext = Zotero.FullText = new function(){
}, _indexDelay);
};
this.indexNextInTest = function () {
_indexNextInTest = true;
};
async function _processNextItem() {
if (!_queue.length) return;
// Another _processNextItem() was scheduled

View file

@ -357,6 +357,7 @@ describe("Zotero.Attachments", function() {
httpd.registerDirectory("/" + prefix + "/", new FileUtils.File(uri));
browser = await HiddenBrowser.create(testServerPath + "/index.html");
Zotero.FullText.indexNextInTest();
var attachment = await Zotero.Attachments.importFromDocument({
browser,
parentItemID: item.id
@ -528,6 +529,7 @@ describe("Zotero.Attachments", function() {
let snapshotContent = await Zotero.File.getContentsAsync(content);
Zotero.FullText.indexNextInTest();
let attachment = await Zotero.Attachments.importFromSnapshotContent({
parentItemID: item.id,
url: "https://example.com/test.html",