1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-13 00:10:37 +02:00

All: Also duplicate resources when duplicating a note

Ref: https://github.com/laurent22/joplin/issues/5796
This commit is contained in:
Laurent Cozic
2021-11-27 16:05:28 +00:00
parent 4ce58fa486
commit c0a8c330a9
3 changed files with 43 additions and 5 deletions

View File

@ -7,6 +7,8 @@ import Folder from './Folder';
import Note from './Note';
import Tag from './Tag';
import ItemChange from './ItemChange';
import Resource from './Resource';
import { ResourceEntity } from '../services/database/types';
const ArrayUtils = require('../ArrayUtils.js');
async function allItems() {
@ -143,6 +145,27 @@ describe('models/Note', function() {
expect(duplicatedNoteTags.length).toBe(2);
}));
it('should also duplicate resources when duplicating a note', (async () => {
const folder = await Folder.save({ title: 'folder' });
let note = await Note.save({ title: 'note', parent_id: folder.id });
await shim.attachFileToNote(note, `${supportDir}/photo.jpg`);
const resource = (await Resource.all())[0];
expect((await Resource.all()).length).toBe(1);
const duplicatedNote = await Note.duplicate(note.id);
const resources: ResourceEntity[] = await Resource.all();
expect(resources.length).toBe(2);
const duplicatedResource = resources.find(r => r.id !== resource.id);
note = await Note.load(note.id);
expect(note.body).toContain(resource.id);
expect(duplicatedNote.body).toContain(duplicatedResource.id);
}));
it('should delete a set of notes', (async () => {
const folder1 = await Folder.save({ title: 'folder1' });
const noOfNotes = 20;