1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

All: Fix calls to non-existent function (#2675)

* Fix calls to non-existent function

* Add tests.

* Fix travis lint problems.
This commit is contained in:
mic704b 2020-03-16 08:53:49 +11:00 committed by GitHub
parent 9b562276f3
commit 63a2f7b7a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 14 deletions

View File

@ -93,10 +93,10 @@ describe('integration_ShowAllNotes', function() {
it('should support note duplication', asyncTest(async () => { it('should support note duplication', asyncTest(async () => {
// setup // setup
let folder1 = await Folder.save({ title: 'folder1' }); const folder1 = await Folder.save({ title: 'folder1' });
let folder2 = await Folder.save({ title: 'folder2' }); const folder2 = await Folder.save({ title: 'folder2' });
let note1 = await Note.save({ title: 'note1', parent_id: folder1.id }); const note1 = await Note.save({ title: 'note1', parent_id: folder1.id });
let note2 = await Note.save({ title: 'note2', parent_id: folder2.id }); const note2 = await Note.save({ title: 'note2', parent_id: folder2.id });
testApp.dispatch({ type: 'FOLDER_SELECT', id: folder1.id }); // active folder testApp.dispatch({ type: 'FOLDER_SELECT', id: folder1.id }); // active folder
await time.msleep(100); await time.msleep(100);
testApp.dispatch({ type: 'NOTE_SELECT', id: note1.id }); testApp.dispatch({ type: 'NOTE_SELECT', id: note1.id });
@ -130,10 +130,10 @@ describe('integration_ShowAllNotes', function() {
it('should support changing the note parent', asyncTest(async () => { it('should support changing the note parent', asyncTest(async () => {
// setup // setup
let folder1 = await Folder.save({ title: 'folder1' }); const folder1 = await Folder.save({ title: 'folder1' });
let folder2 = await Folder.save({ title: 'folder2' }); const folder2 = await Folder.save({ title: 'folder2' });
let note1 = await Note.save({ title: 'note1', parent_id: folder1.id }); const note1 = await Note.save({ title: 'note1', parent_id: folder1.id });
let note2 = await Note.save({ title: 'note1', parent_id: folder2.id }); const note2 = await Note.save({ title: 'note1', parent_id: folder2.id });
testApp.dispatch({ type: 'FOLDER_SELECT', id: folder1.id }); // active folder testApp.dispatch({ type: 'FOLDER_SELECT', id: folder1.id }); // active folder
await time.msleep(100); await time.msleep(100);
testApp.dispatch({ type: 'NOTE_SELECT', id: note1.id }); testApp.dispatch({ type: 'NOTE_SELECT', id: note1.id });

View File

@ -58,11 +58,11 @@ describe('models_BaseItem', function() {
})); }));
it('should correctly unserialize note timestamps', asyncTest(async () => { it('should correctly unserialize note timestamps', asyncTest(async () => {
let folder = await Folder.save({ title: 'folder' }); const folder = await Folder.save({ title: 'folder' });
let note = await Note.save({ title: 'note', parent_id: folder.id }); const note = await Note.save({ title: 'note', parent_id: folder.id });
let serialized = await Note.serialize(note); const serialized = await Note.serialize(note);
let unserialized = await Note.unserialize(serialized); const unserialized = await Note.unserialize(serialized);
expect(unserialized.created_time).toEqual(note.created_time); expect(unserialized.created_time).toEqual(note.created_time);
expect(unserialized.updated_time).toEqual(note.updated_time); expect(unserialized.updated_time).toEqual(note.updated_time);

View File

@ -195,4 +195,25 @@ describe('models_Note', function() {
expect(sortedIds(afterDelete)).toEqual(sortedIds(beforeDelete)); expect(sortedIds(afterDelete)).toEqual(sortedIds(beforeDelete));
})); }));
it('should not move to conflict folder', asyncTest(async () => {
const folder1 = await Folder.save({ title: 'Folder' });
const folder2 = await Folder.save({ title: Folder.conflictFolderTitle(), id: Folder.conflictFolderId() });
const note1 = await Note.save({ title: 'note', parent_id: folder1.id });
const hasThrown = await checkThrowAsync(async () => await Folder.moveToFolder(note1.id, folder2.id));
expect(hasThrown).toBe(true);
const note = await Note.load(note1.id);
expect(note.parent_id).toEqual(folder1.id);
}));
it('should not copy to conflict folder', asyncTest(async () => {
const folder1 = await Folder.save({ title: 'Folder' });
const folder2 = await Folder.save({ title: Folder.conflictFolderTitle(), id: Folder.conflictFolderId() });
const note1 = await Note.save({ title: 'note', parent_id: folder1.id });
const hasThrown = await checkThrowAsync(async () => await Folder.copyToFolder(note1.id, folder2.id));
expect(hasThrown).toBe(true);
}));
}); });

View File

@ -448,7 +448,7 @@ class Note extends BaseItem {
} }
static async copyToFolder(noteId, folderId) { static async copyToFolder(noteId, folderId) {
if (folderId == this.getClass('Folder').conflictFolderId()) throw new Error(_('Cannot copy note to "%s" notebook', this.getClass('Folder').conflictFolderIdTitle())); if (folderId == this.getClass('Folder').conflictFolderId()) throw new Error(_('Cannot copy note to "%s" notebook', this.getClass('Folder').conflictFolderTitle()));
return Note.duplicate(noteId, { return Note.duplicate(noteId, {
changes: { changes: {
@ -459,7 +459,7 @@ class Note extends BaseItem {
} }
static async moveToFolder(noteId, folderId) { static async moveToFolder(noteId, folderId) {
if (folderId == this.getClass('Folder').conflictFolderId()) throw new Error(_('Cannot move note to "%s" notebook', this.getClass('Folder').conflictFolderIdTitle())); if (folderId == this.getClass('Folder').conflictFolderId()) throw new Error(_('Cannot move note to "%s" notebook', this.getClass('Folder').conflictFolderTitle()));
// When moving a note to a different folder, the user timestamp is not updated. // When moving a note to a different folder, the user timestamp is not updated.
// However updated_time is updated so that the note can be synced later on. // However updated_time is updated so that the note can be synced later on.