Skip to content

Commit

Permalink
Test for tag selector search
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Jul 20, 2017
1 parent 80c70d9 commit 316a6f9
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions test/tests/tagSelectorTest.js
@@ -1,7 +1,7 @@
"use strict";

describe("Tag Selector", function () {
var win, doc, collectionsView;
var win, doc, collectionsView, tagSelector;

var clearTagColors = Zotero.Promise.coroutine(function* (libraryID) {
var tagColors = Zotero.Tags.getColors(libraryID);
Expand All @@ -11,7 +11,6 @@ describe("Tag Selector", function () {
});

function getColoredTags() {
var tagSelector = doc.getElementById('zotero-tag-selector');
var tagsBox = tagSelector.id('tags-box');
var elems = tagsBox.getElementsByTagName('button');
var names = [];
Expand All @@ -24,7 +23,6 @@ describe("Tag Selector", function () {
}

function getRegularTags() {
var tagSelector = doc.getElementById('zotero-tag-selector');
var tagsBox = tagSelector.id('tags-box');
var elems = tagsBox.getElementsByTagName('button');
var names = [];
Expand All @@ -41,22 +39,47 @@ describe("Tag Selector", function () {
win = yield loadZoteroPane();
doc = win.document;
collectionsView = win.ZoteroPane.collectionsView;
tagSelector = doc.getElementById('zotero-tag-selector');

// Wait for things to settle
yield Zotero.Promise.delay(100);
});

beforeEach(function* () {
var libraryID = Zotero.Libraries.userLibraryID;
yield clearTagColors(libraryID);
var tagSelector = doc.getElementById('zotero-tag-selector');
// Default "Display All Tags in This Library" off
tagSelector.filterToScope = true;
tagSelector.setSearch('');
yield tagSelector.refresh(true);
})

after(function () {
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 () {
it("should remove tags not on matching items on tag click", function* () {
var collection = yield createDataObject('collection');
Expand Down Expand Up @@ -89,7 +112,6 @@ describe("Tag Selector", function () {
});
yield promise;

var tagSelector = doc.getElementById('zotero-tag-selector');
var buttons = tagSelector.id('tags-box').getElementsByTagName('button');
var spy = sinon.spy(win.ZoteroPane, "updateTagFilter");
buttons[0].click();
Expand All @@ -106,7 +128,6 @@ describe("Tag Selector", function () {

describe("#filterToScope", function () {
it("should show all tags in library when false", function* () {
var tagSelector = doc.getElementById('zotero-tag-selector');
tagSelector.filterToScope = false;

var collection = yield createDataObject('collection');
Expand Down Expand Up @@ -229,14 +250,12 @@ describe("Tag Selector", function () {
yield promise;

// Tag selector should show the new item's tag
tagSelector = doc.getElementById('zotero-tag-selector');
assert.equal(getRegularTags().length, 1);
})

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 tagSelector = doc.getElementById('zotero-tag-selector');
var tagElems = tagSelector.id('tags-box').getElementsByTagName('button');
var count = tagElems.length;

Expand Down Expand Up @@ -270,7 +289,6 @@ describe("Tag Selector", function () {
yield item.saveTx();
yield promise;

var tagSelector = doc.getElementById('zotero-tag-selector');
var tagElems = tagSelector.id('tags-box').getElementsByTagName('button');

// Make sure the colored tags are still in the right position
Expand Down Expand Up @@ -362,7 +380,6 @@ describe("Tag Selector", function () {
// Remove tag from library
promise = waitForTagSelector(win);
var dialogPromise = waitForDialog();
var tagSelector = doc.getElementById('zotero-tag-selector');
yield tagSelector.deleteTag("A");
yield promise;

Expand All @@ -387,7 +404,6 @@ describe("Tag Selector", function () {
yield item.saveTx();
yield promise;

var tagSelector = doc.getElementById('zotero-tag-selector');
promise = waitForTagSelector(win);
var promptPromise = waitForWindow("chrome://global/content/commonDialog.xul", function (dialog) {
dialog.document.getElementById('loginTextbox').value = newTag;
Expand All @@ -411,7 +427,6 @@ describe("Tag Selector", function () {
yield Zotero.Tags.setColor(libraryID, oldTag, "#F3F3F3");
yield promise;

var tagSelector = doc.getElementById('zotero-tag-selector');
promise = waitForTagSelector(win);
var promptPromise = waitForWindow("chrome://global/content/commonDialog.xul", function (dialog) {
dialog.document.getElementById('loginTextbox').value = newTag;
Expand Down Expand Up @@ -443,7 +458,6 @@ describe("Tag Selector", function () {
yield item.saveTx();
yield promise;

var tagSelector = doc.getElementById('zotero-tag-selector');

assert.include(getRegularTags(), "a");

Expand Down

0 comments on commit 316a6f9

Please sign in to comment.