Test for tag selector search

This commit is contained in:
Dan Stillman 2017-07-20 18:24:51 -04:00
parent 80c70d9bff
commit 316a6f91b2

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
describe("Tag Selector", function () { describe("Tag Selector", function () {
var win, doc, collectionsView; var win, doc, collectionsView, tagSelector;
var clearTagColors = Zotero.Promise.coroutine(function* (libraryID) { var clearTagColors = Zotero.Promise.coroutine(function* (libraryID) {
var tagColors = Zotero.Tags.getColors(libraryID); var tagColors = Zotero.Tags.getColors(libraryID);
@ -11,7 +11,6 @@ describe("Tag Selector", function () {
}); });
function getColoredTags() { function getColoredTags() {
var tagSelector = doc.getElementById('zotero-tag-selector');
var tagsBox = tagSelector.id('tags-box'); var tagsBox = tagSelector.id('tags-box');
var elems = tagsBox.getElementsByTagName('button'); var elems = tagsBox.getElementsByTagName('button');
var names = []; var names = [];
@ -24,7 +23,6 @@ describe("Tag Selector", function () {
} }
function getRegularTags() { function getRegularTags() {
var tagSelector = doc.getElementById('zotero-tag-selector');
var tagsBox = tagSelector.id('tags-box'); var tagsBox = tagSelector.id('tags-box');
var elems = tagsBox.getElementsByTagName('button'); var elems = tagsBox.getElementsByTagName('button');
var names = []; var names = [];
@ -41,22 +39,47 @@ describe("Tag Selector", function () {
win = yield loadZoteroPane(); win = yield loadZoteroPane();
doc = win.document; doc = win.document;
collectionsView = win.ZoteroPane.collectionsView; collectionsView = win.ZoteroPane.collectionsView;
tagSelector = doc.getElementById('zotero-tag-selector');
// Wait for things to settle // Wait for things to settle
yield Zotero.Promise.delay(100); yield Zotero.Promise.delay(100);
}); });
beforeEach(function* () { beforeEach(function* () {
var libraryID = Zotero.Libraries.userLibraryID; var libraryID = Zotero.Libraries.userLibraryID;
yield clearTagColors(libraryID); yield clearTagColors(libraryID);
var tagSelector = doc.getElementById('zotero-tag-selector');
// Default "Display All Tags in This Library" off // Default "Display All Tags in This Library" off
tagSelector.filterToScope = true; tagSelector.filterToScope = true;
tagSelector.setSearch('');
yield tagSelector.refresh(true); yield tagSelector.refresh(true);
}) })
after(function () { after(function () {
win.close(); win.close();
}); });
describe("#setSearch()", function () {
it("should filter to tags matching the search", function* () {
var collection = yield createDataObject('collection');
var item = createUnsavedDataObject('item', { collections: [collection.id] });
item.setTags(['a', 'b', 'c']);
var promise = waitForTagSelector(win);
yield item.saveTx();
yield promise;
var tagsSearch = doc.getElementById('tags-search');
tagsSearch.value = 'a';
tagsSearch.doCommand();
var tags = getRegularTags();
assert.sameMembers(tags, ['a']);
tagsSearch.value = '';
tagsSearch.doCommand();
yield item.eraseTx();
});
});
describe("#refresh()", function () { describe("#refresh()", function () {
it("should remove tags not on matching items on tag click", function* () { it("should remove tags not on matching items on tag click", function* () {
var collection = yield createDataObject('collection'); var collection = yield createDataObject('collection');
@ -89,7 +112,6 @@ describe("Tag Selector", function () {
}); });
yield promise; yield promise;
var tagSelector = doc.getElementById('zotero-tag-selector');
var buttons = tagSelector.id('tags-box').getElementsByTagName('button'); var buttons = tagSelector.id('tags-box').getElementsByTagName('button');
var spy = sinon.spy(win.ZoteroPane, "updateTagFilter"); var spy = sinon.spy(win.ZoteroPane, "updateTagFilter");
buttons[0].click(); buttons[0].click();
@ -106,7 +128,6 @@ describe("Tag Selector", function () {
describe("#filterToScope", function () { describe("#filterToScope", function () {
it("should show all tags in library when false", function* () { it("should show all tags in library when false", function* () {
var tagSelector = doc.getElementById('zotero-tag-selector');
tagSelector.filterToScope = false; tagSelector.filterToScope = false;
var collection = yield createDataObject('collection'); var collection = yield createDataObject('collection');
@ -229,14 +250,12 @@ describe("Tag Selector", function () {
yield promise; yield promise;
// Tag selector should show the new item's tag // Tag selector should show the new item's tag
tagSelector = doc.getElementById('zotero-tag-selector');
assert.equal(getRegularTags().length, 1); assert.equal(getRegularTags().length, 1);
}) })
it("should show a colored tag at the top of the list even when linked to no items", function* () { it("should show a colored tag at the top of the list even when linked to no items", function* () {
var libraryID = Zotero.Libraries.userLibraryID; var libraryID = Zotero.Libraries.userLibraryID;
var tagSelector = doc.getElementById('zotero-tag-selector');
var tagElems = tagSelector.id('tags-box').getElementsByTagName('button'); var tagElems = tagSelector.id('tags-box').getElementsByTagName('button');
var count = tagElems.length; var count = tagElems.length;
@ -270,7 +289,6 @@ describe("Tag Selector", function () {
yield item.saveTx(); yield item.saveTx();
yield promise; yield promise;
var tagSelector = doc.getElementById('zotero-tag-selector');
var tagElems = tagSelector.id('tags-box').getElementsByTagName('button'); var tagElems = tagSelector.id('tags-box').getElementsByTagName('button');
// Make sure the colored tags are still in the right position // Make sure the colored tags are still in the right position
@ -362,7 +380,6 @@ describe("Tag Selector", function () {
// Remove tag from library // Remove tag from library
promise = waitForTagSelector(win); promise = waitForTagSelector(win);
var dialogPromise = waitForDialog(); var dialogPromise = waitForDialog();
var tagSelector = doc.getElementById('zotero-tag-selector');
yield tagSelector.deleteTag("A"); yield tagSelector.deleteTag("A");
yield promise; yield promise;
@ -387,7 +404,6 @@ describe("Tag Selector", function () {
yield item.saveTx(); yield item.saveTx();
yield promise; yield promise;
var tagSelector = doc.getElementById('zotero-tag-selector');
promise = waitForTagSelector(win); promise = waitForTagSelector(win);
var promptPromise = waitForWindow("chrome://global/content/commonDialog.xul", function (dialog) { var promptPromise = waitForWindow("chrome://global/content/commonDialog.xul", function (dialog) {
dialog.document.getElementById('loginTextbox').value = newTag; dialog.document.getElementById('loginTextbox').value = newTag;
@ -411,7 +427,6 @@ describe("Tag Selector", function () {
yield Zotero.Tags.setColor(libraryID, oldTag, "#F3F3F3"); yield Zotero.Tags.setColor(libraryID, oldTag, "#F3F3F3");
yield promise; yield promise;
var tagSelector = doc.getElementById('zotero-tag-selector');
promise = waitForTagSelector(win); promise = waitForTagSelector(win);
var promptPromise = waitForWindow("chrome://global/content/commonDialog.xul", function (dialog) { var promptPromise = waitForWindow("chrome://global/content/commonDialog.xul", function (dialog) {
dialog.document.getElementById('loginTextbox').value = newTag; dialog.document.getElementById('loginTextbox').value = newTag;
@ -443,7 +458,6 @@ describe("Tag Selector", function () {
yield item.saveTx(); yield item.saveTx();
yield promise; yield promise;
var tagSelector = doc.getElementById('zotero-tag-selector');
assert.include(getRegularTags(), "a"); assert.include(getRegularTags(), "a");