feat: add models package

This commit is contained in:
Karol Sójko
2022-07-05 20:47:11 +02:00
parent 60d1554ff7
commit b614c71e79
199 changed files with 8772 additions and 22 deletions

View File

@@ -0,0 +1,42 @@
import { createNote } from './../../Utilities/Test/SpecUtils'
describe('SNNote Tests', () => {
it('should safely type required fields of Note when creating from PayloadContent', () => {
const note = createNote({
title: 'Expected string',
text: ['unexpected array'] as never,
preview_plain: 'Expected preview',
preview_html: {} as never,
hidePreview: 'string' as never,
})
expect([
typeof note.title,
typeof note.text,
typeof note.preview_html,
typeof note.preview_plain,
typeof note.hidePreview,
]).toStrictEqual(['string', 'string', 'string', 'string', 'boolean'])
})
it('should preserve falsy values when casting from PayloadContent', () => {
const note = createNote({
preview_plain: null as never,
preview_html: undefined,
})
expect(note.preview_plain).toBeFalsy()
expect(note.preview_html).toBeFalsy()
})
it('should set mobilePrefersPlainEditor when given a valid choice', () => {
const selected = createNote({
mobilePrefersPlainEditor: true,
})
const unselected = createNote()
expect(selected.mobilePrefersPlainEditor).toBeTruthy()
expect(unselected.mobilePrefersPlainEditor).toBe(undefined)
})
})