Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Desktop: Fixes #8661: Fix note editor blank after syncing an encrypte…
…d note with remote changes (#8666)
- Loading branch information
1 parent
4804c1c
commit e701449
Showing
8 changed files
with
136 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/app-desktop/gui/NoteEditor/utils/useFormNote.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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'; | ||
|
||
|
||
describe('useFormNote', () => { | ||
beforeEach(async () => { | ||
await setupDatabaseAndSynchronizer(1); | ||
await switchClient(1); | ||
}); | ||
|
||
it('should update note when decryption completes', async () => { | ||
const testNote = await Note.save({ title: 'Test Note!' }); | ||
|
||
const makeFormNoteProps = (syncStarted: boolean, decryptionStarted: boolean): HookDependencies => { | ||
return { | ||
syncStarted, | ||
decryptionStarted, | ||
noteId: testNote.id, | ||
isProvisional: false, | ||
titleInputRef: null, | ||
editorRef: null, | ||
onBeforeLoad: ()=>{}, | ||
onAfterLoad: ()=>{}, | ||
}; | ||
}; | ||
|
||
const formNote = renderHook(props => useFormNote(props), { | ||
initialProps: makeFormNoteProps(true, false), | ||
}); | ||
await formNote.waitFor(() => { | ||
expect(formNote.result.current.formNote).toMatchObject({ | ||
encryption_applied: 0, | ||
title: testNote.title, | ||
}); | ||
}); | ||
|
||
await Note.save({ | ||
id: testNote.id, | ||
encryption_cipher_text: 'cipher_text', | ||
encryption_applied: 1, | ||
}); | ||
|
||
// Sync starting should cause a re-render | ||
formNote.rerender(makeFormNoteProps(false, false)); | ||
|
||
await formNote.waitFor(() => { | ||
expect(formNote.result.current.formNote).toMatchObject({ | ||
encryption_applied: 1, | ||
}); | ||
}); | ||
|
||
|
||
formNote.rerender(makeFormNoteProps(false, true)); | ||
|
||
await Note.save({ | ||
id: testNote.id, | ||
encryption_applied: 0, | ||
title: 'Test Note!', | ||
}); | ||
|
||
// Ending decryption should also cause a re-render | ||
formNote.rerender(makeFormNoteProps(false, false)); | ||
|
||
await formNote.waitFor(() => { | ||
expect(formNote.result.current.formNote).toMatchObject({ | ||
encryption_applied: 0, | ||
title: 'Test Note!', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters