<commit_before>"use strict";

describe("Note Editor", function () {
	var win, zp;
	
	before(function* () {
		win = yield loadZoteroPane();
		zp = win.ZoteroPane;
	});
	
	beforeEach(function* () {
		// Avoid "this._editor is undefined" error and incorrect note selection between tests,
		// though there's definitely a better way to fix this
		yield Zotero.Promise.delay(150);
	});
	
	after(function () {
		win.close();
	});
	
	describe("Tags box", function () {
		it("should open new row for editing if no tags", function* () {
			var note = yield createDataObject('item', { itemType: 'note' });
			var noteEditor = win.document.getElementById('zotero-note-editor');
			var linksBox = noteEditor._id('links-box');
			linksBox.tagsClick();
			var tagsBox = linksBox.id('tagsPopup').firstChild;
			var tagRows = tagsBox.id('tagRows');
			assert.equal(tagRows.childNodes.length, 1);
			
			linksBox.id('tagsPopup').hidePopup();
		});
		
		it("should only open one new row for editing", function* () {
			var note = yield createDataObject('item', { itemType: 'note' });
			var noteEditor = win.document.getElementById('zotero-note-editor');
			var linksBox = noteEditor._id('links-box');
			linksBox.tagsClick();
			// Close and reopen
			linksBox.id('tagsPopup').hidePopup();
			linksBox.tagsClick();
			
			// Should still be only one empty row
			var tagsBox = linksBox.id('tagsPopup').firstChild;
			var tagRows = tagsBox.id('tagRows');
			assert.equal(tagRows.childNodes.length, 1);
			
			linksBox.id('tagsPopup').hidePopup();
		});
		
		it("should show tags in alphabetical order", function* () {
			var note = new Zotero.Item('note');
			note.addTag('B');
			yield note.saveTx();
			note.addTag('A');
			note.addTag('C');
			yield note.saveTx();
			
			var noteEditor = win.document.getElementById('zotero-note-editor');
			var linksBox = noteEditor._id('links-box');
			assert.equal(linksBox.id('tags').summary, "A, B, C");
		});
	});<commit_msg>Maybe fix noteeditor test failures for real<commit_after>"use strict";

describe("Note Editor", function () {
	var win, zp;
	
	before(function* () {
		win = yield loadZoteroPane();
		zp = win.ZoteroPane;
	});
	
	after(function () {
		win.close();
	});
	
	var waitForNoteEditor = Zotero.Promise.coroutine(function* (item) {
		var noteEditor = win.document.getElementById('zotero-note-editor');
		while (noteEditor.item != item) {
			Zotero.debug("Waiting for note editor");
			yield Zotero.Promise.delay(50);
			noteEditor = win.document.getElementById('zotero-note-editor');
		}
		return new Zotero.Promise((resolve, reject) => {
			noteEditor.noteField.onInit(() => resolve(noteEditor));
		});
	});
	
	
	describe("Tags box", function () {
		it("should open new row for editing if no tags", function* () {
			var note = yield createDataObject('item', { itemType: 'note', note: "A" });
			var noteEditor = yield waitForNoteEditor(note);
			var linksBox = noteEditor._id('links-box');
			linksBox.tagsClick();
			var tagsBox = linksBox.id('tagsPopup').firstChild;
			var tagRows = tagsBox.id('tagRows');
			assert.equal(tagRows.childNodes.length, 1);
			
			linksBox.id('tagsPopup').hidePopup();
		});
		
		it("should only open one new row for editing", function* () {
			var note = yield createDataObject('item', { itemType: 'note', note: "B" });
			var noteEditor = yield waitForNoteEditor(note);
			var linksBox = noteEditor._id('links-box');
			linksBox.tagsClick();
			// Close and reopen
			linksBox.id('tagsPopup').hidePopup();
			linksBox.tagsClick();
			
			// Should still be only one empty row
			var tagsBox = linksBox.id('tagsPopup').firstChild;
			var tagRows = tagsBox.id('tagRows');
			assert.equal(tagRows.childNodes.length, 1);
			
			linksBox.id('tagsPopup').hidePopup();
		});
		
		it("should show tags in alphabetical order", function* () {
			var note = new Zotero.Item('note');
			note.setNote('C');
			note.addTag('B');
			yield note.saveTx();
			note.addTag('A');
			note.addTag('C');
			yield note.saveTx();
			
			var noteEditor = yield waitForNoteEditor(note);
			var linksBox = noteEditor._id('links-box');
			assert.equal(linksBox.id('tags').summary, "A, B, C");
		});
	});
{'fraction_non_alphanumeric': 0.1644990366088632, 'fraction_numerical': 0.002167630057803468, 'mean_word_length': 3.9031877213695396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1657254', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1332, 'n_words': 305}