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');
|
2022-06-20 04:47:14 +00:00
|
|
|
var label = itemBox.shadowRoot.querySelectorAll('[fieldname="title"]')[1];
|
2015-05-19 21:05:58 +00:00
|
|
|
assert.equal(label.textContent, '');
|
|
|
|
|
|
|
|
item.setField('title', 'Test');
|
|
|
|
yield item.saveTx();
|
|
|
|
|
2022-06-20 04:47:14 +00:00
|
|
|
label = itemBox.shadowRoot.querySelectorAll('[fieldname="title"]')[1];
|
2015-05-19 21:05:58 +00:00
|
|
|
assert.equal(label.textContent, 'Test');
|
|
|
|
|
|
|
|
yield Zotero.Items.erase(id);
|
|
|
|
})
|
2016-06-29 09:24:14 +00:00
|
|
|
|
|
|
|
|
2022-06-20 04:47:14 +00:00
|
|
|
it("should swap creator names", async function () {
|
2016-06-29 09:24:14 +00:00
|
|
|
var item = new Zotero.Item('book');
|
|
|
|
item.setCreators([
|
|
|
|
{
|
|
|
|
firstName: "First",
|
|
|
|
lastName: "Last",
|
|
|
|
creatorType: "author"
|
|
|
|
}
|
|
|
|
]);
|
2022-06-20 04:47:14 +00:00
|
|
|
await item.saveTx();
|
2016-06-29 09:24:14 +00:00
|
|
|
|
|
|
|
var itemBox = doc.getElementById('zotero-editpane-item-box');
|
2022-06-20 04:47:14 +00:00
|
|
|
var label = itemBox.shadowRoot.querySelector('[fieldname="creator-0-lastName"]')
|
2016-06-29 09:24:14 +00:00
|
|
|
var parent = label.parentNode;
|
2022-06-20 04:47:14 +00:00
|
|
|
assert.property(parent, 'oncontextmenu');
|
|
|
|
assert.isFunction(label.parentNode.oncontextmenu);
|
2016-06-29 09:24:14 +00:00
|
|
|
|
2022-06-20 04:47:14 +00:00
|
|
|
var menupopup = itemBox.shadowRoot.getElementById('zotero-creator-transform-menu');
|
2016-06-29 09:24:14 +00:00
|
|
|
// 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();
|
2022-06-20 04:47:14 +00:00
|
|
|
await waitForItemEvent('modify');
|
2016-06-29 09:24:14 +00:00
|
|
|
|
|
|
|
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');
|
2022-06-20 04:47:14 +00:00
|
|
|
var label = itemBox.shadowRoot.querySelector('[fieldname="creator-0-lastName"]');
|
|
|
|
assert.isNull(label.parentNode.oncontextmenu, null);
|
2016-06-29 09:24:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
});
|
2018-01-05 08:40:57 +00:00
|
|
|
|
|
|
|
it("should accept 'now' for Accessed", async function () {
|
|
|
|
var item = await createDataObject('item');
|
|
|
|
|
|
|
|
var itemBox = doc.getElementById('zotero-editpane-item-box');
|
2022-06-20 04:47:14 +00:00
|
|
|
var box = itemBox.shadowRoot;
|
|
|
|
var label = box.querySelector('div[fieldname="accessDate"].zotero-clicky');
|
2018-01-05 08:40:57 +00:00
|
|
|
label.click();
|
2022-06-20 04:47:14 +00:00
|
|
|
var textbox = box.querySelector('input[fieldname="accessDate"]');
|
2018-01-05 08:40:57 +00:00
|
|
|
textbox.value = 'now';
|
|
|
|
// Blur events don't necessarily trigger if window doesn't have focus
|
|
|
|
itemBox.hideEditor(textbox);
|
|
|
|
|
|
|
|
await waitForItemEvent('modify');
|
|
|
|
|
|
|
|
assert.approximately(
|
|
|
|
Zotero.Date.sqlToDate(item.getField('accessDate'), true).getTime(),
|
|
|
|
Date.now(),
|
2018-01-05 11:04:53 +00:00
|
|
|
5000
|
2018-01-05 08:40:57 +00:00
|
|
|
);
|
|
|
|
});
|
2022-08-08 15:48:33 +00:00
|
|
|
|
|
|
|
it("should persist fieldMode after hiding a creator name editor", async function () {
|
|
|
|
let item = new Zotero.Item('book');
|
|
|
|
item.setCreators([
|
|
|
|
{
|
|
|
|
name: "First Last",
|
|
|
|
creatorType: "author",
|
|
|
|
fieldMode: 1
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
await item.saveTx();
|
|
|
|
|
|
|
|
let itemBox = doc.getElementById('zotero-editpane-item-box');
|
|
|
|
let box = doc.getAnonymousNodes(itemBox)[0];
|
|
|
|
|
|
|
|
box.querySelector('label[fieldname="creator-0-lastName"]').click();
|
|
|
|
itemBox.hideEditor(box.querySelector('textbox[fieldname="creator-0-lastName"]'));
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
box.querySelector('label[fieldname="creator-0-lastName"]').getAttribute('fieldMode'),
|
|
|
|
'1'
|
|
|
|
);
|
|
|
|
});
|
2015-05-19 21:05:58 +00:00
|
|
|
})
|
|
|
|
|
2017-03-01 06:35:15 +00:00
|
|
|
|
|
|
|
describe("Notes pane", function () {
|
|
|
|
it("should refresh on child note change", function* () {
|
|
|
|
var item;
|
|
|
|
var note1;
|
|
|
|
var note2;
|
2020-07-05 10:20:01 +00:00
|
|
|
yield Zotero.DB.executeTransaction(async function () {
|
2017-03-01 06:35:15 +00:00
|
|
|
item = createUnsavedDataObject('item');
|
2020-07-05 10:20:01 +00:00
|
|
|
await item.save();
|
2017-03-01 06:35:15 +00:00
|
|
|
|
|
|
|
note1 = new Zotero.Item('note');
|
|
|
|
note1.parentID = item.id;
|
|
|
|
note1.setNote('A');
|
2020-07-05 10:20:01 +00:00
|
|
|
await note1.save();
|
2017-03-01 06:35:15 +00:00
|
|
|
|
|
|
|
note2 = new Zotero.Item('note');
|
|
|
|
note2.parentID = item.id;
|
|
|
|
note2.setNote('B');
|
2020-07-05 10:20:01 +00:00
|
|
|
await note2.save();
|
2017-03-01 06:35:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var tabs = doc.getElementById('zotero-editpane-tabs');
|
|
|
|
var notesTab = doc.getElementById('zotero-editpane-notes-tab');
|
2022-06-20 04:47:14 +00:00
|
|
|
var noteRows = doc.getElementById('zotero-editpane-notes');
|
|
|
|
var grid = noteRows.shadowRoot.getElementById('grid');
|
2017-03-01 06:35:15 +00:00
|
|
|
tabs.selectedItem = notesTab;
|
|
|
|
// Wait for note list to update
|
|
|
|
do {
|
|
|
|
yield Zotero.Promise.delay(1);
|
|
|
|
}
|
2022-06-20 04:47:14 +00:00
|
|
|
while (grid.querySelectorAll('div.box > label').length !== 2);
|
2017-03-01 06:35:15 +00:00
|
|
|
|
|
|
|
// Update note text
|
|
|
|
note2.setNote('C');
|
|
|
|
yield note2.saveTx();
|
|
|
|
|
|
|
|
// Wait for note list to update
|
|
|
|
do {
|
|
|
|
yield Zotero.Promise.delay(1);
|
|
|
|
}
|
2022-06-20 04:47:14 +00:00
|
|
|
while ([...grid.querySelectorAll('div.box > label')].every(label => label.textContent != 'C'));
|
2017-03-01 06:35:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should refresh on child note trash", function* () {
|
|
|
|
var item;
|
|
|
|
var note1;
|
|
|
|
var note2;
|
2020-07-05 10:20:01 +00:00
|
|
|
yield Zotero.DB.executeTransaction(async function () {
|
2017-03-01 06:35:15 +00:00
|
|
|
item = createUnsavedDataObject('item');
|
2020-07-05 10:20:01 +00:00
|
|
|
await item.save();
|
2017-03-01 06:35:15 +00:00
|
|
|
|
|
|
|
note1 = new Zotero.Item('note');
|
|
|
|
note1.parentID = item.id;
|
|
|
|
note1.setNote('A');
|
2020-07-05 10:20:01 +00:00
|
|
|
await note1.save();
|
2017-03-01 06:35:15 +00:00
|
|
|
|
|
|
|
note2 = new Zotero.Item('note');
|
|
|
|
note2.parentID = item.id;
|
|
|
|
note2.setNote('B');
|
2020-07-05 10:20:01 +00:00
|
|
|
await note2.save();
|
2017-03-01 06:35:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var tabs = doc.getElementById('zotero-editpane-tabs');
|
|
|
|
var notesTab = doc.getElementById('zotero-editpane-notes-tab');
|
2022-06-20 04:47:14 +00:00
|
|
|
var noteRows = doc.getElementById('zotero-editpane-notes');
|
|
|
|
var grid = noteRows.shadowRoot.getElementById('grid');
|
2017-03-01 06:35:15 +00:00
|
|
|
tabs.selectedItem = notesTab;
|
|
|
|
// Wait for note list to update
|
|
|
|
do {
|
|
|
|
yield Zotero.Promise.delay(1);
|
|
|
|
}
|
2022-06-20 04:47:14 +00:00
|
|
|
while (grid.querySelectorAll('div.box > label').length !== 2);
|
2017-03-01 06:35:15 +00:00
|
|
|
|
|
|
|
// Click "-" in first note
|
|
|
|
var promise = waitForDialog();
|
2022-06-20 04:47:14 +00:00
|
|
|
grid.querySelector(".zotero-clicky-minus").click();
|
2017-03-01 06:35:15 +00:00
|
|
|
yield promise;
|
|
|
|
|
|
|
|
// Wait for note list to update
|
|
|
|
do {
|
|
|
|
yield Zotero.Promise.delay(1);
|
|
|
|
}
|
2022-06-20 04:47:14 +00:00
|
|
|
while (grid.querySelectorAll('div.box > label').length !== 1);
|
2017-03-01 06:35:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should refresh on child note delete", function* () {
|
|
|
|
var item;
|
|
|
|
var note1;
|
|
|
|
var note2;
|
2020-07-05 10:20:01 +00:00
|
|
|
yield Zotero.DB.executeTransaction(async function () {
|
2017-03-01 06:35:15 +00:00
|
|
|
item = createUnsavedDataObject('item');
|
2020-07-05 10:20:01 +00:00
|
|
|
await item.save();
|
2017-03-01 06:35:15 +00:00
|
|
|
|
|
|
|
note1 = new Zotero.Item('note');
|
|
|
|
note1.parentID = item.id;
|
|
|
|
note1.setNote('A');
|
2020-07-05 10:20:01 +00:00
|
|
|
await note1.save();
|
2017-03-01 06:35:15 +00:00
|
|
|
|
|
|
|
note2 = new Zotero.Item('note');
|
|
|
|
note2.parentID = item.id;
|
|
|
|
note2.setNote('B');
|
2020-07-05 10:20:01 +00:00
|
|
|
await note2.save();
|
2017-03-01 06:35:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var tabs = doc.getElementById('zotero-editpane-tabs');
|
|
|
|
var notesTab = doc.getElementById('zotero-editpane-notes-tab');
|
2022-06-20 04:47:14 +00:00
|
|
|
var noteRows = doc.getElementById('zotero-editpane-notes');
|
|
|
|
var grid = noteRows.shadowRoot.getElementById('grid');
|
2017-03-01 06:35:15 +00:00
|
|
|
tabs.selectedItem = notesTab;
|
|
|
|
// Wait for note list to update
|
|
|
|
do {
|
|
|
|
yield Zotero.Promise.delay(1);
|
|
|
|
}
|
2022-06-20 04:47:14 +00:00
|
|
|
while (grid.querySelectorAll('div.box > label').length !== 2);
|
2017-03-01 06:35:15 +00:00
|
|
|
|
|
|
|
yield note2.eraseTx();
|
|
|
|
|
|
|
|
// Wait for note list to update
|
|
|
|
do {
|
|
|
|
yield Zotero.Promise.delay(1);
|
|
|
|
}
|
2022-06-20 04:47:14 +00:00
|
|
|
while (grid.querySelectorAll('div.box > label').length !== 1);
|
2017-03-01 06:35:15 +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);
|
|
|
|
})
|
2021-05-31 07:25:23 +00:00
|
|
|
|
|
|
|
it("should update on attachment title change", async function () {
|
|
|
|
var file = getTestDataDirectory();
|
|
|
|
file.append('test.png');
|
|
|
|
var item = await Zotero.Attachments.importFromFile({ file });
|
|
|
|
var newTitle = 'New Title';
|
|
|
|
item.setField('title', newTitle);
|
|
|
|
await item.saveTx();
|
|
|
|
|
|
|
|
var itemBox = doc.getElementById('zotero-attachment-box');
|
|
|
|
var label = itemBox._id('title');
|
|
|
|
assert.equal(label.textContent, newTitle);
|
|
|
|
})
|
2015-08-07 19:36:46 +00:00
|
|
|
})
|
|
|
|
|
2017-03-01 06:35:15 +00:00
|
|
|
|
|
|
|
describe("Note editor", function () {
|
2015-05-19 21:05:58 +00:00
|
|
|
it("should refresh on note update", function* () {
|
|
|
|
var item = new Zotero.Item('note');
|
|
|
|
var id = yield item.saveTx();
|
|
|
|
|
2017-08-30 22:22:00 +00:00
|
|
|
var noteEditor = doc.getElementById('zotero-note-editor');
|
|
|
|
|
2015-05-19 21:05:58 +00:00
|
|
|
// Wait for the editor
|
2017-08-30 22:22:00 +00:00
|
|
|
yield new Zotero.Promise((resolve, reject) => {
|
2021-01-13 12:01:44 +00:00
|
|
|
noteEditor.onInit(() => resolve());
|
|
|
|
});
|
|
|
|
assert.equal(noteEditor._editorInstance._iframeWindow.wrappedJSObject.getDataSync(), null);
|
2015-05-19 21:05:58 +00:00
|
|
|
item.setNote('<p>Test</p>');
|
|
|
|
yield item.saveTx();
|
|
|
|
|
2021-01-13 12:01:44 +00:00
|
|
|
// Wait for asynchronous editor update
|
|
|
|
do {
|
|
|
|
yield Zotero.Promise.delay(10);
|
2022-07-25 15:04:00 +00:00
|
|
|
} while (
|
|
|
|
!/<div data-schema-version=".*"><p>Test<\/p><\/div>/.test(
|
|
|
|
noteEditor._editorInstance._iframeWindow.wrappedJSObject.getDataSync().html.replace(/\n/g, '')
|
|
|
|
)
|
|
|
|
);
|
2021-01-13 12:01:44 +00:00
|
|
|
});
|
|
|
|
});
|
2016-03-25 04:49:14 +00:00
|
|
|
|
|
|
|
describe("Feed buttons", function() {
|
|
|
|
describe("Mark as Read/Unread", function() {
|
2017-11-03 08:47:04 +00:00
|
|
|
it("should update label when state of an item changes", function* () {
|
2016-03-25 04:49:14 +00:00
|
|
|
let feed = yield createFeed();
|
|
|
|
yield selectLibrary(win, feed.libraryID);
|
2017-11-03 08:47:04 +00:00
|
|
|
yield waitForItemsLoad(win);
|
|
|
|
|
|
|
|
var stub = sinon.stub(win.ZoteroPane, 'startItemReadTimeout');
|
|
|
|
var item = yield createDataObject('feedItem', { libraryID: feed.libraryID });
|
|
|
|
// Skip timed mark-as-read
|
|
|
|
assert.ok(stub.called);
|
|
|
|
stub.restore();
|
|
|
|
item.isRead = true;
|
|
|
|
yield item.saveTx();
|
|
|
|
|
2016-03-25 04:49:14 +00:00
|
|
|
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'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-06-06 21:16:09 +00:00
|
|
|
|
|
|
|
describe("Duplicates Merge pane", function () {
|
|
|
|
// Same as test in itemsTest, but via UI, which makes a copy via toJSON()/fromJSON()
|
|
|
|
it("should transfer merge-tracking relations when merging two pairs into one item", async function () {
|
|
|
|
var item1 = await createDataObject('item', { title: 'A' });
|
|
|
|
var item2 = await createDataObject('item', { title: 'B' });
|
|
|
|
var item3 = await createDataObject('item', { title: 'C' });
|
|
|
|
var item4 = await createDataObject('item', { title: 'D' });
|
|
|
|
|
|
|
|
var uris = [item2, item3, item4].map(item => Zotero.URI.getItemURI(item));
|
|
|
|
|
|
|
|
var p;
|
|
|
|
|
|
|
|
var zp = win.ZoteroPane;
|
|
|
|
await zp.selectItems([item1.id, item2.id]);
|
|
|
|
zp.mergeSelectedItems();
|
|
|
|
p = waitForItemEvent('modify');
|
|
|
|
doc.getElementById('zotero-duplicates-merge-button').click();
|
|
|
|
await p;
|
|
|
|
|
|
|
|
assert.sameMembers(
|
|
|
|
item1.getRelations()[Zotero.Relations.replacedItemPredicate],
|
|
|
|
[uris[0]]
|
|
|
|
);
|
|
|
|
|
|
|
|
await zp.selectItems([item3.id, item4.id]);
|
|
|
|
zp.mergeSelectedItems();
|
|
|
|
p = waitForItemEvent('modify');
|
|
|
|
doc.getElementById('zotero-duplicates-merge-button').click();
|
|
|
|
await p;
|
|
|
|
|
|
|
|
assert.sameMembers(
|
|
|
|
item3.getRelations()[Zotero.Relations.replacedItemPredicate],
|
|
|
|
[uris[2]]
|
|
|
|
);
|
|
|
|
|
|
|
|
await zp.selectItems([item1.id, item3.id]);
|
|
|
|
zp.mergeSelectedItems();
|
|
|
|
p = waitForItemEvent('modify');
|
|
|
|
doc.getElementById('zotero-duplicates-merge-button').click();
|
|
|
|
await p;
|
|
|
|
|
|
|
|
// Remaining item should include all other URIs
|
|
|
|
assert.sameMembers(
|
|
|
|
item1.getRelations()[Zotero.Relations.replacedItemPredicate],
|
|
|
|
uris
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2015-05-19 21:05:58 +00:00
|
|
|
})
|