From 0fc91a4ef281b9cf2ff0bc89cb33c7d175f715e6 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 12 Mar 2016 05:03:47 -0500 Subject: [PATCH] Tests for showing/hiding virtual folders --- test/tests/collectionTreeViewTest.js | 8 ++-- test/tests/zoteroPaneTest.js | 71 +++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/test/tests/collectionTreeViewTest.js b/test/tests/collectionTreeViewTest.js index f78c2d3e96..e5b8e9c4a8 100644 --- a/test/tests/collectionTreeViewTest.js +++ b/test/tests/collectionTreeViewTest.js @@ -22,8 +22,8 @@ describe("Zotero.CollectionTreeView", function() { Zotero.Prefs.clear('duplicateLibraries'); Zotero.Prefs.clear('unfiledLibraries'); yield cv.refresh(); - yield assert.eventually.ok(cv.selectByID("D" + userLibraryID)); - yield assert.eventually.ok(cv.selectByID("U" + userLibraryID)); + assert.isTrue(cv.getRowIndexByID("D" + userLibraryID)); + assert.isTrue(cv.getRowIndexByID("U" + userLibraryID)); assert.equal(Zotero.Prefs.get('duplicateLibraries'), "" + userLibraryID); assert.equal(Zotero.Prefs.get('unfiledLibraries'), "" + userLibraryID); }); @@ -32,8 +32,8 @@ describe("Zotero.CollectionTreeView", function() { Zotero.Prefs.set('duplicateLibraries', ""); Zotero.Prefs.set('unfiledLibraries', ""); yield cv.refresh(); - yield assert.eventually.notOk(cv.selectByID("D" + userLibraryID)); - yield assert.eventually.notOk(cv.selectByID("U" + userLibraryID)); + assert.isFalse(cv.getRowIndexByID("D" + userLibraryID)); + assert.isFalse(cv.getRowIndexByID("U" + userLibraryID)); assert.strictEqual(Zotero.Prefs.get('duplicateLibraries'), ""); assert.strictEqual(Zotero.Prefs.get('unfiledLibraries'), ""); }); diff --git a/test/tests/zoteroPaneTest.js b/test/tests/zoteroPaneTest.js index 5d768bfaaf..1b88d040c3 100644 --- a/test/tests/zoteroPaneTest.js +++ b/test/tests/zoteroPaneTest.js @@ -1,13 +1,14 @@ "use strict"; describe("ZoteroPane", function() { - var win, doc, zp; + var win, doc, zp, userLibraryID; // Load Zotero pane and select library before(function* () { win = yield loadZoteroPane(); doc = win.document; zp = win.ZoteroPane; + userLibraryID = Zotero.Libraries.userLibraryID; }); after(function () { @@ -201,4 +202,72 @@ describe("ZoteroPane", function() { assert.equal((yield Zotero.File.getContentsAsync(path)), text); }) }) + + + describe("#setVirtual()", function () { + var cv; + + before(function* () { + cv = zp.collectionsView; + }); + beforeEach(function () { + Zotero.Prefs.clear('duplicateLibraries'); + Zotero.Prefs.clear('unfiledLibraries'); + return selectLibrary(win); + }) + + it("should show a hidden virtual folder", function* () { + // Start hidden + Zotero.Prefs.set('duplicateLibraries', ""); + Zotero.Prefs.set('unfiledLibraries', ""); + yield cv.refresh(); + + // Show Duplicate Items + var id = "D" + userLibraryID; + assert.isFalse(cv.getRowIndexByID(id)); + yield zp.setVirtual(userLibraryID, 'duplicates', true); + assert.ok(cv.getRowIndexByID(id)); + + // Show Unfiled Items + id = "U" + userLibraryID; + assert.isFalse(cv.getRowIndexByID(id)); + yield zp.setVirtual(userLibraryID, 'unfiled', true); + assert.ok(cv.getRowIndexByID(id)); + }); + + it("should hide a virtual folder shown by default", function* () { + yield cv.refresh(); + + // Hide Duplicate Items + var id = "D" + userLibraryID; + assert.ok(yield cv.selectByID(id)); + yield zp.setVirtual(userLibraryID, 'duplicates', false); + assert.isFalse(cv.getRowIndexByID(id)); + + // Hide Unfiled Items + id = "U" + userLibraryID; + assert.ok(yield cv.selectByID(id)); + yield zp.setVirtual(userLibraryID, 'unfiled', false); + assert.isFalse(cv.getRowIndexByID(id)); + }); + + it("should hide an explicitly shown virtual folder", function* () { + // Start shown + Zotero.Prefs.set('duplicateLibraries', "" + userLibraryID); + Zotero.Prefs.set('unfiledLibraries' "" + userLibraryID); + yield cv.refresh(); + + // Hide Duplicate Items + var id = "D" + userLibraryID; + assert.ok(yield cv.selectByID(id)); + yield zp.setVirtual(userLibraryID, 'duplicates', false); + assert.isFalse(cv.getRowIndexByID(id)); + + // Hide Unfiled Items + id = "U" + userLibraryID; + assert.ok(yield cv.selectByID(id)); + yield zp.setVirtual(userLibraryID, 'unfiled', false); + assert.isFalse(cv.getRowIndexByID(id)); + }); + }); })