refactor: note editor relationships (#1821)
This commit is contained in:
33
packages/snjs/lib/Client/NoteViewController.spec.ts
Normal file
33
packages/snjs/lib/Client/NoteViewController.spec.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { SNApplication } from './../Application/Application'
|
||||
import { ContentType } from '@standardnotes/common'
|
||||
import { MutatorService } from './../Services/Mutator/MutatorService'
|
||||
import { SNComponentManager } from './../Services/ComponentManager/ComponentManager'
|
||||
import { NoteType } from '@standardnotes/features'
|
||||
import { NoteViewController } from './NoteViewController'
|
||||
|
||||
describe('note view controller', () => {
|
||||
let application: SNApplication
|
||||
|
||||
beforeEach(() => {
|
||||
application = {} as jest.Mocked<SNApplication>
|
||||
application.streamItems = jest.fn()
|
||||
|
||||
const componentManager = {} as jest.Mocked<SNComponentManager>
|
||||
componentManager.getDefaultEditor = jest.fn()
|
||||
Object.defineProperty(application, 'componentManager', { value: componentManager })
|
||||
|
||||
const mutator = {} as jest.Mocked<MutatorService>
|
||||
mutator.createTemplateItem = jest.fn()
|
||||
Object.defineProperty(application, 'mutator', { value: mutator })
|
||||
})
|
||||
|
||||
it('should create notes with plaintext note type', async () => {
|
||||
const controller = new NoteViewController(application)
|
||||
await controller.initialize(false)
|
||||
|
||||
expect(application.mutator.createTemplateItem).toHaveBeenCalledWith(
|
||||
ContentType.Note,
|
||||
expect.objectContaining({ noteType: NoteType.Plain }),
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -1,3 +1,4 @@
|
||||
import { NoteType } from '@standardnotes/features'
|
||||
import {
|
||||
NoteMutator,
|
||||
SNNote,
|
||||
@@ -66,9 +67,12 @@ export class NoteViewController implements ItemViewControllerInterface {
|
||||
|
||||
async initialize(addTagHierarchy: boolean): Promise<void> {
|
||||
if (!this.item) {
|
||||
const editor = this.application.componentManager.getDefaultEditor()
|
||||
const note = this.application.mutator.createTemplateItem<NoteContent, SNNote>(ContentType.Note, {
|
||||
text: '',
|
||||
title: this.defaultTitle || '',
|
||||
noteType: editor?.noteType || NoteType.Plain,
|
||||
editorIdentifier: editor?.identifier,
|
||||
references: [],
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user