Save open field when selecting from an item pane context menu

If a field is open and the user right-clicks on another field (e.g., swap
names, creator type, transform text), any changed value in the open field was
lost.

Also:

- Don't show swap-names menu in single-field mode

I can't quite get programmatic access to context menus to work correctly, so
tests are disabled for now. (They work individually, but not together.)
This commit is contained in:
Dan Stillman 2016-06-29 05:24:14 -04:00
parent 2cce099928
commit 2a55e56f3f
2 changed files with 129 additions and 32 deletions

View file

@ -27,6 +27,89 @@ describe("Item pane", function () {
yield Zotero.Items.erase(id);
})
it.skip("should swap creator names", function* () {
var item = new Zotero.Item('book');
item.setCreators([
{
firstName: "First",
lastName: "Last",
creatorType: "author"
}
]);
yield item.saveTx();
var itemBox = doc.getElementById('zotero-editpane-item-box');
var label = doc.getAnonymousNodes(itemBox)[0].getElementsByAttribute('fieldname', 'creator-0-lastName')[0];
var parent = label.parentNode;
assert.isTrue(parent.hasAttribute('contextmenu'));
var menupopup = doc.getAnonymousNodes(itemBox)[0]
.getElementsByAttribute('id', 'zotero-creator-transform-menu')[0];
// Fake a right-click
doc.popupNode = parent;
menupopup.openPopup(
parent, "after_start", 0, 0, true, false, new MouseEvent('click', { button: 2 })
);
var menuitem = menupopup.getElementsByTagName('menuitem')[0];
menuitem.click();
yield waitForItemEvent('modify');
var creator = item.getCreators()[0];
assert.propertyVal(creator, 'firstName', 'Last');
assert.propertyVal(creator, 'lastName', 'First');
});
it("shouldn't show Swap Names menu for single-field mode", function* () {
var item = new Zotero.Item('book');
item.setCreators([
{
name: "Name",
creatorType: "author"
}
]);
yield item.saveTx();
var itemBox = doc.getElementById('zotero-editpane-item-box');
var label = doc.getAnonymousNodes(itemBox)[0].getElementsByAttribute('fieldname', 'creator-0-lastName')[0];
assert.isFalse(label.parentNode.hasAttribute('contextmenu'));
});
// Note: This issue applies to all context menus in the item box (text transform, name swap),
// though the others aren't tested. This might go away with the XUL->HTML transition.
it.skip("should save open field after changing creator type", function* () {
var item = new Zotero.Item('book');
item.setCreators([
{
firstName: "First",
lastName: "Last",
creatorType: "author"
}
]);
var id = yield item.saveTx();
var itemBox = doc.getElementById('zotero-editpane-item-box');
var label = doc.getAnonymousNodes(itemBox)[0].getElementsByAttribute('fieldname', 'place')[1];
label.click();
var textbox = doc.getAnonymousNodes(itemBox)[0].getElementsByAttribute('fieldname', 'place')[1];
textbox.value = "Place";
var menuLabel = doc.getAnonymousNodes(itemBox)[0].getElementsByAttribute('fieldname', 'creator-0-typeID')[0];
menuLabel.click();
var menupopup = itemBox._creatorTypeMenu;
var menuItems = menupopup.getElementsByTagName('menuitem');
menuItems[1].click();
yield waitForItemEvent('modify');
assert.equal(item.getField('place'), 'Place');
assert.equal(Zotero.CreatorTypes.getName(item.getCreators()[0].creatorTypeID), 'contributor');
// Wait for no-op saveTx()
yield Zotero.Promise.delay(1);
});
})
describe("Attachment pane", function () {