diff --git a/test/tests/tagsboxTest.js b/test/tests/tagsboxTest.js index bc3dadff29..a7d705a6ce 100644 --- a/test/tests/tagsboxTest.js +++ b/test/tests/tagsboxTest.js @@ -17,20 +17,26 @@ describe("Item Tags Box", function () { describe("Tag Editing", function () { it("should update tag when pressing Enter in textbox", async function () { + // Bring the window to the front. Without this, fields will never get focus. + Zotero.Utilities.Internal.activate(); + Zotero.Utilities.Internal.activate(Zotero.getMainWindow()); + await Zotero.Promise.delay(100); + var tag = Zotero.Utilities.randomString(); var newTag = Zotero.Utilities.randomString(); var item = await createDataObject('item', { tags: [{ tag }] }); - var tagsbox = doc.querySelector('tags-box'); - var rows = tagsbox.querySelectorAll('li'); + var tagsbox = doc.querySelector('#zotero-editpane-tags'); + var rows = tagsbox.querySelectorAll('.row editable-text'); assert.equal(rows.length, 1); - assert.equal(rows[0].textContent, tag); + assert.equal(rows[0].value, tag); - var label = rows[0].querySelector('label[fieldname="tag"]'); - label.click(); - var input = rows[0].querySelector('input[fieldname="tag"]'); - input.value = newTag; + var firstRow = rows[0]; + firstRow.focus(); + await Zotero.Promise.delay(100); + firstRow.ref.value = newTag; + firstRow.ref.dispatchEvent(new Event('input')); // Press Enter in textbox var enterEvent = new KeyboardEvent('keydown', { @@ -39,13 +45,13 @@ describe("Item Tags Box", function () { 'keyCode': 13, 'which': 13 }); - input.dispatchEvent(enterEvent); - await waitForItemEvent('modify'); + let promise = waitForItemEvent('modify'); + firstRow.ref.dispatchEvent(enterEvent); + await promise; - rows = tagsbox.querySelectorAll('li'); - assert.equal(rows[0].textContent, newTag); - // Should open new empty textbox - assert.equal(rows.length, 2); + rows = tagsbox.querySelectorAll('.row editable-text'); + assert.equal(rows[0].value, newTag); + assert.equal(rows.length, 1); }); });