refactor: note editor relationships (#1821)
This commit is contained in:
@@ -10,15 +10,16 @@ import {
|
||||
ProposedSecondsToDeferUILevelSessionExpirationDuringActiveInteraction,
|
||||
NoteViewController,
|
||||
SNNote,
|
||||
NoteType,
|
||||
PayloadEmitSource,
|
||||
} from '@standardnotes/snjs'
|
||||
|
||||
import NoteView from './NoteView'
|
||||
|
||||
describe('NoteView', () => {
|
||||
let noteViewController: NoteViewController
|
||||
let application: WebApplication
|
||||
let viewControllerManager: ViewControllerManager
|
||||
let notesState: NotesController
|
||||
let notesController: NotesController
|
||||
|
||||
const createNoteView = () =>
|
||||
new NoteView({
|
||||
@@ -31,11 +32,12 @@ describe('NoteView', () => {
|
||||
|
||||
noteViewController = {} as jest.Mocked<NoteViewController>
|
||||
|
||||
notesState = {} as jest.Mocked<NotesController>
|
||||
notesState.setShowProtectedWarning = jest.fn()
|
||||
notesController = {} as jest.Mocked<NotesController>
|
||||
notesController.setShowProtectedWarning = jest.fn()
|
||||
notesController.getSpellcheckStateForNote = jest.fn()
|
||||
|
||||
viewControllerManager = {
|
||||
notesController: notesState,
|
||||
notesController: notesController,
|
||||
} as jest.Mocked<ViewControllerManager>
|
||||
|
||||
application = {} as jest.Mocked<WebApplication>
|
||||
@@ -59,7 +61,7 @@ describe('NoteView', () => {
|
||||
|
||||
await createNoteView().onAppEvent(ApplicationEvent.UnprotectedSessionExpired)
|
||||
|
||||
expect(notesState.setShowProtectedWarning).toHaveBeenCalledWith(true)
|
||||
expect(notesController.setShowProtectedWarning).toHaveBeenCalledWith(true)
|
||||
})
|
||||
|
||||
it('should postpone the note hiding by correct time if the time passed after its last modification is less than the allowed idle time', async () => {
|
||||
@@ -77,11 +79,11 @@ describe('NoteView', () => {
|
||||
|
||||
jest.advanceTimersByTime((secondsAfterWhichTheNoteShouldHide - 1) * 1000)
|
||||
|
||||
expect(notesState.setShowProtectedWarning).not.toHaveBeenCalled()
|
||||
expect(notesController.setShowProtectedWarning).not.toHaveBeenCalled()
|
||||
|
||||
jest.advanceTimersByTime(1 * 1000)
|
||||
|
||||
expect(notesState.setShowProtectedWarning).toHaveBeenCalledWith(true)
|
||||
expect(notesController.setShowProtectedWarning).toHaveBeenCalledWith(true)
|
||||
})
|
||||
|
||||
it('should postpone the note hiding by correct time if the user continued editing it even after the protection session has expired', async () => {
|
||||
@@ -105,10 +107,10 @@ describe('NoteView', () => {
|
||||
|
||||
secondsAfterWhichTheNoteShouldHide = ProposedSecondsToDeferUILevelSessionExpirationDuringActiveInteraction
|
||||
jest.advanceTimersByTime((secondsAfterWhichTheNoteShouldHide - 1) * 1000)
|
||||
expect(notesState.setShowProtectedWarning).not.toHaveBeenCalled()
|
||||
expect(notesController.setShowProtectedWarning).not.toHaveBeenCalled()
|
||||
|
||||
jest.advanceTimersByTime(1 * 1000)
|
||||
expect(notesState.setShowProtectedWarning).toHaveBeenCalledWith(true)
|
||||
expect(notesController.setShowProtectedWarning).toHaveBeenCalledWith(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -120,7 +122,43 @@ describe('NoteView', () => {
|
||||
|
||||
await createNoteView().onAppEvent(ApplicationEvent.UnprotectedSessionExpired)
|
||||
|
||||
expect(notesState.setShowProtectedWarning).not.toHaveBeenCalled()
|
||||
expect(notesController.setShowProtectedWarning).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('editors', () => {
|
||||
it('should reload editor if noteType changes', async () => {
|
||||
noteViewController.item = {
|
||||
noteType: NoteType.Code,
|
||||
} as jest.Mocked<SNNote>
|
||||
|
||||
const view = createNoteView()
|
||||
view.reloadEditorComponent = jest.fn()
|
||||
view.setState = jest.fn()
|
||||
|
||||
const changedItem = {
|
||||
noteType: NoteType.Plain,
|
||||
} as jest.Mocked<SNNote>
|
||||
view.onNoteInnerChange(changedItem, PayloadEmitSource.LocalChanged)
|
||||
|
||||
expect(view.reloadEditorComponent).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should reload editor if editorIdentifier changes', async () => {
|
||||
noteViewController.item = {
|
||||
editorIdentifier: 'foo',
|
||||
} as jest.Mocked<SNNote>
|
||||
|
||||
const view = createNoteView()
|
||||
view.reloadEditorComponent = jest.fn()
|
||||
view.setState = jest.fn()
|
||||
|
||||
const changedItem = {
|
||||
editorIdentifier: 'bar',
|
||||
} as jest.Mocked<SNNote>
|
||||
view.onNoteInnerChange(changedItem, PayloadEmitSource.LocalChanged)
|
||||
|
||||
expect(view.reloadEditorComponent).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -142,7 +180,7 @@ describe('NoteView', () => {
|
||||
|
||||
await noteView.dismissProtectedWarning()
|
||||
|
||||
expect(notesState.setShowProtectedWarning).toHaveBeenCalledWith(false)
|
||||
expect(notesController.setShowProtectedWarning).toHaveBeenCalledWith(false)
|
||||
})
|
||||
|
||||
it('should not reveal note contents if the authorization has not been passed', async () => {
|
||||
@@ -155,7 +193,7 @@ describe('NoteView', () => {
|
||||
|
||||
await noteView.dismissProtectedWarning()
|
||||
|
||||
expect(notesState.setShowProtectedWarning).not.toHaveBeenCalled()
|
||||
expect(notesController.setShowProtectedWarning).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -170,7 +208,7 @@ describe('NoteView', () => {
|
||||
|
||||
await noteView.dismissProtectedWarning()
|
||||
|
||||
expect(notesState.setShowProtectedWarning).toHaveBeenCalledWith(false)
|
||||
expect(notesController.setShowProtectedWarning).toHaveBeenCalledWith(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user