2023-07-16 18:42:42 +02:00
|
|
|
import { ErrorCode } from '../errors';
|
2021-05-21 15:17:21 +02:00
|
|
|
import { FolderEntity } from '../services/database/types';
|
2023-07-16 18:42:42 +02:00
|
|
|
import { createNTestNotes, setupDatabaseAndSynchronizer, sleep, switchClient, checkThrowAsync, createFolderTree, simulateReadOnlyShareEnv, expectThrow } from '../testing/test-utils';
|
2021-05-21 15:17:21 +02:00
|
|
|
import Folder from './Folder';
|
|
|
|
import Note from './Note';
|
2018-05-09 10:53:47 +02:00
|
|
|
|
|
|
|
async function allItems() {
|
2020-03-14 01:46:14 +02:00
|
|
|
const folders = await Folder.all();
|
|
|
|
const notes = await Note.all();
|
2018-05-09 10:53:47 +02:00
|
|
|
return folders.concat(notes);
|
|
|
|
}
|
|
|
|
|
2023-02-20 17:02:29 +02:00
|
|
|
describe('models/Folder', () => {
|
2018-05-09 10:53:47 +02:00
|
|
|
|
2022-11-15 12:23:50 +02:00
|
|
|
beforeEach(async () => {
|
2018-05-09 10:53:47 +02:00
|
|
|
await setupDatabaseAndSynchronizer(1);
|
|
|
|
await switchClient(1);
|
|
|
|
});
|
|
|
|
|
2023-07-16 18:42:42 +02:00
|
|
|
it('should tell if a folder can be nested under another one', (async () => {
|
2020-03-14 01:46:14 +02:00
|
|
|
const f1 = await Folder.save({ title: 'folder1' });
|
|
|
|
const f2 = await Folder.save({ title: 'folder2', parent_id: f1.id });
|
|
|
|
const f3 = await Folder.save({ title: 'folder3', parent_id: f2.id });
|
|
|
|
const f4 = await Folder.save({ title: 'folder4' });
|
2018-05-09 10:53:47 +02:00
|
|
|
|
|
|
|
expect(await Folder.canNestUnder(f1.id, f2.id)).toBe(false);
|
|
|
|
expect(await Folder.canNestUnder(f2.id, f2.id)).toBe(false);
|
|
|
|
expect(await Folder.canNestUnder(f3.id, f1.id)).toBe(true);
|
|
|
|
expect(await Folder.canNestUnder(f4.id, f1.id)).toBe(true);
|
|
|
|
expect(await Folder.canNestUnder(f2.id, f3.id)).toBe(false);
|
|
|
|
expect(await Folder.canNestUnder(f3.id, f2.id)).toBe(true);
|
|
|
|
expect(await Folder.canNestUnder(f1.id, '')).toBe(true);
|
|
|
|
expect(await Folder.canNestUnder(f2.id, '')).toBe(true);
|
|
|
|
}));
|
|
|
|
|
2023-07-16 18:42:42 +02:00
|
|
|
it('should recursively delete notes and sub-folders', (async () => {
|
2020-03-14 01:46:14 +02:00
|
|
|
const f1 = await Folder.save({ title: 'folder1' });
|
|
|
|
const f2 = await Folder.save({ title: 'folder2', parent_id: f1.id });
|
2020-03-14 12:01:45 +02:00
|
|
|
const f3 = await Folder.save({ title: 'folder3', parent_id: f2.id });
|
|
|
|
const f4 = await Folder.save({ title: 'folder4', parent_id: f1.id });
|
|
|
|
|
|
|
|
const noOfNotes = 20;
|
|
|
|
await createNTestNotes(noOfNotes, f1, null, 'note1');
|
|
|
|
await createNTestNotes(noOfNotes, f2, null, 'note2');
|
|
|
|
await createNTestNotes(noOfNotes, f3, null, 'note3');
|
|
|
|
await createNTestNotes(noOfNotes, f4, null, 'note4');
|
2018-05-09 10:53:47 +02:00
|
|
|
|
|
|
|
await Folder.delete(f1.id);
|
|
|
|
|
|
|
|
const all = await allItems();
|
|
|
|
expect(all.length).toBe(0);
|
|
|
|
}));
|
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should sort by last modified, based on content', (async () => {
|
2019-03-02 19:35:57 +02:00
|
|
|
let folders;
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const f1 = await Folder.save({ title: 'folder1' }); await sleep(0.1);
|
|
|
|
const f2 = await Folder.save({ title: 'folder2' }); await sleep(0.1);
|
|
|
|
const f3 = await Folder.save({ title: 'folder3' }); await sleep(0.1);
|
|
|
|
const n1 = await Note.save({ title: 'note1', parent_id: f2.id });
|
2019-03-02 19:35:57 +02:00
|
|
|
|
|
|
|
folders = await Folder.orderByLastModified(await Folder.all(), 'desc');
|
|
|
|
expect(folders.length).toBe(3);
|
|
|
|
expect(folders[0].id).toBe(f2.id);
|
|
|
|
expect(folders[1].id).toBe(f3.id);
|
|
|
|
expect(folders[2].id).toBe(f1.id);
|
|
|
|
|
2020-11-14 14:37:18 +02:00
|
|
|
await Note.save({ title: 'note1', parent_id: f1.id });
|
2019-03-02 19:35:57 +02:00
|
|
|
|
|
|
|
folders = await Folder.orderByLastModified(await Folder.all(), 'desc');
|
|
|
|
expect(folders[0].id).toBe(f1.id);
|
|
|
|
expect(folders[1].id).toBe(f2.id);
|
|
|
|
expect(folders[2].id).toBe(f3.id);
|
|
|
|
|
|
|
|
await Note.save({ id: n1.id, title: 'note1 mod' });
|
|
|
|
|
|
|
|
folders = await Folder.orderByLastModified(await Folder.all(), 'desc');
|
|
|
|
expect(folders[0].id).toBe(f2.id);
|
|
|
|
expect(folders[1].id).toBe(f1.id);
|
|
|
|
expect(folders[2].id).toBe(f3.id);
|
|
|
|
|
|
|
|
folders = await Folder.orderByLastModified(await Folder.all(), 'asc');
|
|
|
|
expect(folders[0].id).toBe(f3.id);
|
|
|
|
expect(folders[1].id).toBe(f1.id);
|
|
|
|
expect(folders[2].id).toBe(f2.id);
|
|
|
|
}));
|
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should sort by last modified, based on content (sub-folders too)', (async () => {
|
2019-03-02 19:35:57 +02:00
|
|
|
let folders;
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const f1 = await Folder.save({ title: 'folder1' }); await sleep(0.1);
|
|
|
|
const f2 = await Folder.save({ title: 'folder2' }); await sleep(0.1);
|
|
|
|
const f3 = await Folder.save({ title: 'folder3', parent_id: f1.id }); await sleep(0.1);
|
|
|
|
const n1 = await Note.save({ title: 'note1', parent_id: f3.id });
|
2019-03-02 19:35:57 +02:00
|
|
|
|
|
|
|
folders = await Folder.orderByLastModified(await Folder.all(), 'desc');
|
|
|
|
expect(folders.length).toBe(3);
|
|
|
|
expect(folders[0].id).toBe(f1.id);
|
|
|
|
expect(folders[1].id).toBe(f3.id);
|
|
|
|
expect(folders[2].id).toBe(f2.id);
|
2019-03-10 23:16:05 +02:00
|
|
|
|
2020-11-14 14:37:18 +02:00
|
|
|
await Note.save({ title: 'note2', parent_id: f2.id });
|
2019-03-10 23:16:05 +02:00
|
|
|
folders = await Folder.orderByLastModified(await Folder.all(), 'desc');
|
|
|
|
|
|
|
|
expect(folders[0].id).toBe(f2.id);
|
|
|
|
expect(folders[1].id).toBe(f1.id);
|
|
|
|
expect(folders[2].id).toBe(f3.id);
|
|
|
|
|
|
|
|
await Note.save({ id: n1.id, title: 'note1 MOD' });
|
2019-07-30 09:35:42 +02:00
|
|
|
|
2019-03-10 23:16:05 +02:00
|
|
|
folders = await Folder.orderByLastModified(await Folder.all(), 'desc');
|
|
|
|
expect(folders[0].id).toBe(f1.id);
|
|
|
|
expect(folders[1].id).toBe(f3.id);
|
|
|
|
expect(folders[2].id).toBe(f2.id);
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const f4 = await Folder.save({ title: 'folder4', parent_id: f1.id }); await sleep(0.1);
|
2020-11-14 14:37:18 +02:00
|
|
|
await Note.save({ title: 'note3', parent_id: f4.id });
|
2019-03-10 23:16:05 +02:00
|
|
|
|
|
|
|
folders = await Folder.orderByLastModified(await Folder.all(), 'desc');
|
|
|
|
expect(folders.length).toBe(4);
|
2019-04-02 01:22:04 +02:00
|
|
|
expect(folders[0].id).toBe(f1.id);
|
|
|
|
expect(folders[1].id).toBe(f4.id);
|
2019-03-10 23:16:05 +02:00
|
|
|
expect(folders[2].id).toBe(f3.id);
|
|
|
|
expect(folders[3].id).toBe(f2.id);
|
2019-03-02 19:35:57 +02:00
|
|
|
}));
|
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should add node counts', (async () => {
|
2020-03-14 01:46:14 +02:00
|
|
|
const f1 = await Folder.save({ title: 'folder1' });
|
|
|
|
const f2 = await Folder.save({ title: 'folder2', parent_id: f1.id });
|
|
|
|
const f3 = await Folder.save({ title: 'folder3', parent_id: f2.id });
|
|
|
|
const f4 = await Folder.save({ title: 'folder4' });
|
2019-11-11 08:14:56 +02:00
|
|
|
|
2020-11-14 14:37:18 +02:00
|
|
|
await Note.save({ title: 'note1', parent_id: f3.id });
|
|
|
|
await Note.save({ title: 'note1', parent_id: f3.id });
|
|
|
|
await Note.save({ title: 'note1', parent_id: f1.id });
|
|
|
|
await Note.save({ title: 'conflicted', parent_id: f1.id, is_conflict: 1 });
|
|
|
|
|
|
|
|
{
|
|
|
|
const folders = await Folder.all({ includeConflictFolder: false });
|
|
|
|
await Folder.addNoteCounts(folders);
|
|
|
|
const foldersById: any = {};
|
2023-06-30 10:39:21 +02:00
|
|
|
// eslint-disable-next-line github/array-foreach -- Old code before rule was applied
|
2020-11-14 14:37:18 +02:00
|
|
|
folders.forEach((f: FolderEntity) => { foldersById[f.id] = f; });
|
|
|
|
|
|
|
|
expect(folders.length).toBe(4);
|
|
|
|
expect(foldersById[f1.id].note_count).toBe(3);
|
|
|
|
expect(foldersById[f2.id].note_count).toBe(2);
|
|
|
|
expect(foldersById[f3.id].note_count).toBe(2);
|
|
|
|
expect(foldersById[f4.id].note_count).toBe(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const folders = await Folder.all({ includeConflictFolder: true });
|
|
|
|
await Folder.addNoteCounts(folders);
|
|
|
|
const foldersById: any = {};
|
2023-06-30 10:39:21 +02:00
|
|
|
// eslint-disable-next-line github/array-foreach -- Old code before rule was applied
|
2020-11-14 14:37:18 +02:00
|
|
|
folders.forEach((f: FolderEntity) => { foldersById[f.id] = f; });
|
|
|
|
|
|
|
|
expect(folders.length).toBe(5);
|
|
|
|
expect(foldersById[Folder.conflictFolderId()].note_count).toBe(1);
|
|
|
|
}
|
2019-11-11 08:14:56 +02:00
|
|
|
}));
|
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should not count completed to-dos', (async () => {
|
2020-01-18 15:46:04 +02:00
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const f1 = await Folder.save({ title: 'folder1' });
|
|
|
|
const f2 = await Folder.save({ title: 'folder2', parent_id: f1.id });
|
|
|
|
const f3 = await Folder.save({ title: 'folder3', parent_id: f2.id });
|
|
|
|
const f4 = await Folder.save({ title: 'folder4' });
|
2020-01-18 15:46:04 +02:00
|
|
|
|
2020-11-14 14:37:18 +02:00
|
|
|
await Note.save({ title: 'note1', parent_id: f3.id });
|
|
|
|
await Note.save({ title: 'note2', parent_id: f3.id });
|
|
|
|
await Note.save({ title: 'note3', parent_id: f1.id });
|
2021-01-22 19:41:11 +02:00
|
|
|
await Note.save({ title: 'note4', parent_id: f3.id, is_todo: 1, todo_completed: 0 });
|
|
|
|
await Note.save({ title: 'note5', parent_id: f3.id, is_todo: 1, todo_completed: 999 });
|
|
|
|
await Note.save({ title: 'note6', parent_id: f3.id, is_todo: 1, todo_completed: 999 });
|
2020-01-18 15:46:04 +02:00
|
|
|
|
|
|
|
const folders = await Folder.all();
|
|
|
|
await Folder.addNoteCounts(folders, false);
|
|
|
|
|
2020-11-14 14:37:18 +02:00
|
|
|
const foldersById: any = {};
|
2023-06-30 10:39:21 +02:00
|
|
|
// eslint-disable-next-line github/array-foreach -- Old code before rule was applied
|
2020-11-14 14:37:18 +02:00
|
|
|
folders.forEach((f: FolderEntity) => { foldersById[f.id] = f; });
|
2020-01-18 15:46:04 +02:00
|
|
|
|
|
|
|
expect(folders.length).toBe(4);
|
|
|
|
expect(foldersById[f1.id].note_count).toBe(4);
|
|
|
|
expect(foldersById[f2.id].note_count).toBe(3);
|
|
|
|
expect(foldersById[f3.id].note_count).toBe(3);
|
|
|
|
expect(foldersById[f4.id].note_count).toBe(0);
|
|
|
|
}));
|
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should recursively find folder path', (async () => {
|
2020-03-14 01:46:14 +02:00
|
|
|
const f1 = await Folder.save({ title: 'folder1' });
|
|
|
|
const f2 = await Folder.save({ title: 'folder2', parent_id: f1.id });
|
|
|
|
const f3 = await Folder.save({ title: 'folder3', parent_id: f2.id });
|
2020-03-11 16:20:25 +02:00
|
|
|
|
|
|
|
const folders = await Folder.all();
|
|
|
|
const folderPath = await Folder.folderPath(folders, f3.id);
|
|
|
|
|
|
|
|
expect(folderPath.length).toBe(3);
|
|
|
|
expect(folderPath[0].id).toBe(f1.id);
|
|
|
|
expect(folderPath[1].id).toBe(f2.id);
|
|
|
|
expect(folderPath[2].id).toBe(f3.id);
|
|
|
|
}));
|
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should sort folders alphabetically', (async () => {
|
2020-05-09 17:19:30 +02:00
|
|
|
const f1 = await Folder.save({ title: 'folder1' });
|
|
|
|
const f2 = await Folder.save({ title: 'folder2', parent_id: f1.id });
|
|
|
|
const f3 = await Folder.save({ title: 'folder3', parent_id: f1.id });
|
|
|
|
const f4 = await Folder.save({ title: 'folder4' });
|
|
|
|
const f5 = await Folder.save({ title: 'folder5', parent_id: f4.id });
|
|
|
|
const f6 = await Folder.save({ title: 'folder6' });
|
|
|
|
|
|
|
|
const folders = await Folder.allAsTree();
|
|
|
|
const sortedFolderTree = await Folder.sortFolderTree(folders);
|
|
|
|
|
|
|
|
expect(sortedFolderTree.length).toBe(3);
|
|
|
|
expect(sortedFolderTree[0].id).toBe(f1.id);
|
|
|
|
expect(sortedFolderTree[0].children[0].id).toBe(f2.id);
|
|
|
|
expect(sortedFolderTree[0].children[1].id).toBe(f3.id);
|
|
|
|
expect(sortedFolderTree[1].id).toBe(f4.id);
|
|
|
|
expect(sortedFolderTree[1].children[0].id).toBe(f5.id);
|
|
|
|
expect(sortedFolderTree[2].id).toBe(f6.id);
|
|
|
|
}));
|
2020-06-07 13:47:43 +02:00
|
|
|
|
2023-07-16 18:42:42 +02:00
|
|
|
it('should not allow setting a folder parent as itself', (async () => {
|
2020-06-07 13:47:43 +02:00
|
|
|
const f1 = await Folder.save({ title: 'folder1' });
|
|
|
|
const hasThrown = await checkThrowAsync(() => Folder.save({ id: f1.id, parent_id: f1.id }, { userSideValidation: true }));
|
|
|
|
expect(hasThrown).toBe(true);
|
|
|
|
}));
|
2021-05-13 18:57:37 +02:00
|
|
|
|
|
|
|
it('should get all the children of a folder', (async () => {
|
|
|
|
const folder = await createFolderTree('', [
|
|
|
|
{
|
|
|
|
title: 'folder 1',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'note 1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'note 2',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'folder 2',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'note 3',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'folder 3',
|
|
|
|
children: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'folder 4',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'folder 5',
|
|
|
|
children: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
const folder2 = await Folder.loadByTitle('folder 2');
|
|
|
|
const folder3 = await Folder.loadByTitle('folder 3');
|
|
|
|
const folder4 = await Folder.loadByTitle('folder 4');
|
|
|
|
const folder5 = await Folder.loadByTitle('folder 5');
|
|
|
|
|
|
|
|
{
|
|
|
|
const children = await Folder.allChildrenFolders(folder.id);
|
|
|
|
expect(children.map(c => c.id).sort()).toEqual([folder2.id, folder3.id].sort());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const children = await Folder.allChildrenFolders(folder4.id);
|
|
|
|
expect(children.map(c => c.id).sort()).toEqual([folder5.id].sort());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const children = await Folder.allChildrenFolders(folder5.id);
|
|
|
|
expect(children.map(c => c.id).sort()).toEqual([].sort());
|
|
|
|
}
|
|
|
|
}));
|
2023-07-16 18:42:42 +02:00
|
|
|
|
|
|
|
it('should not allow creating a new folder as a child of a read-only folder', async () => {
|
|
|
|
const cleanup = simulateReadOnlyShareEnv('123456789');
|
|
|
|
|
|
|
|
const readonlyFolder = await Folder.save({ share_id: '123456789' });
|
|
|
|
await expectThrow(async () => Folder.save({ parent_id: readonlyFolder.id }), ErrorCode.IsReadOnly);
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not allow moving a folder as a child of a read-only folder', async () => {
|
|
|
|
const cleanup = simulateReadOnlyShareEnv('123456789');
|
|
|
|
|
|
|
|
const readonlyFolder = await Folder.save({ share_id: '123456789' });
|
|
|
|
const folder = await Folder.save({});
|
|
|
|
await expectThrow(async () => Folder.save({ id: folder.id, parent_id: readonlyFolder.id }), ErrorCode.IsReadOnly);
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not allow modifying a read-only folder', async () => {
|
|
|
|
const cleanup = simulateReadOnlyShareEnv('123456789');
|
|
|
|
|
|
|
|
const readonlyFolder = await Folder.save({ share_id: '123456789' });
|
|
|
|
await expectThrow(async () => Folder.save({ id: readonlyFolder.id, title: 'cannot do that' }), ErrorCode.IsReadOnly);
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not allow deleting a read-only folder', async () => {
|
|
|
|
const cleanup = simulateReadOnlyShareEnv('123456789');
|
|
|
|
|
|
|
|
const readonlyFolder = await Folder.save({ share_id: '123456789' });
|
|
|
|
await expectThrow(async () => Folder.delete(readonlyFolder.id), ErrorCode.IsReadOnly);
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
2024-03-02 16:25:27 +02:00
|
|
|
it('should allow deleting a folder to trash', async () => {
|
|
|
|
const folder1 = await Folder.save({});
|
|
|
|
const folder2 = await Folder.save({});
|
|
|
|
const note1 = await Note.save({ parent_id: folder1.id });
|
|
|
|
const note2 = await Note.save({ parent_id: folder1.id });
|
|
|
|
const note3 = await Note.save({ parent_id: folder2.id });
|
|
|
|
|
|
|
|
const beforeTime = Date.now();
|
|
|
|
await Folder.delete(folder1.id, { toTrash: true, deleteChildren: true });
|
|
|
|
|
|
|
|
expect((await Folder.load(folder1.id)).deleted_time).toBeGreaterThanOrEqual(beforeTime);
|
|
|
|
expect((await Folder.load(folder2.id)).deleted_time).toBe(0);
|
|
|
|
expect((await Note.load(note1.id)).deleted_time).toBeGreaterThanOrEqual(beforeTime);
|
|
|
|
expect((await Note.load(note2.id)).deleted_time).toBeGreaterThanOrEqual(beforeTime);
|
|
|
|
expect((await Note.load(note3.id)).deleted_time).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete and set the parent ID', async () => {
|
|
|
|
const folder1 = await Folder.save({});
|
|
|
|
const folder2 = await Folder.save({});
|
|
|
|
|
|
|
|
await Folder.delete(folder1.id, { toTrash: true });
|
|
|
|
await Folder.delete(folder2.id, { toTrash: true, toTrashParentId: folder1.id });
|
|
|
|
|
|
|
|
expect((await Folder.load(folder2.id)).parent_id).toBe(folder1.id);
|
|
|
|
|
|
|
|
// But it should not allow moving a folder to itself
|
|
|
|
await expectThrow(async () => Folder.delete(folder2.id, { toTrash: true, toTrashParentId: folder2.id }));
|
|
|
|
});
|
|
|
|
|
2024-03-20 12:53:36 +02:00
|
|
|
it('should filter out the trash folder and the deleted folders', async () => {
|
|
|
|
let folders: FolderEntity[] = [];
|
|
|
|
|
|
|
|
expect(Folder.getRealFolders(folders).length).toBe(0);
|
|
|
|
|
|
|
|
const folder1 = await Folder.save({});
|
|
|
|
const folder2 = await Folder.save({ parent_id: folder1.id });
|
|
|
|
const folder3 = await Folder.save({ parent_id: folder2.id });
|
|
|
|
|
|
|
|
folders = await Folder.all();
|
|
|
|
expect(Folder.getRealFolders(folders).sort((a, b) => a.created_time - b.created_time)).toEqual([folder1, folder2, folder3]);
|
|
|
|
|
|
|
|
await Folder.delete(folder2.id, { toTrash: true });
|
|
|
|
folders = await Folder.all();
|
|
|
|
expect(Folder.getRealFolders(folders)).toEqual([folder1]);
|
|
|
|
|
|
|
|
await Folder.delete(folder1.id, { toTrash: true });
|
|
|
|
folders = await Folder.all();
|
|
|
|
expect(Folder.getRealFolders(folders).length).toBe(0);
|
|
|
|
});
|
|
|
|
|
2024-03-11 17:22:26 +02:00
|
|
|
it('should tell if at least one folder other than trash and deleted exists', async () => {
|
|
|
|
let folders: FolderEntity[] = [];
|
|
|
|
expect(Folder.atLeastOneRealFolderExists(folders)).toBe(false);
|
|
|
|
|
|
|
|
folders = await Folder.all({ includeTrash: true });
|
|
|
|
expect(Folder.atLeastOneRealFolderExists(folders)).toBe(false);
|
|
|
|
|
|
|
|
const f1 = await Folder.save({ title: 'folder1' });
|
|
|
|
folders = await Folder.all({ includeTrash: true });
|
|
|
|
expect(Folder.atLeastOneRealFolderExists(folders)).toBe(true);
|
|
|
|
|
|
|
|
await Folder.delete(f1.id, { toTrash: true });
|
|
|
|
folders = await Folder.all({ includeTrash: true });
|
|
|
|
expect(Folder.atLeastOneRealFolderExists(folders)).toBe(false);
|
|
|
|
});
|
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
});
|