zotero/test/tests/itemTreeViewTest.js
Dan Stillman 8fec5ace3a Fix post-save textbox focusing bugs in right-hand pane
Fix a couple cases of lost text field focus after an edit, including
focusing of the Title field after using New Item when a field is already
being edited and has a changed value.

Also, in tests, select My Library and wait for items to load when using
the loadZoteroPane() support function. We could add a parameter to skip
that or move it to a separate function, but the code to detect it is a
bit convoluted and it's a prerequisite for many tests, so it's handy to
have a function for it.
2015-05-04 02:45:55 -04:00

123 lines
3.6 KiB
JavaScript

describe("Zotero.ItemTreeView", function() {
var win, itemsView, existingItemID;
// Load Zotero pane and select library
before(function* () {
win = yield loadZoteroPane();
itemsView = win.ZoteroPane.itemsView;
var item = new Zotero.Item('book');
existingItemID = yield item.save();
});
after(function () {
win.close();
});
describe("#selectItem()", function () {
/**
* Make sure that selectItem() doesn't hang if the pane's item-select handler is never
* triggered due to the item already being selected
*/
it("should return if item is already selected", function* () {
yield itemsView.selectItem(existingItemID);
var selected = itemsView.getSelectedItems();
assert.lengthOf(selected, 1);
assert.equal(selected[0].id, existingItemID);
yield itemsView.selectItem(existingItemID);
selected = itemsView.getSelectedItems();
assert.lengthOf(selected, 1);
assert.equal(selected[0].id, existingItemID);
});
})
describe("#notify()", function () {
it("should select a new item", function* () {
itemsView.selection.clearSelection();
assert.lengthOf(itemsView.getSelectedItems(), 0);
// Create item
var item = new Zotero.Item('book');
var id = yield item.save();
// New item should be selected
var selected = itemsView.getSelectedItems();
assert.lengthOf(selected, 1);
assert.equal(selected[0].id, id);
});
it("shouldn't select a new item if skipNotifier is passed", function* () {
// Select existing item
yield itemsView.selectItem(existingItemID);
var selected = itemsView.getSelectedItems();
assert.lengthOf(selected, 1);
assert.equal(selected[0].id, existingItemID);
// Create item with skipNotifier flag
var item = new Zotero.Item('book');
var id = yield item.save({
skipNotifier: true
});
// Existing item should still be selected
selected = itemsView.getSelectedItems();
assert.lengthOf(selected, 1);
assert.equal(selected[0].id, existingItemID);
});
it("shouldn't select a new item if skipSelect is passed", function* () {
// Select existing item
yield itemsView.selectItem(existingItemID);
var selected = itemsView.getSelectedItems();
assert.lengthOf(selected, 1);
assert.equal(selected[0].id, existingItemID);
// Create item with skipSelect flag
var item = new Zotero.Item('book');
var id = yield item.save({
skipSelect: true
});
// Existing item should still be selected
selected = itemsView.getSelectedItems(true);
assert.lengthOf(selected, 1);
assert.equal(selected[0], existingItemID);
});
it("shouldn't select a modified item", function* () {
// Create item
var item = new Zotero.Item('book');
var id = yield item.save();
item = yield Zotero.Items.getAsync(id);
itemsView.selection.clearSelection();
assert.lengthOf(itemsView.getSelectedItems(), 0);
item.setField('title', 'no select on modify');
yield item.save();
// Modified item should not be selected
assert.lengthOf(itemsView.getSelectedItems(), 0);
});
it("should reselect a selected modified item", function* () {
// Create item
var item = new Zotero.Item('book');
var id = yield item.save();
item = yield Zotero.Items.getAsync(id);
yield itemsView.selectItem(id);
var selected = itemsView.getSelectedItems(true);
assert.lengthOf(selected, 1);
assert.equal(selected[0], id);
item.setField('title', 'reselect on modify');
yield item.save();
// Modified item should still be selected
selected = itemsView.getSelectedItems(true);
assert.lengthOf(selected, 1);
assert.equal(selected[0], id);
});
})
})