-
Notifications
You must be signed in to change notification settings - Fork 388
/
text.test.ts
54 lines (49 loc) · 1.64 KB
/
text.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
import {describe, it} from '@jest/globals'
/* 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 {type BooleanDefinition, type TextDefinition} from '../definition'
import {defineType} from '../types'
describe('text types', () => {
describe('defineType', () => {
it('should define text schema', () => {
const textDef = defineType({
type: 'text',
name: 'custom-text',
title: 'Custom text',
description: 'Description',
placeholder: 'fdsasfd',
initialValue: () => Promise.resolve('text'),
validation: (Rule) => [
Rule.required()
.min(1)
.max(10)
.length(10)
.uppercase()
.lowercase()
.regex(/a+/, 'test', {name: 'yeah', invert: true})
.regex(/a+/, {name: 'yeah', invert: true})
.regex(/a+/, 'test')
.regex(/a+/)
.custom((value) => (value?.toUpperCase() == 'SHOUT' ? 'Error' : true))
.warning(),
// @ts-expect-error greaterThan is not on textRule
Rule.greaterThan(5).error(),
],
hidden: () => false,
readOnly: () => false,
options: {
layout: 'radio',
direction: 'horizontal',
list: [{value: 'A', title: 'An entry'}],
},
})
const assignableToText: TextDefinition = textDef
// @ts-expect-error text is not assignable to boolean
const notAssignableToBoolean: BooleanDefinition = textDef
})
})
})
export {}