1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-03 23:50:33 +02:00

Desktop: Fixes #5955: Changing the currently opened note from plugins or the data API does not refresh the note content

This commit is contained in:
Laurent Cozic
2023-09-23 17:50:24 +01:00
parent cc459a68d5
commit a1821d607e
6 changed files with 148 additions and 38 deletions

View File

@ -1,8 +1,19 @@
import Note from '@joplin/lib/models/Note';
import { setupDatabaseAndSynchronizer, switchClient } from '@joplin/lib/testing/test-utils';
import { renderHook } from '@testing-library/react-hooks';
import useFormNote, { HookDependencies } from './useFormNote';
import useFormNote, { DbNote, HookDependencies } from './useFormNote';
const defaultFormNoteProps: HookDependencies = {
syncStarted: false,
decryptionStarted: false,
noteId: '',
isProvisional: false,
titleInputRef: null,
editorRef: null,
onBeforeLoad: ()=>{},
onAfterLoad: ()=>{},
dbNote: { id: '', updated_time: 0 },
};
describe('useFormNote', () => {
beforeEach(async () => {
@ -15,14 +26,10 @@ describe('useFormNote', () => {
const makeFormNoteProps = (syncStarted: boolean, decryptionStarted: boolean): HookDependencies => {
return {
...defaultFormNoteProps,
syncStarted,
decryptionStarted,
noteId: testNote.id,
isProvisional: false,
titleInputRef: null,
editorRef: null,
onBeforeLoad: ()=>{},
onAfterLoad: ()=>{},
};
};
@ -70,4 +77,35 @@ describe('useFormNote', () => {
});
});
});
it('should reload the note when it is changed outside of the editor', async () => {
const note = await Note.save({ title: 'Test Note!' });
const makeFormNoteProps = (dbNote: DbNote): HookDependencies => {
return {
...defaultFormNoteProps,
noteId: note.id,
dbNote,
};
};
const formNote = renderHook(props => useFormNote(props), {
initialProps: makeFormNoteProps({ id: note.id, updated_time: note.updated_time }),
});
await formNote.waitFor(() => {
expect(formNote.result.current.formNote.title).toBe('Test Note!');
});
// Simulate the note being modified outside the editor
const modifiedNote = await Note.save({ id: note.id, title: 'Modified' });
// NoteEditor then would update `dbNote`
formNote.rerender(makeFormNoteProps({ id: note.id, updated_time: modifiedNote.updated_time }));
await formNote.waitFor(() => {
expect(formNote.result.current.formNote.title).toBe('Modified');
});
});
});