passing newItem tests

This commit is contained in:
Bogdan Abaev 2024-01-12 10:07:19 -05:00 committed by Dan Stillman
parent 3073137d39
commit 8e4fd75f1d
2 changed files with 12 additions and 12 deletions

View file

@ -1328,9 +1328,11 @@ var ZoteroPane = new function()
if (manual) { if (manual) {
// Update most-recently-used list for New Item menu // Update most-recently-used list for New Item menu
this.addItemTypeToNewItemTypeMRU(Zotero.ItemTypes.getName(typeID)); this.addItemTypeToNewItemTypeMRU(Zotero.ItemTypes.getName(typeID));
// Focus the title field if the itemPane is expanded
// Focus the title field let itemPane = document.getElementById("zotero-item-pane");
document.getElementById('zotero-editpane-item-box').focusFirstField(); if (!itemPane.getAttribute("collapsed")) {
document.getElementById('zotero-item-pane-header').querySelector("editable-text").focus();
}
} }
return Zotero.Items.getAsync(itemID); return Zotero.Items.getAsync(itemID);

View file

@ -18,21 +18,19 @@ describe("ZoteroPane", function() {
describe("#newItem", function () { describe("#newItem", function () {
it("should create an item and focus the title field", function* () { it("should create an item and focus the title field", function* () {
yield zp.newItem(Zotero.ItemTypes.getID('book'), {}, null, true); yield zp.newItem(Zotero.ItemTypes.getID('book'), {}, null, true);
var itemBox = doc.getElementById('zotero-editpane-item-box'); let title = doc.getElementById('zotero-item-pane-header').querySelector("editable-text");
var textboxes = itemBox.querySelectorAll('input, textarea'); assert.equal(doc.activeElement.getAttribute("aria-label"), title.getAttribute("aria-label"));
assert.lengthOf(textboxes, 1); title.blur();
assert.equal(textboxes[0].getAttribute('fieldname'), 'title');
textboxes[0].blur();
yield Zotero.Promise.delay(1); yield Zotero.Promise.delay(1);
}) })
it("should save an entered value when New Item is used", function* () { it("should save an entered value when New Item is used", function* () {
var value = "Test"; var value = "Test";
var item = yield zp.newItem(Zotero.ItemTypes.getID('book'), {}, null, true); var item = yield zp.newItem(Zotero.ItemTypes.getID('book'), {}, null, true);
var itemBox = doc.getElementById('zotero-editpane-item-box'); let header = doc.getElementById('zotero-item-pane-header');
var textbox = itemBox.querySelector('textarea'); let title = header.querySelector("editable-text");
textbox.value = value; title.value = value;
yield itemBox.blurOpenField(); yield header.save();
item = yield Zotero.Items.getAsync(item.id); item = yield Zotero.Items.getAsync(item.id);
assert.equal(item.getField('title'), value); assert.equal(item.getField('title'), value);
}) })