Tests: Fix importFileAttachment() logic, update outdated test (#4475)

After dd16017
This commit is contained in:
Abe Jellinek 2024-07-31 16:24:19 -04:00 committed by GitHub
parent 374dab2cb4
commit 804b2d1216
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 6 deletions

View file

@ -1005,9 +1005,12 @@ function importFileAttachment(filename, options = {}) {
parentItemID: options.parentID, parentItemID: options.parentID,
}; };
Object.assign(importOptions, options); Object.assign(importOptions, options);
// Override default behavior - don't set title based on type, // If the caller didn't pass anything as title (null counts as something),
// just use extension-less leafName // override default Zotero.Attachments.importFromFile() behavior - don't
if (!('title' in importOptions)) { // 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(/\.[^.]+$/, ''); importOptions.title = file.leafName.replace(/\.[^.]+$/, '');
} }
return Zotero.Attachments.importFromFile(importOptions); return Zotero.Attachments.importFromFile(importOptions);

View file

@ -314,10 +314,10 @@ describe("Document Recognition", function() {
// The file should not have been renamed // The file should not have been renamed
assert.equal(attachment.attachmentFilename, 'test.pdf'); assert.equal(attachment.attachmentFilename, 'test.pdf');
// The title should have changed // The title should not have changed
assert.equal( assert.equal(
attachment.getField('title'), attachment.getField('title'),
Zotero.getString('file-type-pdf') 'test'
); );
}); });
}); });

View file

@ -681,7 +681,7 @@ describe("ZoteroPane", function() {
// Use default setAutoAttachmentTitle() behavior -- the file isn't going to be // Use default setAutoAttachmentTitle() behavior -- the file isn't going to be
// renamed because autoRenameFiles.fileTypes doesn't match image/, so the title // renamed because autoRenameFiles.fileTypes doesn't match image/, so the title
// becomes the filename minus extension, i.e., "test" // becomes the filename minus extension, i.e., "test"
title: undefined title: null
}); });
assert.equal(attachment.getField('title'), 'test'); assert.equal(attachment.getField('title'), 'test');
await zp.selectItem(attachment.id); await zp.selectItem(attachment.id);