Adjust attachment-title handling on Rename File from Parent Metadata

Don't change the attachment title on a manual rename from metadata if it
doesn't match the current filename, with or without the extension

Closes #3220
This commit is contained in:
Dan Stillman 2023-07-25 01:44:42 -04:00
parent d95c10e06c
commit ed2cae9236
2 changed files with 61 additions and 9 deletions

View file

@ -614,6 +614,51 @@ describe("ZoteroPane", function() {
assert.equal(OS.Path.basename(path), uniqueFilename)
await OS.File.exists(path);
});
it("shouldn't change attachment title if different from filename", async function () {
var item = createUnsavedDataObject('item');
item.setField('title', 'Title');
await item.saveTx();
var attachment = await importFileAttachment('test.png', { parentItemID: item.id });
attachment.setField('title', 'Image');
await attachment.saveTx();
await zp.selectItem(attachment.id);
assert.isTrue(await zp.renameSelectedAttachmentsFromParents());
assert.equal(attachment.attachmentFilename, 'Title.png');
assert.equal(attachment.getField('title'), 'Image')
});
it("should change attachment title if the same as filename", async function () {
var item = createUnsavedDataObject('item');
item.setField('title', 'Title');
await item.saveTx();
var attachment = await importFileAttachment('test.png', { parentItemID: item.id });
attachment.setField('title', 'test.png');
await attachment.saveTx();
await zp.selectItem(attachment.id);
assert.isTrue(await zp.renameSelectedAttachmentsFromParents());
assert.equal(attachment.attachmentFilename, 'Title.png');
assert.equal(attachment.getField('title'), 'Title.png')
});
it("should change attachment title if the same as filename without extension", async function () {
var item = createUnsavedDataObject('item');
item.setField('title', 'Title');
await item.saveTx();
var attachment = await importFileAttachment('test.png', { parentItemID: item.id });
attachment.setField('title', 'test');
await attachment.saveTx();
await zp.selectItem(attachment.id);
assert.isTrue(await zp.renameSelectedAttachmentsFromParents());
assert.equal(attachment.attachmentFilename, 'Title.png');
assert.equal(attachment.getField('title'), 'Title.png')
});
});