Beginning of tests for zotero://select

This commit is contained in:
Dan Stillman 2019-08-02 02:28:43 -04:00
parent d0002736cd
commit fda002ec34
2 changed files with 47 additions and 1 deletions

View file

@ -36,7 +36,7 @@ Zotero.API = {
/**
* @return {(Zotero.Collection|Zotero.Item)[]}
* @return {(Zotero.Collection|Zotero.Search|Zotero.Item)[]}
*/
getResultsFromParams: Zotero.Promise.coroutine(function* (params) {
if (!params.objectType) {

View file

@ -0,0 +1,46 @@
function runHandler(url) {
var [_, extension] = url.match(/^zotero:\/\/([a-z]+)\//);
var handler = Services.io.getProtocolHandler('zotero').wrappedJSObject;
var uri = Services.io.newURI(url, null, null);
return handler._extensions['zotero://' + extension].newChannel(uri);
}
describe("Protocol Handler", function () {
var win;
var zp;
before(async function () {
win = await loadZoteroPane();
zp = win.ZoteroPane;
});
describe("zotero://select", function () {
async function waitForItemSelect(items) {
if (items instanceof Zotero.Item) {
items = [items];
}
while (true) {
let selected = zp.getSelectedItems();
if (selected.every(item => items.includes(item))) {
return;
}
await Zotero.Promise.delay(20);
}
}
it("should select an item", async function () {
var item1 = await createDataObject('item', { title: 'A' });
var item2 = await createDataObject('item', { title: 'B' });
runHandler(`zotero://select/library/items/${item1.key}`);
await waitForItemSelect(item1);
});
it("should select multiple items", async function () {
var item1 = await createDataObject('item', { title: 'A' });
var item2 = await createDataObject('item', { title: 'B' });
var item3 = await createDataObject('item', { title: 'C' });
runHandler(`zotero://select/library/items?itemKey=${item1.key},${item2.key}`);
await waitForItemSelect([item1, item2]);
});
});
});