forked from tdwesten/statamic-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextTest.php
More file actions
140 lines (109 loc) · 4.44 KB
/
TextTest.php
File metadata and controls
140 lines (109 loc) · 4.44 KB
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
137
138
139
140
<?php
use Tdwesten\StatamicBuilder\Enums\AutocompleteOption;
use Tdwesten\StatamicBuilder\Enums\InputTypeOption;
use Tdwesten\StatamicBuilder\Enums\VisibilityOption;
use Tdwesten\StatamicBuilder\FieldTypes\Text;
it('can render to a array', function (): void {
Text::make('title')
->inputType(InputTypeOption::Email)
->displayName('Name')
->required()
->instructions('The name of the county')
->instructionsPosition('above')
->antlers(false)
->placeholder('Enter a title')
->default('Default value')
->characterLimit(100)
->autocomplete(AutocompleteOption::BdayDay)
->prepend('https://')
->append('.com')
->toArray();
$field = new \Tdwesten\StatamicBuilder\FieldTypes\Group('title');
$field->displayName('Display Name')
->instructions('Enter the title')
->visibility(VisibilityOption::Hidden)
->required()
->instructionsPosition('below')
->listable()
->replicatorPreview(true)
->width(50);
expect($field->toArray()['field']['display'])->toBe('Display Name');
expect($field->toArray()['field']['instructions'])->toBe('Enter the title');
expect($field->toArray()['field']['visibility'])->toBe('hidden');
expect($field->toArray()['field']['validate'])->toBe(['required']);
expect($field->toArray()['field']['instructions_position'])->toBe('below');
expect($field->toArray()['field']['listable'])->toBe(true);
expect($field->toArray()['field']['replicator_preview'])->toBe(true);
expect($field->toArray()['field']['width'])->toBe(50);
});
test('Renders expected array data', function (): void {
$text = new \Tdwesten\StatamicBuilder\FieldTypes\Text('title');
$text->displayName('Name')
->required()
->instructions('The name of the county')
->instructionsPosition('above')
->antlers(false)
->listable();
$expected = [
'handle' => 'title',
'field' => [
'antlers' => false,
'display' => 'Name',
'duplicate' => true,
'hide_display' => false,
'input_type' => 'text',
'instructions' => 'The name of the county',
'instructions_position' => 'above',
'listable' => true,
'localizable' => false,
'replicator_preview' => true,
'required' => true,
'type' => 'text',
'validate' => [
'required',
],
'visibility' => 'visible',
],
];
expect($text->toArray())->toBe($expected);
});
test('Can set input type to email', function (): void {
$text = new \Tdwesten\StatamicBuilder\FieldTypes\Text('title');
$text->inputType(InputTypeOption::Email);
expect($text->toArray()['field']['input_type'])->toBe('email');
});
test('Can set input type to number', function (): void {
$text = new \Tdwesten\StatamicBuilder\FieldTypes\Text('title');
$text->inputType(InputTypeOption::Number);
expect($text->toArray()['field']['input_type'])->toBe('number');
});
test('Can add a placeholder', function (): void {
$text = new \Tdwesten\StatamicBuilder\FieldTypes\Text('title');
$text->placeholder('Enter a title');
expect($text->toArray()['field']['placeholder'])->toBe('Enter a title');
});
test('Can add a default value', function (): void {
$text = new \Tdwesten\StatamicBuilder\FieldTypes\Text('title');
$text->default('Default value');
expect($text->toArray()['field']['default'])->toBe('Default value');
});
test('Can add a character limit', function (): void {
$text = new \Tdwesten\StatamicBuilder\FieldTypes\Text('title');
$text->characterLimit(100);
expect($text->toArray()['field']['character_limit'])->toBe(100);
});
test('Can add autocomplete options', function (): void {
$text = new \Tdwesten\StatamicBuilder\FieldTypes\Text('title');
$text->autocomplete(AutocompleteOption::BdayDay);
expect($text->toArray()['field']['autocomplete'])->toBe('bday-day');
});
test('Can add prepend text', function (): void {
$text = new \Tdwesten\StatamicBuilder\FieldTypes\Text('title');
$text->prepend('https://');
expect($text->toArray()['field']['prepend'])->toBe('https://');
});
test('Can add append text', function (): void {
$text = new \Tdwesten\StatamicBuilder\FieldTypes\Text('title');
$text->append('.com');
expect($text->toArray()['field']['append'])->toBe('.com');
});