Fix tags box tests
This commit is contained in:
parent
b391b6ca21
commit
b24d7d8f44
1 changed files with 19 additions and 13 deletions
|
@ -17,20 +17,26 @@ describe("Item Tags Box", function () {
|
||||||
|
|
||||||
describe("Tag Editing", function () {
|
describe("Tag Editing", function () {
|
||||||
it("should update tag when pressing Enter in textbox", async 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 tag = Zotero.Utilities.randomString();
|
||||||
var newTag = Zotero.Utilities.randomString();
|
var newTag = Zotero.Utilities.randomString();
|
||||||
|
|
||||||
var item = await createDataObject('item', { tags: [{ tag }] });
|
var item = await createDataObject('item', { tags: [{ tag }] });
|
||||||
|
|
||||||
var tagsbox = doc.querySelector('tags-box');
|
var tagsbox = doc.querySelector('#zotero-editpane-tags');
|
||||||
var rows = tagsbox.querySelectorAll('li');
|
var rows = tagsbox.querySelectorAll('.row editable-text');
|
||||||
assert.equal(rows.length, 1);
|
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"]');
|
var firstRow = rows[0];
|
||||||
label.click();
|
firstRow.focus();
|
||||||
var input = rows[0].querySelector('input[fieldname="tag"]');
|
await Zotero.Promise.delay(100);
|
||||||
input.value = newTag;
|
firstRow.ref.value = newTag;
|
||||||
|
firstRow.ref.dispatchEvent(new Event('input'));
|
||||||
|
|
||||||
// Press Enter in textbox
|
// Press Enter in textbox
|
||||||
var enterEvent = new KeyboardEvent('keydown', {
|
var enterEvent = new KeyboardEvent('keydown', {
|
||||||
|
@ -39,13 +45,13 @@ describe("Item Tags Box", function () {
|
||||||
'keyCode': 13,
|
'keyCode': 13,
|
||||||
'which': 13
|
'which': 13
|
||||||
});
|
});
|
||||||
input.dispatchEvent(enterEvent);
|
let promise = waitForItemEvent('modify');
|
||||||
await waitForItemEvent('modify');
|
firstRow.ref.dispatchEvent(enterEvent);
|
||||||
|
await promise;
|
||||||
|
|
||||||
rows = tagsbox.querySelectorAll('li');
|
rows = tagsbox.querySelectorAll('.row editable-text');
|
||||||
assert.equal(rows[0].textContent, newTag);
|
assert.equal(rows[0].value, newTag);
|
||||||
// Should open new empty textbox
|
assert.equal(rows.length, 1);
|
||||||
assert.equal(rows.length, 2);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue