www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

tagsboxTest.js (3172B)


      1 "use strict";
      2 
      3 describe("Item Tags Box", function () {
      4 	var win, doc, collectionsView;
      5 	
      6 	before(function* () {
      7 		win = yield loadZoteroPane();
      8 		doc = win.document;
      9 		
     10 		// Wait for things to settle
     11 		yield Zotero.Promise.delay(100);
     12 	});
     13 	after(function () {
     14 		win.close();
     15 	});
     16 	
     17 	describe("#notify()", function () {
     18 		it("should update an existing tag on rename", function* () {
     19 			var tag = Zotero.Utilities.randomString();
     20 			var newTag = Zotero.Utilities.randomString();
     21 			
     22 			var tabbox = doc.getElementById('zotero-view-tabbox');
     23 			tabbox.selectedIndex = 0;
     24 			
     25 			var item = createUnsavedDataObject('item');
     26 			item.setTags([
     27 				{
     28 					tag: tag
     29 				}
     30 			]);
     31 			yield item.saveTx();
     32 			
     33 			var tabbox = doc.getElementById('zotero-view-tabbox');
     34 			tabbox.selectedIndex = 2;
     35 			var tagsbox = doc.getElementById('zotero-editpane-tags');
     36 			var rows = tagsbox.id('tagRows').getElementsByTagName('row');
     37 			assert.equal(rows.length, 1);
     38 			assert.equal(rows[0].textContent, tag);
     39 			
     40 			yield Zotero.Tags.rename(Zotero.Libraries.userLibraryID, tag, newTag);
     41 			
     42 			var rows = tagsbox.id('tagRows').getElementsByTagName('row');
     43 			assert.equal(rows.length, 1);
     44 			assert.equal(rows[0].textContent, newTag);
     45 		})
     46 		
     47 		it("should update when a tag's color is removed", function* () {
     48 			var libraryID = Zotero.Libraries.userLibraryID;
     49 			
     50 			var tag = Zotero.Utilities.randomString();
     51 			var tabbox = doc.getElementById('zotero-view-tabbox');
     52 			tabbox.selectedIndex = 0;
     53 			
     54 			yield Zotero.Tags.setColor(libraryID, tag, "#990000");
     55 			var item = createUnsavedDataObject('item');
     56 			item.setTags([
     57 				{
     58 					tag: tag,
     59 				},
     60 				{
     61 					tag: "_A"
     62 				}
     63 			]);
     64 			yield item.saveTx();
     65 			
     66 			var tabbox = doc.getElementById('zotero-view-tabbox');
     67 			tabbox.selectedIndex = 2;
     68 			var tagsbox = doc.getElementById('zotero-editpane-tags');
     69 			var rows = tagsbox.id('tagRows').getElementsByTagName('row');
     70 			
     71 			// Colored tags aren't sorted first, for now
     72 			assert.notOk(rows[0].getElementsByTagName('label')[0].style.color);
     73 			assert.ok(rows[1].getElementsByTagName('label')[0].style.color);
     74 			assert.equal(rows[0].textContent, "_A");
     75 			assert.equal(rows[1].textContent, tag);
     76 			
     77 			yield Zotero.Tags.setColor(libraryID, tag, false);
     78 			
     79 			assert.notOk(rows[1].getElementsByTagName('label')[0].style.color);
     80 		})
     81 		
     82 		it("should update when a tag is removed from the library", function* () {
     83 			var tag = Zotero.Utilities.randomString();
     84 			
     85 			var tabbox = doc.getElementById('zotero-view-tabbox');
     86 			tabbox.selectedIndex = 0;
     87 			
     88 			var item = createUnsavedDataObject('item');
     89 			item.setTags([
     90 				{
     91 					tag: tag
     92 				}
     93 			]);
     94 			yield item.saveTx();
     95 			
     96 			var tabbox = doc.getElementById('zotero-view-tabbox');
     97 			tabbox.selectedIndex = 2;
     98 			var tagsbox = doc.getElementById('zotero-editpane-tags');
     99 			var rows = tagsbox.id('tagRows').getElementsByTagName('row');
    100 			assert.equal(rows.length, 1);
    101 			assert.equal(rows[0].textContent, tag);
    102 			
    103 			yield Zotero.Tags.removeFromLibrary(Zotero.Libraries.userLibraryID, Zotero.Tags.getID(tag));
    104 			
    105 			var rows = tagsbox.id('tagRows').getElementsByTagName('row');
    106 			assert.equal(rows.length, 0);
    107 		})
    108 	})
    109 })