/
block.test.ts
136 lines (130 loc) · 3.91 KB
/
block.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* eslint-disable @typescript-eslint/no-unused-vars */
/**
* Some of these tests have no expect statement;
* use of ts-expect-error serves the same purpose - TypeScript is the testrunner here
*/
import {BlockDefinition, BooleanDefinition} from '../definition'
import {defineArrayMember, defineField, defineType} from '../types'
describe('block types', () => {
describe('defineType', () => {
it('should define block schema', () => {
const blockDef = defineType({
type: 'block',
name: 'custom-block',
title: 'Custom PTE',
icon: () => null,
description: 'Description',
initialValue: () => Promise.resolve([]),
validation: (Rule) => [
Rule.required()
.required()
.custom((value) => (value?.filter((t) => !t).length === 1 ? 'Error' : true))
.warning(),
// @ts-expect-error greaterThan does not exist on BlockRule
Rule.greaterThan(5).error(),
],
hidden: () => false,
readOnly: () => false,
styles: [{title: 'Quote', value: 'blockquote'}],
lists: [{title: 'Bullet', value: 'bullet'}],
marks: {
decorators: [
{title: 'Strong', value: 'strong'},
{title: 'Emphasis', value: 'em'},
{
title: 'Sup',
value: 'sup',
icon: () => null,
},
],
annotations: [
{
name: 'authorInline',
title: 'Author',
type: 'reference',
to: {type: 'author'},
},
{type: 'author', initialValue: {}},
{type: 'object', fields: [{name: 'title', type: 'string'}]},
],
},
of: [{type: 'string'}],
options: {
spellCheck: true,
},
})
const assignableToBlock: BlockDefinition = blockDef
// @ts-expect-error block is not assignable to boolean
const notAssignableToBoolean: BooleanDefinition = blockDef
})
})
it('should define block field and arrayOf', () => {
const field: BlockDefinition = defineField({
type: 'block',
name: 'pteField',
title: 'Custom PTE',
icon: () => null,
styles: [{title: 'Quote', value: 'blockquote'}],
lists: [{title: 'Bullet', value: 'bullet'}],
marks: {
decorators: [
{title: 'Strong', value: 'strong'},
{
title: 'Sup',
value: 'sup',
icon: () => null,
},
],
annotations: [{name: 'author', title: 'Author', type: 'reference', to: {type: 'author'}}],
},
of: [{type: 'string'}],
options: {
spellCheck: true,
},
})
const arrayOf = defineArrayMember({
type: 'block',
name: 'pteField',
title: 'Custom PTE',
icon: () => null,
styles: [{title: 'Quote', value: 'blockquote'}],
lists: [{title: 'Bullet', value: 'bullet'}],
marks: {
decorators: [
{title: 'Strong', value: 'strong'},
{
title: 'Sup',
value: 'sup',
icon: () => null,
},
],
annotations: [{name: 'author', title: 'Author', type: 'reference', to: {type: 'author'}}],
},
of: [{type: 'string'}],
options: {
spellCheck: true,
},
})
})
it('should allow block fields in array defineType as inline definition', () => {
defineType({
type: 'array',
name: 'pte',
of: [
{
type: 'block',
name: 'pte',
styles: [{title: 'Quote', value: 'blockquote'}],
lists: [{title: 'Bullet', value: 'bullet'}],
marks: {
decorators: [{title: 'Strong', value: 'strong'}],
annotations: [
{name: 'author', title: 'Author', type: 'reference', to: {type: 'author'}},
],
},
},
],
})
})
})
export {}