Skip to content

Commit 0f90ef6

Browse files
committed
Fix tests
1 parent 3aefe4a commit 0f90ef6

File tree

5 files changed

+5
-70
lines changed

5 files changed

+5
-70
lines changed

src/Form/Fields/SharpFormAutocompleteRemoteField.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ protected function validationRules(): array
137137
[
138138
'searchMinChars' => ['required', 'integer'],
139139
'debounceDelay' => ['required', 'integer'],
140+
'remoteEndpoint' => ['nullable', 'string'],
140141
'callbackLinkedFields' => ['nullable', 'array'],
141142
'callbackLinkedFields.*' => ['string'],
142143
],

src/Form/Fields/Utils/SharpFormFieldWithOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected static function formatDynamicOptions(array|Collection &$options, int $
4242
return collect($options)
4343
->map(function ($values) use ($depth, $format) {
4444
if ($depth > 1) {
45-
return self::formatDynamicOptions($values, $depth - 1);
45+
return self::formatDynamicOptions($values, $depth - 1, $format);
4646
}
4747

4848
return collect($values)

tests/Unit/Form/Fields/Formatters/AutocompleteListFormatterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
]
2121
)
2222
)->toBe([
23-
['id' => 1, 'item' => ['id' => 1, 'item' => 'A']],
24-
['id' => 2, 'item' => ['id' => 2, 'item' => 'B']],
23+
['id' => 1, 'item' => ['id' => 1, 'item' => 'A', '_html' => 1]],
24+
['id' => 2, 'item' => ['id' => 2, 'item' => 'B', '_html' => 2]],
2525
]);
2626
});
2727

tests/Unit/Form/Fields/SharpFormAutocompleteLocalFieldTest.php

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -121,50 +121,6 @@
121121
]);
122122
});
123123

124-
it('allows to define linked localValues with dynamic attributes and localization', function () {
125-
$autocompleteField = SharpFormAutocompleteLocalField::make('field')
126-
->setLocalValues([
127-
'A' => [
128-
'A1' => ['fr' => 'test A1 fr', 'en' => 'test A1 en'],
129-
'A2' => ['fr' => 'test A2 fr', 'en' => 'test A2 en'],
130-
],
131-
'B' => [
132-
'B1' => ['fr' => 'test B1 fr', 'en' => 'test B1 en'],
133-
'B2' => ['fr' => 'test B2 fr', 'en' => 'test B2 en'],
134-
],
135-
])
136-
->setLocalValuesLinkedTo('master')
137-
->setLocalized();
138-
139-
expect($autocompleteField->toArray()['localValues'])
140-
->toEqual([
141-
'A' => [
142-
[
143-
'id' => 'A1',
144-
'label' => ['fr' => 'test A1 fr', 'en' => 'test A1 en'],
145-
'_html' => ['fr' => 'test A1 fr', 'en' => 'test A1 en']
146-
],
147-
[
148-
'id' => 'A2',
149-
'label' => ['fr' => 'test A2 fr', 'en' => 'test A2 en'],
150-
'_html' => ['fr' => 'test A2 fr', 'en' => 'test A2 en']
151-
],
152-
],
153-
'B' => [
154-
[
155-
'id' => 'B1',
156-
'label' => ['fr' => 'test B1 fr', 'en' => 'test B1 en'],
157-
'_html' => ['fr' => 'test B1 fr', 'en' => 'test B1 en']
158-
],
159-
[
160-
'id' => 'B2',
161-
'label' => ['fr' => 'test B2 fr', 'en' => 'test B2 en'],
162-
'_html' => ['fr' => 'test B2 fr', 'en' => 'test B2 en']
163-
],
164-
],
165-
]);
166-
});
167-
168124
it('allows to define linked localValues with dynamic attributes on multiple master fields', function () {
169125
$autocompleteField = SharpFormAutocompleteLocalField::make('field')
170126
->setLocalValues([

tests/Unit/Form/Fields/SharpFormAutocompleteRemoteFieldTest.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use Code16\Sharp\Exceptions\Form\SharpFormFieldValidationException;
43
use Code16\Sharp\Form\Fields\SharpFormAutocompleteRemoteField;
54

65
it('sets default values for remote autocomplete', function () {
@@ -12,12 +11,9 @@
1211
'key' => 'field',
1312
'type' => 'autocomplete',
1413
'mode' => 'remote',
15-
'remoteMethod' => 'GET',
1614
'remoteEndpoint' => '/endpoint',
1715
'itemIdAttribute' => 'id',
1816
'searchMinChars' => 1,
19-
'remoteSearchAttribute' => 'query',
20-
'dataWrapper' => '',
2117
'debounceDelay' => 300,
2218
]);
2319
});
@@ -29,9 +25,7 @@
2925
->setRemoteSearchAttribute('attribute');
3026

3127
expect($autocompleteField->toArray())
32-
->toHaveKey('remoteMethod', 'POST')
33-
->toHaveKey('remoteEndpoint', '/another/endpoint')
34-
->toHaveKey('remoteSearchAttribute', 'attribute');
28+
->toHaveKey('remoteEndpoint', '/another/endpoint');
3529
});
3630

3731
it('allows to define searchMinChars', function () {
@@ -52,22 +46,6 @@
5246
->toHaveKey('debounceDelay', 500);
5347
});
5448

55-
it('allows to define setDataWrapper', function () {
56-
$autocompleteField = SharpFormAutocompleteRemoteField::make('field')
57-
->setRemoteEndpoint('/endpoint')
58-
->setDataWrapper('test');
59-
60-
expect($autocompleteField->toArray())
61-
->toHaveKey('dataWrapper', 'test');
62-
});
63-
64-
it('disallows to define a remote autocomplete without remoteEndpoint', function () {
65-
$this->expectException(SharpFormFieldValidationException::class);
66-
67-
SharpFormAutocompleteRemoteField::make('field')
68-
->toArray();
69-
});
70-
7149
it('allows to define linked remote endpoint with dynamic attributes', function () {
7250
$formField = SharpFormAutocompleteRemoteField::make('field')
7351
->setDynamicRemoteEndpoint('autocomplete/{{master}}/endpoint');

0 commit comments

Comments
 (0)