mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
This commit is contained in:
parent
313587097a
commit
385fe7bbe0
@ -70,4 +70,25 @@ describe('onFolderDrop', () => {
|
||||
expect(n1.parent_id).toBe(folder2.id);
|
||||
});
|
||||
|
||||
it('should drop a non-deleted folder to the virtual root notebook', async () => {
|
||||
const folder1 = await Folder.save({});
|
||||
const folder2 = await Folder.save({ parent_id: folder1.id });
|
||||
|
||||
await onFolderDrop([], [folder2.id], '');
|
||||
|
||||
const folder2Reloaded = await Folder.load(folder2.id);
|
||||
expect(folder2Reloaded.parent_id).toBe(folder1.parent_id);
|
||||
expect(folder2Reloaded.parent_id).toBe('');
|
||||
});
|
||||
|
||||
it('should drop a deleted folder to the virtual root notebook', async () => {
|
||||
const folder1 = await Folder.save({});
|
||||
await Folder.delete(folder1.id, { toTrash: true });
|
||||
|
||||
await onFolderDrop([], [folder1.id], '');
|
||||
|
||||
const folder1Reloaded = await Folder.load(folder1.id);
|
||||
expect(folder1Reloaded.parent_id).toBe('');
|
||||
expect(folder1Reloaded.deleted_time).toBe(0);
|
||||
});
|
||||
});
|
||||
|
@ -5,8 +5,19 @@ import restoreItems from '../../services/trash/restoreItems';
|
||||
import Folder from '../Folder';
|
||||
import Note from '../Note';
|
||||
|
||||
const rootFolder = {
|
||||
id: '',
|
||||
deleted_time: 0,
|
||||
type_: ModelType.Folder,
|
||||
};
|
||||
|
||||
export default async (noteIds: string[], folderIds: string[], targetFolderId: string) => {
|
||||
const targetFolder = await Folder.load(targetFolderId, { fields: ['id', 'deleted_time'] });
|
||||
let targetFolder: FolderEntity;
|
||||
if (targetFolderId !== '') {
|
||||
targetFolder = await Folder.load(targetFolderId, { fields: ['id', 'deleted_time'] });
|
||||
} else {
|
||||
targetFolder = rootFolder;
|
||||
}
|
||||
|
||||
if (!targetFolder) throw new Error(`No such folder: ${targetFolderId}`);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user