2015-05-19 21:05:58 +00:00
|
|
|
describe("Item pane", function () {
|
|
|
|
var win, doc, itemsView;
|
|
|
|
|
|
|
|
before(function* () {
|
|
|
|
win = yield loadZoteroPane();
|
|
|
|
doc = win.document;
|
|
|
|
itemsView = win.ZoteroPane.itemsView;
|
|
|
|
});
|
|
|
|
after(function () {
|
|
|
|
win.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Info pane", function () {
|
|
|
|
it("should refresh on item update", function* () {
|
|
|
|
var item = new Zotero.Item('book');
|
|
|
|
var id = yield item.saveTx();
|
|
|
|
|
|
|
|
var itemBox = doc.getElementById('zotero-editpane-item-box');
|
|
|
|
var label = doc.getAnonymousNodes(itemBox)[0].getElementsByAttribute('fieldname', 'title')[1];
|
|
|
|
assert.equal(label.textContent, '');
|
|
|
|
|
|
|
|
item.setField('title', 'Test');
|
|
|
|
yield item.saveTx();
|
|
|
|
|
|
|
|
var label = doc.getAnonymousNodes(itemBox)[0].getElementsByAttribute('fieldname', 'title')[1];
|
|
|
|
assert.equal(label.textContent, 'Test');
|
|
|
|
|
|
|
|
yield Zotero.Items.erase(id);
|
|
|
|
})
|
2016-06-29 09:24:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2015-05-19 21:05:58 +00:00
|
|
|
})
|
|
|
|
|
2015-08-07 19:36:46 +00:00
|
|
|
describe("Attachment pane", function () {
|
|
|
|
it("should refresh on file rename", function* () {
|
|
|
|
var file = getTestDataDirectory();
|
|
|
|
file.append('test.png');
|
|
|
|
var item = yield Zotero.Attachments.importFromFile({
|
|
|
|
file: file
|
|
|
|
});
|
|
|
|
var newName = 'test2.png';
|
|
|
|
yield item.renameAttachmentFile(newName);
|
|
|
|
|
|
|
|
var itemBox = doc.getElementById('zotero-attachment-box');
|
|
|
|
var label = itemBox._id('fileName');
|
|
|
|
assert.equal(label.value, newName);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2015-05-19 21:05:58 +00:00
|
|
|
describe("Note pane", function () {
|
|
|
|
it("should refresh on note update", function* () {
|
|
|
|
var item = new Zotero.Item('note');
|
|
|
|
var id = yield item.saveTx();
|
|
|
|
|
|
|
|
// Wait for the editor
|
|
|
|
var noteBox = doc.getElementById('zotero-note-editor');
|
|
|
|
var val = false;
|
|
|
|
do {
|
|
|
|
try {
|
|
|
|
val = noteBox.noteField.value;
|
|
|
|
}
|
|
|
|
catch (e) {}
|
|
|
|
yield Zotero.Promise.delay(1);
|
|
|
|
}
|
|
|
|
while (val === false)
|
|
|
|
assert.equal(noteBox.noteField.value, '');
|
|
|
|
|
|
|
|
item.setNote('<p>Test</p>');
|
|
|
|
yield item.saveTx();
|
|
|
|
|
|
|
|
assert.equal(noteBox.noteField.value, '<p>Test</p>');
|
|
|
|
})
|
2017-02-15 18:15:30 +00:00
|
|
|
|
|
|
|
it("should refresh on note trash", function* () {
|
|
|
|
var item = yield createDataObject('item');
|
|
|
|
|
|
|
|
var note = new Zotero.Item('note');
|
|
|
|
note.parentItemID = item.id;
|
|
|
|
yield note.saveTx();
|
|
|
|
yield itemsView.selectItem(note.id);
|
|
|
|
|
|
|
|
// Wait for the note editor, just to be polite
|
|
|
|
var noteBox = doc.getElementById('zotero-note-editor');
|
|
|
|
var val = false;
|
|
|
|
do {
|
|
|
|
try {
|
|
|
|
val = noteBox.noteField.value;
|
|
|
|
}
|
|
|
|
catch (e) {}
|
|
|
|
yield Zotero.Promise.delay(1);
|
|
|
|
}
|
|
|
|
while (val === false)
|
|
|
|
|
|
|
|
// Select parent and make sure there's 1 note
|
|
|
|
yield itemsView.selectItem(item.id);
|
|
|
|
var tabs = doc.getElementById('zotero-editpane-tabs');
|
|
|
|
var infoTab = doc.getElementById('zotero-editpane-info-tab');
|
|
|
|
var notesTab = doc.getElementById('zotero-editpane-notes-tab');
|
|
|
|
var notesList = doc.getElementById('zotero-editpane-dynamic-notes');
|
|
|
|
tabs.selectedItem = notesTab;
|
|
|
|
// Wait for note list to update
|
|
|
|
do {
|
|
|
|
yield Zotero.Promise.delay(1);
|
|
|
|
}
|
|
|
|
while (notesList.childNodes.length !== 1);
|
|
|
|
tabs.selectedItem = infoTab;
|
|
|
|
|
|
|
|
// Select child and trash it
|
|
|
|
yield itemsView.selectItem(note.id);
|
|
|
|
yield Zotero.Items.trashTx([note.id]);
|
|
|
|
|
|
|
|
// Select parent and select notes pane
|
|
|
|
yield itemsView.selectItem(item.id);
|
|
|
|
tabs.selectedItem = notesTab;
|
|
|
|
// Wait for note list to update
|
|
|
|
var len = false;
|
|
|
|
do {
|
|
|
|
yield Zotero.Promise.delay(1);
|
|
|
|
}
|
|
|
|
while (notesList.childNodes.length !== 0);
|
|
|
|
})
|
2015-05-19 21:05:58 +00:00
|
|
|
})
|
2016-03-25 04:49:14 +00:00
|
|
|
|
|
|
|
describe("Feed buttons", function() {
|
|
|
|
describe("Mark as Read/Unread", function() {
|
|
|
|
it("Updates label when state of an item changes", function* () {
|
|
|
|
let feed = yield createFeed();
|
|
|
|
yield selectLibrary(win, feed.libraryID);
|
|
|
|
let item = yield createDataObject('feedItem', {libraryID: feed.libraryID});
|
|
|
|
yield itemsView.selectItem(item.id);
|
|
|
|
let button = doc.getElementById('zotero-feed-item-toggleRead-button');
|
|
|
|
|
|
|
|
assert.equal(button.getAttribute('label'), Zotero.getString('pane.item.markAsUnread'));
|
|
|
|
yield item.toggleRead(false);
|
|
|
|
assert.equal(button.getAttribute('label'), Zotero.getString('pane.item.markAsRead'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-05-19 21:05:58 +00:00
|
|
|
})
|