Tests: Fix importFileAttachment()
logic, update outdated test (#4475)
After dd16017
This commit is contained in:
parent
374dab2cb4
commit
804b2d1216
3 changed files with 9 additions and 6 deletions
|
@ -1005,9 +1005,12 @@ function importFileAttachment(filename, options = {}) {
|
|||
parentItemID: options.parentID,
|
||||
};
|
||||
Object.assign(importOptions, options);
|
||||
// Override default behavior - don't set title based on type,
|
||||
// just use extension-less leafName
|
||||
if (!('title' in importOptions)) {
|
||||
// If the caller didn't pass anything as title (null counts as something),
|
||||
// override default Zotero.Attachments.importFromFile() behavior - don't
|
||||
// set the title based on the attachment type and existing attachments,
|
||||
// just use the extension-less leafName. Makes titles deterministic and not
|
||||
// dependent on existing attachments, which is better for tests.
|
||||
if (importOptions.title === undefined) {
|
||||
importOptions.title = file.leafName.replace(/\.[^.]+$/, '');
|
||||
}
|
||||
return Zotero.Attachments.importFromFile(importOptions);
|
||||
|
|
|
@ -314,10 +314,10 @@ describe("Document Recognition", function() {
|
|||
// The file should not have been renamed
|
||||
assert.equal(attachment.attachmentFilename, 'test.pdf');
|
||||
|
||||
// The title should have changed
|
||||
// The title should not have changed
|
||||
assert.equal(
|
||||
attachment.getField('title'),
|
||||
Zotero.getString('file-type-pdf')
|
||||
'test'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -681,7 +681,7 @@ describe("ZoteroPane", function() {
|
|||
// Use default setAutoAttachmentTitle() behavior -- the file isn't going to be
|
||||
// renamed because autoRenameFiles.fileTypes doesn't match image/, so the title
|
||||
// becomes the filename minus extension, i.e., "test"
|
||||
title: undefined
|
||||
title: null
|
||||
});
|
||||
assert.equal(attachment.getField('title'), 'test');
|
||||
await zp.selectItem(attachment.id);
|
||||
|
|
Loading…
Add table
Reference in a new issue