www

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

relatedboxTest.js (2878B)


      1 "use strict";
      2 
      3 describe("Related Box", function () {
      4 	var win, doc, itemsView;
      5 	
      6 	before(function* () {
      7 		win = yield loadZoteroPane();
      8 		doc = win.document;
      9 		itemsView = win.ZoteroPane.itemsView;
     10 	});
     11 	after(function () {
     12 		win.close();
     13 	})
     14 	
     15 	describe("Add button", function () {
     16 		it("should add a related item", function* () {
     17 			var item1 = yield createDataObject('item');
     18 			var item2 = yield createDataObject('item');
     19 			
     20 			// Select the Related pane
     21 			var tabbox = doc.getElementById('zotero-view-tabbox');
     22 			tabbox.selectedIndex = 3;
     23 			var relatedbox = doc.getElementById('zotero-editpane-related');
     24 			assert.lengthOf(relatedbox.id('relatedRows').childNodes, 0);
     25 			
     26 			// Click the Add button to open the Select Items dialog
     27 			setTimeout(function () {
     28 				relatedbox.id('addButton').click();
     29 			});
     30 			var selectWin = yield waitForWindow('chrome://zotero/content/selectItemsDialog.xul');
     31 			// wrappedJSObject isn't working on zotero-collections-tree for some reason, so
     32 			// just wait for the items tree to be created and select it directly
     33 			do {
     34 				var view = selectWin.document.getElementById('zotero-items-tree').view.wrappedJSObject;
     35 				yield Zotero.Promise.delay(50);
     36 			}
     37 			while (!view);
     38 			yield view.waitForLoad();
     39 			
     40 			// Select the other item
     41 			for (let i = 0; i < view.rowCount; i++) {
     42 				if (view.getRow(i).ref.id == item1.id) {
     43 					view.selection.select(i);
     44 				}
     45 			}
     46 			selectWin.document.documentElement.acceptDialog();
     47 			
     48 			// Wait for relations list to populate
     49 			do {
     50 				yield Zotero.Promise.delay(50);
     51 			}
     52 			while (!relatedbox.id('relatedRows').childNodes.length);
     53 			
     54 			assert.lengthOf(relatedbox.id('relatedRows').childNodes, 1);
     55 			
     56 			var items = item1.relatedItems;
     57 			assert.lengthOf(items, 1);
     58 			assert.equal(items[0], item2.key);
     59 			
     60 			// Relation should be assigned bidirectionally
     61 			var items = item2.relatedItems;
     62 			assert.lengthOf(items, 1);
     63 			assert.equal(items[0], item1.key);
     64 		})
     65 	})
     66 	
     67 	describe("Remove button", function () {
     68 		it("should remove a related item", function* () {
     69 			var item1 = yield createDataObject('item');
     70 			var item2 = yield createDataObject('item');
     71 			
     72 			item1.addRelatedItem(item2);
     73 			yield item1.saveTx();
     74 			item2.addRelatedItem(item1);
     75 			yield item2.saveTx();
     76 			
     77 			// Select the Related pane
     78 			var tabbox = doc.getElementById('zotero-view-tabbox');
     79 			tabbox.selectedIndex = 3;
     80 			var relatedbox = doc.getElementById('zotero-editpane-related');
     81 			
     82 			// Wait for relations list to populate
     83 			do {
     84 				yield Zotero.Promise.delay(50);
     85 			}
     86 			while (!relatedbox.id('relatedRows').childNodes.length);
     87 			
     88 			doc.getAnonymousNodes(relatedbox)[0]
     89 				.getElementsByAttribute('value', '-')[0]
     90 				.click();
     91 			
     92 			// Wait for relations list to clear
     93 			do {
     94 				yield Zotero.Promise.delay(50);
     95 			}
     96 			while (relatedbox.id('relatedRows').childNodes.length);
     97 		})
     98 	})
     99 })