-
Notifications
You must be signed in to change notification settings - Fork 391
/
date.test.ts
56 lines (50 loc) · 1.76 KB
/
date.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
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 DateDefinition, type StringDefinition} from '../definition'
import {defineField, defineType} from '../types'
describe('date types', () => {
describe('defineType', () => {
it('should define date schema', () => {
const dateDef = defineType({
type: 'date',
name: 'custom-date',
title: 'Custom',
placeholder: 'blabal',
icon: () => null,
description: 'Description',
initialValue: () => Promise.resolve('2021-01-01'),
validation: (Rule) => [
Rule.required()
.required()
.custom((value) => (value?.indexOf('2021-01-01') ?? -1 >= 0 ? 'Error' : true))
.warning(),
// @ts-expect-error greaterThan does not exist on dateRule
Rule.greaterThan(5).error(),
],
hidden: () => false,
options: {
dateFormat: 'YYYY-MM-DD',
},
})
const assignableToDate: DateDefinition = dateDef
// @ts-expect-error date is not assignable to string
const notAssignableToString: StringDefinition = dateDef
})
})
it('should support Rule.valueOfField calls inside defineField', () => {
const dateField: DateDefinition = defineField({
type: 'date',
name: 'defineField-defined',
description: 'field defined with defineField, containing validation using Rule.valueOfField',
validation: (Rule) => {
const fieldRef = Rule.valueOfField('some-other-field')
return Rule.min(fieldRef).max(fieldRef)
},
})
})
})
export {}