mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-23 18:53:36 +02:00
This commit is contained in:
parent
a67eab46f4
commit
0aef1f95ef
@ -5,6 +5,7 @@ import markdownUtils from '@joplin/lib/markdownUtils';
|
|||||||
const { sortedIds, createNTestNotes, setupDatabaseAndSynchronizer, switchClient, checkThrowAsync } = require('./test-utils.js');
|
const { sortedIds, createNTestNotes, setupDatabaseAndSynchronizer, switchClient, checkThrowAsync } = require('./test-utils.js');
|
||||||
import Folder from '@joplin/lib/models/Folder';
|
import Folder from '@joplin/lib/models/Folder';
|
||||||
import Note from '@joplin/lib/models/Note';
|
import Note from '@joplin/lib/models/Note';
|
||||||
|
import Tag from '@joplin/lib/models/Tag';
|
||||||
const ArrayUtils = require('@joplin/lib/ArrayUtils.js');
|
const ArrayUtils = require('@joplin/lib/ArrayUtils.js');
|
||||||
|
|
||||||
async function allItems() {
|
async function allItems() {
|
||||||
@ -125,6 +126,22 @@ describe('models_Note', function() {
|
|||||||
expect(duplicatedNote.user_updated_time !== note1.user_updated_time).toBe(true);
|
expect(duplicatedNote.user_updated_time !== note1.user_updated_time).toBe(true);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should duplicate a note with tags', (async () => {
|
||||||
|
const folder1 = await Folder.save({ title: 'folder1' });
|
||||||
|
const tag1 = await Tag.save({ title: 'tag1' });
|
||||||
|
const tag2 = await Tag.save({ title: 'tag2' });
|
||||||
|
const originalNote = await Note.save({ title: 'originalNote', parent_id: folder1.id });
|
||||||
|
await Tag.addNote(tag1.id, originalNote.id);
|
||||||
|
await Tag.addNote(tag2.id, originalNote.id);
|
||||||
|
|
||||||
|
const duplicatedNote = await Note.duplicate(originalNote.id);
|
||||||
|
const duplicatedNoteTags = await Tag.tagsByNoteId(duplicatedNote.id);
|
||||||
|
|
||||||
|
expect(duplicatedNoteTags.find(o => o.id === tag1.id)).toBeDefined();
|
||||||
|
expect(duplicatedNoteTags.find(o => o.id === tag2.id)).toBeDefined();
|
||||||
|
expect(duplicatedNoteTags.length).toBe(2);
|
||||||
|
}));
|
||||||
|
|
||||||
it('should delete a set of notes', (async () => {
|
it('should delete a set of notes', (async () => {
|
||||||
const folder1 = await Folder.save({ title: 'folder1' });
|
const folder1 = await Folder.save({ title: 'folder1' });
|
||||||
const noOfNotes = 20;
|
const noOfNotes = 20;
|
||||||
|
@ -6,6 +6,7 @@ import shim from '../shim';
|
|||||||
import time from '../time';
|
import time from '../time';
|
||||||
import markdownUtils from '../markdownUtils';
|
import markdownUtils from '../markdownUtils';
|
||||||
import { NoteEntity } from '../services/database/types';
|
import { NoteEntity } from '../services/database/types';
|
||||||
|
import Tag from './Tag';
|
||||||
|
|
||||||
const { sprintf } = require('sprintf-js');
|
const { sprintf } = require('sprintf-js');
|
||||||
import Resource from './Resource';
|
import Resource from './Resource';
|
||||||
@ -615,7 +616,13 @@ export default class Note extends BaseItem {
|
|||||||
newNote.title = title;
|
newNote.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.save(newNote);
|
const newNoteSaved = await this.save(newNote);
|
||||||
|
const originalTags = await Tag.tagsByNoteId(noteId);
|
||||||
|
for (const tagToAdd of originalTags) {
|
||||||
|
await Tag.addNote(tagToAdd.id, newNoteSaved.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.save(newNoteSaved);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async noteIsOlderThan(noteId: string, date: number) {
|
static async noteIsOlderThan(noteId: string, date: number) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user