Files
filament/tests/Unit/Forms/FieldTest.php
T
2021-08-29 19:27:35 +01:00

41 lines
1.2 KiB
PHP

<?php
use Filament\Forms\ComponentContainer;
use Filament\Forms\Components\Field;
use Illuminate\Support\Str;
use Tests\TestCase;
use Tests\Unit\Forms\Fixtures\Livewire;
uses(TestCase::class);
it('sets its state path from its name', function () {
$field = (new Field($name = Str::random()))
->container(ComponentContainer::make(Livewire::make()));
expect($field)
->getStatePath()->toBe($name);
});
it('sets its fallback label from its name', function () {
$field = (new Field($name = Str::random()))
->container(ComponentContainer::make(Livewire::make()));
expect($field)
->getLabel()->toBe(
(string) Str::of($name)
->afterLast('.')
->kebab()
->replace(['-', '_'], ' ')
->ucfirst(),
);
});
it('has state binding modifiers', function () {
$field = (new Field(Str::random()))
->container(ComponentContainer::make(Livewire::make()))
->stateBindingModifiers($modifiers = [Str::random(), Str::random()]);
expect($field)
->applyStateBindingModifiers($expression = Str::random())->toBe(implode('.', array_merge([$expression], $modifiers)));
});