noteeditorTest.js (2149B)
1 "use strict"; 2 3 describe("Note Editor", function () { 4 var win, zp; 5 6 before(function* () { 7 win = yield loadZoteroPane(); 8 zp = win.ZoteroPane; 9 }); 10 11 after(function () { 12 win.close(); 13 }); 14 15 var waitForNoteEditor = Zotero.Promise.coroutine(function* (item) { 16 var noteEditor = win.document.getElementById('zotero-note-editor'); 17 while (noteEditor.item != item) { 18 Zotero.debug("Waiting for note editor"); 19 yield Zotero.Promise.delay(50); 20 noteEditor = win.document.getElementById('zotero-note-editor'); 21 } 22 return new Zotero.Promise((resolve, reject) => { 23 noteEditor.noteField.onInit(() => resolve(noteEditor)); 24 }); 25 }); 26 27 28 describe("Tags box", function () { 29 it("should open new row for editing if no tags", function* () { 30 var note = yield createDataObject('item', { itemType: 'note', note: "A" }); 31 var noteEditor = yield waitForNoteEditor(note); 32 var linksBox = noteEditor._id('links-box'); 33 linksBox.tagsClick(); 34 var tagsBox = linksBox.id('tagsPopup').firstChild; 35 var tagRows = tagsBox.id('tagRows'); 36 assert.equal(tagRows.childNodes.length, 1); 37 38 linksBox.id('tagsPopup').hidePopup(); 39 }); 40 41 it("should only open one new row for editing", function* () { 42 var note = yield createDataObject('item', { itemType: 'note', note: "B" }); 43 var noteEditor = yield waitForNoteEditor(note); 44 var linksBox = noteEditor._id('links-box'); 45 linksBox.tagsClick(); 46 // Close and reopen 47 linksBox.id('tagsPopup').hidePopup(); 48 linksBox.tagsClick(); 49 50 // Should still be only one empty row 51 var tagsBox = linksBox.id('tagsPopup').firstChild; 52 var tagRows = tagsBox.id('tagRows'); 53 assert.equal(tagRows.childNodes.length, 1); 54 55 linksBox.id('tagsPopup').hidePopup(); 56 }); 57 58 it("should show tags in alphabetical order", function* () { 59 var note = new Zotero.Item('note'); 60 note.setNote('C'); 61 note.addTag('B'); 62 yield note.saveTx(); 63 note.addTag('A'); 64 note.addTag('C'); 65 yield note.saveTx(); 66 67 var noteEditor = yield waitForNoteEditor(note); 68 var linksBox = noteEditor._id('links-box'); 69 assert.equal(linksBox.id('tags').summary, "A, B, C"); 70 }); 71 }); 72 });