Tests: Add additional convenience functions for object selection
Objects can now be selected in the UI with just `await select(win, obj)`
This commit is contained in:
parent
6757c586ea
commit
42d4064bac
1 changed files with 36 additions and 3 deletions
|
@ -260,11 +260,44 @@ function waitForDialog(onOpen, button='accept', url) {
|
|||
}))
|
||||
}
|
||||
|
||||
var selectLibrary = Zotero.Promise.coroutine(function* (win, libraryID) {
|
||||
libraryID = libraryID || Zotero.Libraries.userLibraryID;
|
||||
async function select(win, object) {
|
||||
if (object instanceof Zotero.Library) {
|
||||
return selectLibrary(win, object);
|
||||
}
|
||||
if (object instanceof Zotero.Collection) {
|
||||
return selectCollection(win, object);
|
||||
}
|
||||
if (object instanceof Zotero.Search) {
|
||||
return selectSearch(win, object);
|
||||
}
|
||||
if (object instanceof Zotero.Item) {
|
||||
return win.ZoteroPane.itemsView.selectItem(object.id);
|
||||
}
|
||||
throw new Error("Unknown object");
|
||||
}
|
||||
|
||||
async function selectLibrary(win, libraryOrID = Zotero.Libraries.userLibraryID) {
|
||||
var libraryID = libraryOrID instanceof Zotero.Library ? libraryOrID.libraryID : libraryOrID;
|
||||
yield win.ZoteroPane.collectionsView.selectLibrary(libraryID);
|
||||
yield waitForItemsLoad(win);
|
||||
});
|
||||
}
|
||||
|
||||
async function selectCollection(win, collectionOrID) {
|
||||
var collectionID = collectionOrID instanceof Zotero.Collection ? collectionOrID.id : collectionOrID;
|
||||
await win.ZoteroPane.collectionsView.selectCollection(collectionID);
|
||||
await waitForItemsLoad(win);
|
||||
}
|
||||
|
||||
async function selectSearch(win, searchOrID) {
|
||||
var searchID = searchOrID instanceof Zotero.Search ? searchOrID.id : searchOrID;
|
||||
await win.ZoteroPane.collectionsView.selectSearch(searchID);
|
||||
await waitForItemsLoad(win);
|
||||
}
|
||||
|
||||
async function selectTrash(win, libraryID = Zotero.Libraries.userLibraryID) {
|
||||
await win.ZoteroPane.collectionsView.selectTrash(libraryID);
|
||||
await waitForItemsLoad(win);
|
||||
}
|
||||
|
||||
var waitForItemsLoad = Zotero.Promise.coroutine(function* (win, collectionRowToSelect) {
|
||||
var zp = win.ZoteroPane;
|
||||
|
|
Loading…
Reference in a new issue