Tests: Don't auto-select collections and searches after creation

This changes `createDataObject()` to pass `skipSelect: true` for objects
other than items. If a test is creating a bunch of collections, there's
no reason for each one to be selected and for an items list to start to
load. If a test does need a new collection or search to be selected, it
can call the new convenience function `await select(win, obj)`, which
will select the passed object in the collection tree and wait for its
items list to load. I'm hoping this reduces random test failures due to
items list churn.
This commit is contained in:
Dan Stillman 2024-06-24 02:04:52 -04:00
parent 09aad7b075
commit 173f4c491e
10 changed files with 143 additions and 149 deletions

View file

@ -606,11 +606,14 @@ function createUnsavedDataObject(objectType, params = {}) {
return obj;
}
var createDataObject = Zotero.Promise.coroutine(function* (objectType, params = {}, saveOptions) {
async function createDataObject(objectType, params = {}, saveOptions) {
var obj = createUnsavedDataObject(objectType, params);
yield obj.saveTx(saveOptions);
var options = {
skipSelect: (objectType == 'item' || objectType == 'feedItem') ? false : true
};
await obj.saveTx(Object.assign(options, saveOptions));
return obj;
});
}
function getNameProperty(objectType) {
return objectType == 'item' ? 'title' : 'name';

View file

@ -117,6 +117,7 @@ describe("Zotero.CollectionTree", function() {
col1 = yield createDataObject('collection');
col2 = yield createDataObject('collection', { parentID: col1.id });
col3 = yield createDataObject('collection', { parentID: col2.id });
yield select(win, col3);
});
it("should open a library and respect stored container state", function* () {
@ -158,9 +159,8 @@ describe("Zotero.CollectionTree", function() {
var col4 = yield createDataObject('collection', { libraryID, parentID: col1.id });
var col5 = yield createDataObject('collection', { libraryID, parentID: col4.id });
// Close everything
yield Zotero.Promise.all([col4, col1, group]
.map(o => cv.toggleOpenState(cv.getRowIndexByID(o.treeViewID), false)));
// Close group
cv.toggleOpenState(cv.getRowIndexByID(group.treeViewID), false);
yield cv.expandLibrary(libraryID);
@ -175,11 +175,7 @@ describe("Zotero.CollectionTree", function() {
describe("#expandToCollection()", function () {
it("should expand a collection to a subcollection", function* () {
var collection1 = yield createDataObject('collection');
var collection2 = createUnsavedDataObject('collection');
collection2.parentID = collection1.id;
yield collection2.saveTx({
skipSelect: true
});
var collection2 = yield createDataObject('collection', { parentID: collection1.id });
var row = cv.getRowIndexByID("C" + collection1.id);
assert.isFalse(cv.isContainerOpen(row));
@ -397,6 +393,7 @@ describe("Zotero.CollectionTree", function() {
var o2 = await createDataObject(objectType, { name: ran + "BBB" });
var o3 = await createDataObject(objectType, { name: ran + "CCC" });
await cv.selectByID(o3.treeViewID);
assert.equal(zp.getCollectionTreeRow().ref.id, o3.id);
o1.deleted = true;
@ -503,6 +500,7 @@ describe("Zotero.CollectionTree", function() {
var c3 = yield createDataObject('collection', { name: "3", parentID: c1.id });
var c4 = yield createDataObject('collection', { name: "4", parentID: c3.id });
var c5 = yield createDataObject('collection', { name: "5", parentID: c1.id });
yield select(win, c4);
assert.equal(cv.getRowIndexByID(c1.treeViewID), rootRow + 1);
@ -593,9 +591,10 @@ describe("Zotero.CollectionTree", function() {
var group = yield createGroup();
yield createDataObject('collection', { libraryID: group.libraryID });
var c = yield createDataObject('collection', { libraryID: group.libraryID });
yield createDataObject('collection', { libraryID: group.libraryID, parentID: c.id });
var c2 = yield createDataObject('collection', { libraryID: group.libraryID, parentID: c.id });
yield createDataObject('collection', { libraryID: group.libraryID });
yield createDataObject('collection', { libraryID: group.libraryID });
yield select(win, c2);
// Group, collections, Duplicates, Unfiled, and trash
assert.equal(cv._rows.length, originalRowCount + 9);
@ -762,9 +761,9 @@ describe("Zotero.CollectionTree", function() {
});
describe("with items", function () {
it("should add an item to a collection", function* () {
var collection = yield createDataObject('collection', false, { skipSelect: true });
var item = yield createDataObject('item', false, { skipSelect: true });
it("should add an item to a collection", async function () {
var collection = await createDataObject('collection');
var item = await createDataObject('item', false, { skipSelect: true });
// Add observer to wait for collection add
var deferred = Zotero.Promise.defer();
@ -779,12 +778,11 @@ describe("Zotero.CollectionTree", function() {
}
}, 'collection-item', 'test');
yield onDrop('item', 'C' + collection.id, [item.id], deferred.promise);
await onDrop('item', 'C' + collection.id, [item.id], deferred.promise);
Zotero.Notifier.unregisterObserver(observerID);
yield cv.selectCollection(collection.id);
yield waitForItemsLoad(win);
await select(win, collection.id);
var itemsView = win.ZoteroPane.itemsView;
assert.equal(itemsView.rowCount, 1);
@ -794,8 +792,8 @@ describe("Zotero.CollectionTree", function() {
it("should move an item from one collection to another", function* () {
var collection1 = yield createDataObject('collection');
yield waitForItemsLoad(win);
var collection2 = yield createDataObject('collection', false, { skipSelect: true });
yield select(win, collection1);
var collection2 = yield createDataObject('collection');
var item = yield createDataObject('item', { collections: [collection1.id] });
// Add observer to wait for collection add
@ -820,8 +818,7 @@ describe("Zotero.CollectionTree", function() {
// Source collection should be empty
assert.equal(zp.itemsView.rowCount, 0);
yield cv.selectCollection(collection2.id);
yield waitForItemsLoad(win);
yield select(win, collection2);
// Target collection should have item
assert.equal(zp.itemsView.rowCount, 1);
@ -1154,15 +1151,18 @@ describe("Zotero.CollectionTree", function() {
assert.equal(cv.getRow(newColIndex4).level, cv.getRow(newColIndex1).level);
})
it("should move a subcollection and its subcollection down under another collection", function* () {
var collectionA = yield createDataObject('collection', { name: "A" }, { skipSelect: true });
var collectionB = yield createDataObject('collection', { name: "B", parentKey: collectionA.key });
var collectionC = yield createDataObject('collection', { name: "C", parentKey: collectionB.key });
var collectionD = yield createDataObject('collection', { name: "D" }, { skipSelect: true });
var collectionE = yield createDataObject('collection', { name: "E" }, { skipSelect: true });
var collectionF = yield createDataObject('collection', { name: "F" }, { skipSelect: true });
var collectionG = yield createDataObject('collection', { name: "G", parentKey: collectionD.key });
var collectionH = yield createDataObject('collection', { name: "H", parentKey: collectionG.key });
it("should move a subcollection and its subcollection down under another collection", async function () {
var collectionA = await createDataObject('collection', { name: "A" });
var collectionB = await createDataObject('collection', { name: "B", parentKey: collectionA.key });
var collectionC = await createDataObject('collection', { name: "C", parentKey: collectionB.key });
var collectionD = await createDataObject('collection', { name: "D" });
var collectionE = await createDataObject('collection', { name: "E" });
var collectionF = await createDataObject('collection', { name: "F" });
var collectionG = await createDataObject('collection', { name: "G", parentKey: collectionD.key });
var collectionH = await createDataObject('collection', { name: "H", parentKey: collectionG.key });
await cv.expandToCollection(collectionC.id);
await cv.expandToCollection(collectionH.id);
var colIndexA = cv.getRowIndexByID('C' + collectionA.id);
var colIndexB = cv.getRowIndexByID('C' + collectionB.id);
@ -1173,7 +1173,7 @@ describe("Zotero.CollectionTree", function() {
var colIndexG = cv.getRowIndexByID('C' + collectionG.id);
var colIndexH = cv.getRowIndexByID('C' + collectionH.id);
yield cv.selectCollection(collectionG.id);
await select(win, collectionG);
// Add observer to wait for collection add
var deferred = Zotero.Promise.defer();
@ -1187,7 +1187,7 @@ describe("Zotero.CollectionTree", function() {
}
}, 'collection', 'test');
yield onDrop(
await onDrop(
'collection',
{
row: colIndexE,
@ -1216,17 +1216,20 @@ describe("Zotero.CollectionTree", function() {
assert.equal(newColIndexG, newColIndexH - 1);
// TODO: Check deeper subcollection open states
})
});
it("should move a subcollection and its subcollection up under another collection", async function () {
var collectionA = await createDataObject('collection', { name: "A" });
var collectionB = await createDataObject('collection', { name: "B", parentKey: collectionA.key });
var collectionC = await createDataObject('collection', { name: "C", parentKey: collectionB.key });
var collectionD = await createDataObject('collection', { name: "D" });
var collectionE = await createDataObject('collection', { name: "E" });
var collectionF = await createDataObject('collection', { name: "F" });
var collectionG = await createDataObject('collection', { name: "G", parentKey: collectionE.key });
var collectionH = await createDataObject('collection', { name: "H", parentKey: collectionG.key });
it("should move a subcollection and its subcollection up under another collection", function* () {
var collectionA = yield createDataObject('collection', { name: "A" }, { skipSelect: true });
var collectionB = yield createDataObject('collection', { name: "B", parentKey: collectionA.key });
var collectionC = yield createDataObject('collection', { name: "C", parentKey: collectionB.key });
var collectionD = yield createDataObject('collection', { name: "D" }, { skipSelect: true });
var collectionE = yield createDataObject('collection', { name: "E" }, { skipSelect: true });
var collectionF = yield createDataObject('collection', { name: "F" }, { skipSelect: true });
var collectionG = yield createDataObject('collection', { name: "G", parentKey: collectionE.key });
var collectionH = yield createDataObject('collection', { name: "H", parentKey: collectionG.key });
await cv.expandToCollection(collectionC.id);
await cv.expandToCollection(collectionH.id);
var colIndexA = cv.getRowIndexByID('C' + collectionA.id);
var colIndexB = cv.getRowIndexByID('C' + collectionB.id);
@ -1237,7 +1240,7 @@ describe("Zotero.CollectionTree", function() {
var colIndexG = cv.getRowIndexByID('C' + collectionG.id);
var colIndexH = cv.getRowIndexByID('C' + collectionH.id);
yield cv.selectCollection(collectionG.id);
await cv.selectCollection(collectionG.id);
// Add observer to wait for collection add
var deferred = Zotero.Promise.defer();
@ -1251,7 +1254,7 @@ describe("Zotero.CollectionTree", function() {
}
}, 'collection', 'test');
yield onDrop(
await onDrop(
'collection',
{
row: colIndexD,
@ -1280,12 +1283,12 @@ describe("Zotero.CollectionTree", function() {
assert.equal(newColIndexG, newColIndexH - 1);
// TODO: Check deeper subcollection open states
})
});
it("should copy a collection and its subcollection to another library", async function () {
var group = await createGroup();
var collectionA = await createDataObject('collection', { name: "A" }, { skipSelect: true });
var collectionA = await createDataObject('collection', { name: "A" });
var collectionB = await createDataObject('collection', { name: "B", parentKey: collectionA.key });
var itemA = await createDataObject('item', { collections: [collectionA.key] }, { skipSelect: true });
var itemB = await createDataObject('item', { collections: [collectionB.key] }, { skipSelect: true });
@ -1338,8 +1341,7 @@ describe("Zotero.CollectionTree", function() {
var group2 = await createGroup();
await cv.selectCollection(collection.id);
await waitForItemsLoad(win);
await select(win, collection);
await onDrop('collection', 'L' + group2.libraryID, [collection.id]);
@ -1403,8 +1405,7 @@ describe("Zotero.CollectionTree", function() {
assert.equal(item.id, ids[0]);
});
yield cv.selectCollection(collection.id);
yield waitForItemsLoad(win);
yield select(win, collection);
var itemsView = win.ZoteroPane.itemsView;
assert.equal(itemsView.rowCount, 1);

View file

@ -45,12 +45,13 @@ describe("Zotero_File_Interface", function() {
it("should import RIS into selected collection", async function () {
var collection = await createDataObject('collection');
var collection = await createDataObject('collection');
await selectCollection(win, collection);
var testFile = OS.Path.join(getTestDataDirectory().path, 'book_and_child_note.ris');
await win.Zotero_File_Interface.importFile({
file: testFile,
createNewCollection: false
file: testFile,
createNewCollection: false
});
var items = collection.getChildItems();

View file

@ -461,7 +461,7 @@ describe("Zotero.ItemTree", function() {
it("should reselect the same row when an item is removed", function* () {
var collection = yield createDataObject('collection');
yield waitForItemsLoad(win);
yield selectCollection(win, collection);
itemsView = zp.itemsView;
var items = [];
@ -559,7 +559,7 @@ describe("Zotero.ItemTree", function() {
it.skip("should keep first visible selected item in position when other items are added with skipSelect", function* () {
var collection = yield createDataObject('collection');
yield waitForItemsLoad(win);
yield select(win, collection);
itemsView = zp.itemsView;
var treebox = itemsView._treebox;
@ -615,7 +615,7 @@ describe("Zotero.ItemTree", function() {
it("shouldn't scroll items list if at top when other items are added with skipSelect", function* () {
var collection = yield createDataObject('collection');
yield waitForItemsLoad(win);
yield select(win, collection);
itemsView = zp.itemsView;
var treebox = itemsView._treebox;
@ -663,23 +663,24 @@ describe("Zotero.ItemTree", function() {
assert.equal(treebox.getFirstVisibleRow(), 0);
});
it("should update search results when items are added", function* () {
var search = yield createDataObject('search');
var title = search.getConditions()[0].value;
yield waitForItemsLoad(win);
it("should update search results when items are added", async function () {
var search = await createDataObject('search');
await select(win, search);
assert.equal(zp.itemsView.rowCount, 0);
// Add an item matching search
var item = yield createDataObject('item', { title });
var title = search.getConditions()[0].value;
yield waitForItemsLoad(win);
// Add an item matching search
var item = await createDataObject('item', { title });
await waitForItemsLoad(win);
assert.equal(zp.itemsView.rowCount, 1);
assert.equal(zp.itemsView.getRowIndexByID(item.id), 0);
});
it("should re-sort search results when an item is modified", async function () {
var search = await createDataObject('search');
await select(win, search);
itemsView = zp.itemsView;
var title = search.getConditions()[0].value;
@ -726,7 +727,7 @@ describe("Zotero.ItemTree", function() {
});
yield search.saveTx();
yield waitForItemsLoad(win);
yield select(win, search);
// Add an item that doesn't match search
var item = yield createDataObject('item', { title: title2 });

View file

@ -18,21 +18,21 @@ describe("Zotero.LibraryTree", function() {
});
describe("#getRowIndexByID()", function () {
it("should return the row index of an item", function* () {
var collection = yield createDataObject('collection');
yield waitForItemsLoad(win);
var item = yield createDataObject('item', { collections: [collection.id] });
it("should return the row index of an item", async function () {
var collection = await createDataObject('collection');
await select(win, collection);
var item = await createDataObject('item', { collections: [collection.id] });
var view = zp.itemsView;
assert.strictEqual(view.getRowIndexByID(item.treeViewID), 0);
});
});
describe("#_removeRow()", function () {
it("should remove the last row", function* () {
var collection = yield createDataObject('collection');
yield waitForItemsLoad(win);
yield createDataObject('item', { collections: [collection.id] });
yield createDataObject('item', { collections: [collection.id] });
it("should remove the last row", async function () {
var collection = await createDataObject('collection');
await select(win, collection);
await createDataObject('item', { collections: [collection.id] });
await createDataObject('item', { collections: [collection.id] });
var view = zp.itemsView;
var treeViewID = view.getRow(1).id;

View file

@ -66,7 +66,7 @@ describe("Add Item by Identifier", function() {
this.timeout(20000);
var col = yield createDataObject('collection');
yield waitForItemsLoad(win);
yield select(win, col);
// Initial translator
var ids = yield lookupIdentifier(win, "10.4103/0976-500X.85940");

View file

@ -42,11 +42,7 @@ describe("Document Recognition", function() {
// Import the PDF
var testdir = getTestDataDirectory();
testdir.append("recognizePDF_test_DOI.pdf");
var collection = await createDataObject('collection');
var attachment = await Zotero.Attachments.importFromFile({
file: testdir,
collections: [collection.id]
});
var attachment = await Zotero.Attachments.importFromFile({ file: testdir });
win.ZoteroPane.recognizeSelected();
@ -78,9 +74,7 @@ describe("Document Recognition", function() {
// Import the PDF
var testdir = getTestDataDirectory();
testdir.append("recognizePDF_test_arXiv.pdf");
var attachment = await Zotero.Attachments.importFromFile({
file: testdir
});
var attachment = await Zotero.Attachments.importFromFile({ file: testdir });
// Recognize the PDF
win.ZoteroPane.recognizeSelected();
@ -108,6 +102,7 @@ describe("Document Recognition", function() {
var testdir = getTestDataDirectory();
testdir.append("recognizePDF_test_arXiv.pdf");
var collection = await createDataObject('collection');
await select(win, collection);
var attachment = await Zotero.Attachments.importFromFile({
file: testdir,
collections: [collection.id]
@ -139,6 +134,7 @@ describe("Document Recognition", function() {
testdir.append("recognizePDF_test_arXiv.pdf");
var group = await getGroup();
var collection = await createDataObject('collection', { libraryID: group.libraryID });
await select(win, collection);
var attachment = await Zotero.Attachments.importFromFile({
libraryID: group.libraryID,
file: testdir,
@ -171,6 +167,7 @@ describe("Document Recognition", function() {
testdir.append("recognizePDF_test_ISBN.pdf");
var group = await getGroup();
var collection = await createDataObject('collection', { libraryID: group.libraryID });
await select(win, collection);
var attachment = await Zotero.Attachments.importFromFile({
libraryID: group.libraryID,
file: testdir,
@ -202,6 +199,7 @@ describe("Document Recognition", function() {
testdir.append("recognizePDF_test_title.pdf");
var group = await getGroup();
var collection = await createDataObject('collection', { libraryID: group.libraryID });
await select(win, collection);
var attachment = await Zotero.Attachments.importFromFile({
libraryID: group.libraryID,
file: testdir,
@ -318,11 +316,7 @@ describe("Document Recognition", function() {
let testDir = getTestDataDirectory();
testDir.append('recognizeEPUB_test_ISBN.epub');
let collection = await createDataObject('collection');
let attachment = await Zotero.Attachments.importFromFile({
file: testDir,
collections: [collection.id]
});
let attachment = await Zotero.Attachments.importFromFile({ file: testDir });
win.ZoteroPane.recognizeSelected();
@ -356,11 +350,7 @@ describe("Document Recognition", function() {
it("should recognize an EPUB without an ISBN and rename the file", async function () {
let testDir = getTestDataDirectory();
testDir.append('recognizeEPUB_test_DC.epub');
let collection = await createDataObject('collection');
let attachment = await Zotero.Attachments.importFromFile({
file: testDir,
collections: [collection.id]
});
let attachment = await Zotero.Attachments.importFromFile({ file: testDir });
win.ZoteroPane.recognizeSelected();
@ -405,11 +395,7 @@ describe("Document Recognition", function() {
let testDir = getTestDataDirectory();
testDir.append('recognizeEPUB_test_ISBN.epub');
let collection = await createDataObject('collection');
await Zotero.Attachments.importFromFile({
file: testDir,
collections: [collection.id]
});
await Zotero.Attachments.importFromFile({ file: testDir });
win.ZoteroPane.recognizeSelected();
@ -438,11 +424,7 @@ describe("Document Recognition", function() {
let testDir = getTestDataDirectory();
testDir.append('recognizeEPUB_test_ISBN.epub');
let collection = await createDataObject('collection');
let attachment = await Zotero.Attachments.importFromFile({
file: testDir,
collections: [collection.id]
});
let attachment = await Zotero.Attachments.importFromFile({ file: testDir });
win.ZoteroPane.recognizeSelected();
@ -478,11 +460,7 @@ describe("Document Recognition", function() {
let testDir = getTestDataDirectory();
testDir.append('recognizeEPUB_test_copyright_page.epub');
let collection = await createDataObject('collection');
await Zotero.Attachments.importFromFile({
file: testDir,
collections: [collection.id]
});
await Zotero.Attachments.importFromFile({ file: testDir });
win.ZoteroPane.recognizeSelected();
@ -519,11 +497,7 @@ describe("Document Recognition", function() {
let testDir = getTestDataDirectory();
testDir.append('recognizeEPUB_test_content.epub');
let collection = await createDataObject('collection');
await Zotero.Attachments.importFromFile({
file: testDir,
collections: [collection.id]
});
await Zotero.Attachments.importFromFile({ file: testDir });
win.ZoteroPane.recognizeSelected();

View file

@ -107,7 +107,7 @@ describe("Connector Server", function () {
// TODO: Test cookies
it("should save a translated item to the current selected collection", function* () {
var collection = yield createDataObject('collection');
yield waitForItemsLoad(win);
yield select(win, collection);
var body = {
items: [
@ -178,8 +178,7 @@ describe("Connector Server", function () {
var group = yield createGroup({
editable: false
});
yield selectLibrary(win, group.libraryID);
yield waitForItemsLoad(win);
yield select(win, group);
var body = {
items: [
@ -370,7 +369,7 @@ describe("Connector Server", function () {
it("should download a translated PDF", async function () {
var collection = await createDataObject('collection');
await waitForItemsLoad(win);
await select(win, collection);
var sessionID = Zotero.Utilities.randomString();
@ -513,7 +512,7 @@ describe("Connector Server", function () {
it("should download open-access PDF if no PDF provided", async function () {
var collection = await createDataObject('collection');
await waitForItemsLoad(win);
await select(win, collection);
var sessionID = Zotero.Utilities.randomString();
@ -605,7 +604,7 @@ describe("Connector Server", function () {
it("should download open-access PDF if a translated PDF fails", async function () {
var collection = await createDataObject('collection');
await waitForItemsLoad(win);
await select(win, collection);
var sessionID = Zotero.Utilities.randomString();
@ -761,7 +760,7 @@ describe("Connector Server", function () {
describe("/connector/saveSingleFile", function () {
it("should save a webpage item with /saveSnapshot", async function () {
var collection = await createDataObject('collection');
await waitForItemsLoad(win);
await select(win, collection);
// Promise for item save
let promise = waitForItemEvent('add');
@ -837,7 +836,7 @@ describe("Connector Server", function () {
it("should save a webpage item with /saveItems", async function () {
let collection = await createDataObject('collection');
await waitForItemsLoad(win);
await select(win, collection);
let title = Zotero.Utilities.randomString();
let sessionID = Zotero.Utilities.randomString();
@ -930,7 +929,7 @@ describe("Connector Server", function () {
it("should override SingleFileZ from old connector in /saveSnapshot", async function () {
Components.utils.import("resource://gre/modules/FileUtils.jsm");
var collection = await createDataObject('collection');
await waitForItemsLoad(win);
await select(win, collection);
// Promise for item save
let promise = waitForItemEvent('add');
@ -1023,7 +1022,7 @@ describe("Connector Server", function () {
it("should override SingleFileZ from old connector in /saveItems", async function () {
let collection = await createDataObject('collection');
await waitForItemsLoad(win);
await select(win, collection);
let prefix = '/' + Zotero.Utilities.randomString() + '/';
let uri = OS.Path.join(getTestDataDirectory().path, 'snapshot');
@ -1132,7 +1131,7 @@ describe("Connector Server", function () {
it("should handle race condition with /saveItems", async function () {
let collection = await createDataObject('collection');
await waitForItemsLoad(win);
await select(win, collection);
let pdfURL = testServerPath + '/pdf';
let nonOADOI = '10.2222/bcde';
@ -1296,7 +1295,7 @@ describe("Connector Server", function () {
describe("/connector/saveSnapshot", function () {
it("should save a webpage item and snapshot to the current selected collection", function* () {
var collection = yield createDataObject('collection');
yield waitForItemsLoad(win);
yield select(win, collection);
// saveSnapshot saves parent and child before returning
var ids1, ids2;
@ -1344,7 +1343,7 @@ describe("Connector Server", function () {
it("should save a PDF to the current selected collection and retrieve metadata", async function () {
var collection = await createDataObject('collection');
await waitForItemsLoad(win);
await select(win, collection);
var file = getTestDataDirectory();
file.append('test.pdf');
@ -1408,8 +1407,7 @@ describe("Connector Server", function () {
var group = yield createGroup({
editable: false
});
yield selectLibrary(win, group.libraryID);
yield waitForItemsLoad(win);
yield select(win, group);
var promise = waitForItemEvent('add');
var reqPromise = Zotero.HTTP.request(
@ -1497,7 +1495,7 @@ describe("Connector Server", function () {
it("should update collections and tags of item saved via /saveItems", async function () {
var collection1 = await createDataObject('collection');
var collection2 = await createDataObject('collection');
await waitForItemsLoad(win);
await select(win, collection2);
var sessionID = Zotero.Utilities.randomString();
var body = {
@ -1581,7 +1579,7 @@ describe("Connector Server", function () {
var collection1 = await createDataObject('collection');
var collection2 = await createDataObject('collection');
await waitForItemsLoad(win);
await select(win, collection2);
var file = getTestDataDirectory();
file.append('test.pdf');
@ -1637,7 +1635,7 @@ describe("Connector Server", function () {
var collection1 = await createDataObject('collection');
var collection2 = await createDataObject('collection');
await waitForItemsLoad(win);
await select(win, collection2);
// saveSnapshot saves parent and child before returning
var ids1, ids2;
@ -2585,9 +2583,9 @@ describe("Connector Server", function () {
assert.equal(req.status, 403);
});
it('should import resources (BibTeX) into selected collection', function* () {
var collection = yield createDataObject('collection');
yield waitForItemsLoad(win);
it('should import resources (BibTeX) into selected collection', async function () {
var collection = await createDataObject('collection');
await select(win, collection);
var resource = `@book{test1,
title={Test1},
@ -2598,7 +2596,7 @@ describe("Connector Server", function () {
}`;
var addedItemIDsPromise = waitForItemEvent('add');
var req = yield Zotero.HTTP.request(
var req = await Zotero.HTTP.request(
'POST',
endpoint,
{
@ -2612,19 +2610,18 @@ describe("Connector Server", function () {
assert.equal(req.status, 201);
assert.equal(JSON.parse(req.responseText)[0].title, 'Test1');
let itemIDs = yield addedItemIDsPromise;
let itemIDs = await addedItemIDsPromise;
assert.isTrue(collection.hasItem(itemIDs[0]));
var item = Zotero.Items.get(itemIDs[0]);
assert.sameDeepMembers(item.getTags(), [{ tag: 'A', type: 1 }, { tag: 'B', type: 1 }]);
});
it('should switch to My Library if read-only library is selected', function* () {
var group = yield createGroup({
it('should switch to My Library if read-only library is selected', async function () {
var group = await createGroup({
editable: false
});
yield selectLibrary(win, group.libraryID);
yield waitForItemsLoad(win);
await select(win, group);
var resource = `@book{test1,
title={Test1},
@ -2634,7 +2631,7 @@ describe("Connector Server", function () {
}`;
var addedItemIDsPromise = waitForItemEvent('add');
var req = yield Zotero.HTTP.request(
var req = await Zotero.HTTP.request(
'POST',
endpoint,
{
@ -2653,7 +2650,7 @@ describe("Connector Server", function () {
Zotero.Libraries.userLibraryID
);
let itemIDs = yield addedItemIDsPromise;
let itemIDs = await addedItemIDsPromise;
var item = Zotero.Items.get(itemIDs[0]);
assert.equal(item.libraryID, Zotero.Libraries.userLibraryID);
});

View file

@ -60,6 +60,7 @@ describe("Tag Selector", function () {
it("should sort colored tags by assigned number key", async function () {
var collection = await createDataObject('collection');
await select(win, collection);
await Zotero.Tags.setColor(libraryID, "B", '#AAAAAA', 1);
await Zotero.Tags.setColor(libraryID, "A", '#BBBBBB', 2);
@ -77,6 +78,7 @@ describe("Tag Selector", function () {
it('should not display duplicate tags when automatic and manual tag with same name exists', async function () {
var collection = await createDataObject('collection');
await select(win, collection);
var item1 = createUnsavedDataObject('item', { collections: [collection.id] });
item1.setTags([{
tag: "A",
@ -97,6 +99,7 @@ describe("Tag Selector", function () {
it("should show tags from annotations for attachments in scope", async function () {
var collection = await createDataObject('collection');
await select(win, collection);
var item = await createDataObject('item', { collections: [collection.id] });
var attachment = await importPDFAttachment(item);
var annotation = await createAnnotation('highlight', attachment);
@ -113,6 +116,7 @@ describe("Tag Selector", function () {
describe("#handleSearch()", function () {
it("should filter to tags matching the search", function* () {
var collection = yield createDataObject('collection');
yield select(win, collection);
var item = createUnsavedDataObject('item', { collections: [collection.id] });
item.setTags(['a', 'b', 'c']);
var promise = waitForTagSelector(win);
@ -138,6 +142,7 @@ describe("Tag Selector", function () {
describe("#handleTagSelected()", function () {
it("should remove tags not on matching items on tag click", function* () {
var collection = yield createDataObject('collection');
yield select(win, collection);
var item1 = createUnsavedDataObject('item', { collections: [collection.id] });
item1.setTags([
{
@ -185,6 +190,7 @@ describe("Tag Selector", function () {
var tag3 = 'C ' + Zotero.Utilities.randomString();
var collection = yield createDataObject('collection');
yield select(win, collection);
var item1 = createUnsavedDataObject('item');
item1.setTags([tag1]);
var item2 = createUnsavedDataObject('item', { collections: [collection.id] });
@ -264,6 +270,7 @@ describe("Tag Selector", function () {
// Add collection
promise = waitForTagSelector(win);
var collection = yield createDataObject('collection');
yield select(win, collection);
yield promise;
// Tag selector should be empty in new collection
@ -293,6 +300,7 @@ describe("Tag Selector", function () {
// Add collection
var promise = waitForTagSelector(win);
var collection = await createDataObject('collection');
await select(win, collection);
await promise;
var elems = getColoredTagElements();
@ -396,6 +404,7 @@ describe("Tag Selector", function () {
// Add collection
promise = waitForTagSelector(win);
var collection = yield createDataObject('collection');
yield select(win, collection);
yield promise;
// Tag selector should be empty in new collection
@ -464,6 +473,7 @@ describe("Tag Selector", function () {
// Add collection
var promise = waitForTagSelector(win);
var collection = yield createDataObject('collection');
yield select(win, collection);
yield promise;
// Add item with tag to collection
@ -494,6 +504,7 @@ describe("Tag Selector", function () {
// Add collection
var promise = waitForTagSelector(win);
var collection = yield createDataObject('collection');
yield select(win, collection);
yield promise;
// Add item with tag to collection
@ -533,6 +544,7 @@ describe("Tag Selector", function () {
promise = waitForTagSelector(win);
var collection = await createDataObject('collection');
await select(win, collection);
await promise;
// Add item with tag to collection

View file

@ -71,6 +71,7 @@ describe("ZoteroPane", function() {
it("should create a standalone note within a collection and select it", function* () {
var collection = yield createDataObject('collection');
yield selectCollection(win, collection);
var noteID = yield zp.newNote(false, false, "Test");
assert.equal(zp.collectionsView.getSelectedCollection(), collection);
var selected = zp.itemsView.getSelectedItems(true);
@ -460,6 +461,7 @@ describe("ZoteroPane", function() {
describe("#createStandaloneNoteFromAnnotationsFromSelected()", function () {
it("should create a single standalone note for all child attachments of selected regular items", async function () {
var collection = await createDataObject('collection');
await selectCollection(win, collection);
var item1 = await createDataObject('item', { setTitle: true, collections: [collection.id] });
var item2 = await createDataObject('item', { setTitle: true, collections: [collection.id] });
var attachment1 = await importPDFAttachment(item1);
@ -503,6 +505,7 @@ describe("ZoteroPane", function() {
it("should create a single standalone note for all selected attachments", async function () {
var collection = await createDataObject('collection');
await selectCollection(win, collection);
var item1 = await createDataObject('item', { setTitle: true, collections: [collection.id] });
var item2 = await createDataObject('item', { setTitle: true, collections: [collection.id] });
var attachment1 = await importPDFAttachment(item1);
@ -846,7 +849,7 @@ describe("ZoteroPane", function() {
.filter(x => x.condition == 'title' && x.operator == 'contains')[0].value;
var item = await createDataObject('item', { title });
await waitForItemsLoad(win);
await selectSearch(win, search);
var iv = zp.itemsView;
var selected = iv.selectItem(item.id);
@ -883,7 +886,7 @@ describe("ZoteroPane", function() {
.filter(x => x.condition == 'title' && x.operator == 'contains')[0].value;
var item = await createDataObject('item', { title });
await waitForItemsLoad(win);
await selectSearch(win, search);
var iv = zp.itemsView;
var selected = iv.selectItem(item.id);
@ -920,10 +923,8 @@ describe("ZoteroPane", function() {
let collection1 = await createDataObject('collection');
let collection2 = await createDataObject('collection', { parentID: collection1.id });
let item = await createDataObject('item', { collections: [collection2.id] });
assert.ok(await zp.collectionsView.selectCollection(collection1.id));
await waitForItemsLoad(win);
await selectCollection(win, collection1);
let iv = zp.itemsView;
assert.ok(await iv.selectItem(item.id));
@ -947,6 +948,7 @@ describe("ZoteroPane", function() {
describe("#deleteSelectedCollection()", function () {
it("should move collection to trash but not descendant items by default", function* () {
var collection = yield createDataObject('collection');
yield selectCollection(win, collection);
var item = yield createDataObject('item', { collections: [collection.id] });
var promise = waitForDialog();
yield zp.deleteSelectedCollection();
@ -957,6 +959,7 @@ describe("ZoteroPane", function() {
it("should move to trash collection and descendant items when deleteItems=true", function* () {
var collection = yield createDataObject('collection');
yield selectCollection(win, collection);
var item = yield createDataObject('item', { collections: [collection.id] });
var promise = waitForDialog();
yield zp.deleteSelectedCollection(true);
@ -1112,6 +1115,7 @@ describe("ZoteroPane", function() {
describe("#editSelectedCollection()", function () {
it("should edit a saved search", function* () {
var search = yield createDataObject('search');
yield selectSearch(win, search);
var promise = waitForWindow('chrome://zotero/content/searchDialog.xhtml', function (win) {
let searchBox = win.document.getElementById('search-box');
var c = searchBox.search.getCondition(
@ -1129,6 +1133,7 @@ describe("ZoteroPane", function() {
it("should edit a saved search in a group", function* () {
var group = yield getGroup();
var search = yield createDataObject('search', { libraryID: group.libraryID });
yield selectSearch(win, search);
var promise = waitForWindow('chrome://zotero/content/searchDialog.xhtml', function (win) {
let searchBox = win.document.getElementById('search-box');
var c = searchBox.search.getCondition(