mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Replace old usages of methods
This commit is contained in:
@@ -138,7 +138,7 @@ use PostResource\PostResource;it('can render page', function () {
|
||||
|
||||
##### Filling existing data
|
||||
|
||||
To check that the form is filled with the correct data from the database, you may `assertFormSet()` that the data in the form matches that of the record:
|
||||
To check that the form is filled with the correct data from the database, you may `assertSchemaSet()` that the data in the form matches that of the record:
|
||||
|
||||
```php
|
||||
use function Pest\Livewire\livewire;
|
||||
@@ -149,7 +149,7 @@ it('can retrieve data', function () {
|
||||
livewire(PostResource\Pages\EditPost::class, [
|
||||
'record' => $post->getRouteKey(),
|
||||
])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'author_id' => $post->author->getKey(),
|
||||
'content' => $post->content,
|
||||
'tags' => $post->tags,
|
||||
@@ -262,7 +262,7 @@ use PostResource\PostResource;it('can render page', function () {
|
||||
|
||||
##### Filling existing data
|
||||
|
||||
To check that the form is filled with the correct data from the database, you may `assertFormSet()` that the data in the form matches that of the record:
|
||||
To check that the form is filled with the correct data from the database, you may `assertSchemaSet()` that the data in the form matches that of the record:
|
||||
|
||||
```php
|
||||
use function Pest\Livewire\livewire;
|
||||
@@ -273,7 +273,7 @@ it('can retrieve data', function () {
|
||||
livewire(PostResource\Pages\ViewPost::class, [
|
||||
'record' => $post->getRouteKey(),
|
||||
])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'author_id' => $post->author->getKey(),
|
||||
'content' => $post->content,
|
||||
'tags' => $post->tags,
|
||||
|
||||
@@ -24,7 +24,7 @@ livewire(CreatePost::class)
|
||||
|
||||
> If you have multiple forms on a Livewire component, you can specify which form you want to fill using `fillForm([...], 'createPostForm')`.
|
||||
|
||||
To check that a form has data, use `assertFormSet()`:
|
||||
To check that a form has data, use `assertSchemaSet()`:
|
||||
|
||||
```php
|
||||
use Illuminate\Support\Str;
|
||||
@@ -37,15 +37,15 @@ it('can automatically generate a slug from the title', function () {
|
||||
->fillForm([
|
||||
'title' => $title,
|
||||
])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'slug' => Str::slug($title),
|
||||
]);
|
||||
});
|
||||
```
|
||||
|
||||
> If you have multiple forms on a Livewire component, you can specify which form you want to check using `assertFormSet([...], 'createPostForm')`.
|
||||
> If you have multiple forms on a Livewire component, you can specify which form you want to check using `assertSchemaSet([...], 'createPostForm')`.
|
||||
|
||||
You may also find it useful to pass a function to the `assertFormSet()` method, which allows you to access the form `$state` and perform additional assertions:
|
||||
You may also find it useful to pass a function to the `assertSchemaSet()` method, which allows you to access the form `$state` and perform additional assertions:
|
||||
|
||||
```php
|
||||
use Illuminate\Support\Str;
|
||||
@@ -58,7 +58,7 @@ it('can automatically generate a slug from the title without any spaces', functi
|
||||
->fillForm([
|
||||
'title' => $title,
|
||||
])
|
||||
->assertFormSet(function (array $state): array {
|
||||
->assertSchemaSet(function (array $state): array {
|
||||
expect($state['slug'])
|
||||
->not->toContain(' ');
|
||||
|
||||
|
||||
@@ -5,23 +5,26 @@ namespace Livewire\Features\SupportTesting {
|
||||
use Closure;
|
||||
|
||||
class Testable {
|
||||
public function fillForm(array | Closure $state = [], string $form = 'form'): static {}
|
||||
public function fillForm(array | Closure $state = [], ?string $form = null): static {}
|
||||
|
||||
/**
|
||||
* @deprecated Use `assertSchemaSet()` instead.
|
||||
*/
|
||||
public function assertFormSet(array | Closure $state, string $form = 'form'): static {}
|
||||
|
||||
public function assertHasFormErrors(array $keys = [], string $form = 'form'): static {}
|
||||
public function assertHasFormErrors(array $keys = [], ?string $form = null): static {}
|
||||
|
||||
public function assertHasNoFormErrors(array $keys = [], string $form = 'form'): static {}
|
||||
public function assertHasNoFormErrors(array $keys = [], ?string $form = null): static {}
|
||||
|
||||
public function assertFormFieldExists(string $fieldName, string | Closure $form = 'form', ?Closure $checkFieldUsing = null): static {}
|
||||
public function assertFormFieldExists(string $fieldName, string | Closure | null $form = null, ?Closure $checkFieldUsing = null): static {}
|
||||
|
||||
public function assertFormFieldDoesNotExist(string $fieldName, string $form = 'form'): static {}
|
||||
public function assertFormFieldDoesNotExist(string $fieldName, ?string $form = null): static {}
|
||||
|
||||
public function assertFormFieldDisabled(string $fieldName, string $form = 'form'): static {}
|
||||
public function assertFormFieldDisabled(string $fieldName, ?string $form = null): static {}
|
||||
|
||||
public function assertFormFieldEnabled(string $fieldName, string $form = 'form'): static {}
|
||||
public function assertFormFieldEnabled(string $fieldName, ?string $form = null): static {}
|
||||
|
||||
public function assertFormFieldReadOnly(string $fieldName, string $form = 'form'): static {}
|
||||
public function assertFormFieldReadOnly(string $fieldName, ?string $form = null): static {}
|
||||
|
||||
/**
|
||||
* @deprecated Use `assertSchemaExists()` instead.
|
||||
|
||||
@@ -819,7 +819,7 @@ use function Pest\Livewire\livewire;
|
||||
$undoRepeaterFake = Repeater::fake();
|
||||
|
||||
livewire(EditPost::class, ['record' => $post])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'quotes' => [
|
||||
[
|
||||
'content' => 'First quote',
|
||||
@@ -834,7 +834,7 @@ livewire(EditPost::class, ['record' => $post])
|
||||
$undoRepeaterFake();
|
||||
```
|
||||
|
||||
You may also find it useful to test the number of items in a repeater by passing a function to the `assertFormSet()` method:
|
||||
You may also find it useful to test the number of items in a repeater by passing a function to the `assertSchemaSet()` method:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\Repeater;
|
||||
@@ -843,7 +843,7 @@ use function Pest\Livewire\livewire;
|
||||
$undoRepeaterFake = Repeater::fake();
|
||||
|
||||
livewire(EditPost::class, ['record' => $post])
|
||||
->assertFormSet(function (array $state) {
|
||||
->assertSchemaSet(function (array $state) {
|
||||
expect($state['quotes'])
|
||||
->toHaveCount(2);
|
||||
});
|
||||
|
||||
@@ -675,7 +675,7 @@ use function Pest\Livewire\livewire;
|
||||
$undoBuilderFake = Builder::fake();
|
||||
|
||||
livewire(EditPost::class, ['record' => $post])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'content' => [
|
||||
[
|
||||
'type' => 'heading',
|
||||
@@ -697,7 +697,7 @@ livewire(EditPost::class, ['record' => $post])
|
||||
$undoBuilderFake();
|
||||
```
|
||||
|
||||
You may also find it useful to access test the number of items in a repeater by passing a function to the `assertFormSet()` method:
|
||||
You may also find it useful to access test the number of items in a repeater by passing a function to the `assertSchemaSet()` method:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\Builder;
|
||||
@@ -706,7 +706,7 @@ use function Pest\Livewire\livewire;
|
||||
$undoBuilderFake = Builder::fake();
|
||||
|
||||
livewire(EditPost::class, ['record' => $post])
|
||||
->assertFormSet(function (array $state) {
|
||||
->assertSchemaSet(function (array $state) {
|
||||
expect($state['content'])
|
||||
->toHaveCount(2);
|
||||
});
|
||||
|
||||
@@ -70,7 +70,7 @@ class TestsForms
|
||||
|
||||
public function assertFormSet(): Closure
|
||||
{
|
||||
return function (array | Closure $state, ?string $form = null): static {
|
||||
return function (array | Closure $state, string $form = 'form'): static {
|
||||
$this->assertSchemaSet($state, $form);
|
||||
|
||||
return $this;
|
||||
@@ -158,10 +158,10 @@ class TestsForms
|
||||
|
||||
public function assertFormComponentExists(): Closure
|
||||
{
|
||||
return function (string $componentKey, string | Closure | null $form = null, ?Closure $checkComponentUsing = null): static {
|
||||
return function (string $componentKey, string | Closure $form = 'form', ?Closure $checkComponentUsing = null): static {
|
||||
if ($form instanceof Closure) {
|
||||
$checkComponentUsing = $form;
|
||||
$form = null;
|
||||
$form = 'form';
|
||||
}
|
||||
|
||||
$this->assertSchemaComponentExists($componentKey, $form, $checkComponentUsing);
|
||||
@@ -172,7 +172,7 @@ class TestsForms
|
||||
|
||||
public function assertFormComponentDoesNotExist(): Closure
|
||||
{
|
||||
return function (string $componentKey, ?string $form = null): static {
|
||||
return function (string $componentKey, string $form = 'form'): static {
|
||||
$this->assertSchemaComponentDoesNotExist($componentKey, $form);
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -41,13 +41,13 @@ it('can call an action with data', function (): void {
|
||||
->callAction(TestAction::make('setValue')->schemaComponent('textInput'), data: [
|
||||
'value' => $value = Str::random(),
|
||||
])
|
||||
->assertFormSet(['textInput' => $value]);
|
||||
->assertSchemaSet(['textInput' => $value]);
|
||||
|
||||
livewire(Actions::class)
|
||||
->callFormComponentAction('textInput', 'setValue', data: [
|
||||
'value' => $value = Str::random(),
|
||||
])
|
||||
->assertFormSet(['textInput' => $value]);
|
||||
->assertSchemaSet(['textInput' => $value]);
|
||||
});
|
||||
|
||||
it('can validate an action\'s data', function (): void {
|
||||
@@ -56,14 +56,14 @@ it('can validate an action\'s data', function (): void {
|
||||
'value' => null,
|
||||
])
|
||||
->assertHasFormErrors(['value' => ['required']])
|
||||
->assertFormSet(['textInput' => null]);
|
||||
->assertSchemaSet(['textInput' => null]);
|
||||
|
||||
livewire(Actions::class)
|
||||
->callFormComponentAction('textInput', 'setValue', data: [
|
||||
'value' => null,
|
||||
])
|
||||
->assertHasFormComponentActionErrors(['value' => ['required']])
|
||||
->assertFormSet(['textInput' => null]);
|
||||
->assertSchemaSet(['textInput' => null]);
|
||||
});
|
||||
|
||||
it('can set default action data when mounted', function (): void {
|
||||
@@ -85,13 +85,13 @@ it('can call an action with arguments', function (): void {
|
||||
->callAction(TestAction::make('setValueFromArguments')->schemaComponent('textInput')->arguments([
|
||||
'value' => $value = Str::random(),
|
||||
]))
|
||||
->assertFormSet(['textInput' => $value]);
|
||||
->assertSchemaSet(['textInput' => $value]);
|
||||
|
||||
livewire(Actions::class)
|
||||
->callFormComponentAction('textInput', 'setValueFromArguments', arguments: [
|
||||
'value' => $value = Str::random(),
|
||||
])
|
||||
->assertFormSet(['textInput' => $value]);
|
||||
->assertSchemaSet(['textInput' => $value]);
|
||||
});
|
||||
|
||||
it('can call an action and halt', function (): void {
|
||||
|
||||
@@ -22,7 +22,7 @@ it('UploadedFile should be converted to TemporaryUploadedFile', function (): voi
|
||||
UploadedFile::fake()->image('multiple-file2.jpg'),
|
||||
],
|
||||
])
|
||||
->assertFormSet(function (array $data): void {
|
||||
->assertSchemaSet(function (array $data): void {
|
||||
expect($data['single-file'][0])->toBeInstanceOf(TemporaryUploadedFile::class)
|
||||
->and($data['multiple-files'][0])->toBeInstanceOf(TemporaryUploadedFile::class)
|
||||
->and($data['multiple-files'][1])->toBeInstanceOf(TemporaryUploadedFile::class);
|
||||
|
||||
@@ -21,7 +21,7 @@ it('can fill and assert data in a repeater', function (array $data): void {
|
||||
try {
|
||||
livewire(TestComponentWithRepeater::class)
|
||||
->fillForm($data)
|
||||
->assertFormSet($data);
|
||||
->assertSchemaSet($data);
|
||||
} catch (RootTagMissingFromViewException $exception) {
|
||||
// Flaky test
|
||||
}
|
||||
@@ -127,13 +127,13 @@ it('can remove items from a repeater', function (): void {
|
||||
],
|
||||
],
|
||||
])
|
||||
->assertFormSet($data)
|
||||
->assertSchemaSet($data)
|
||||
->fillForm([
|
||||
'normal' => [
|
||||
Arr::first($data['normal']),
|
||||
],
|
||||
])
|
||||
->assertFormSet(function (array $data) {
|
||||
->assertSchemaSet(function (array $data) {
|
||||
expect($data['normal'])->toHaveCount(1);
|
||||
|
||||
return [
|
||||
|
||||
@@ -48,7 +48,7 @@ it('has fields on multiple forms', function (): void {
|
||||
it('can fill fields on multiple forms', function (): void {
|
||||
livewire(TestComponentWithMultipleForms::class)
|
||||
->fillForm(['title' => 'value'], 'fooForm')
|
||||
->assertFormSet(['title' => 'value'], 'fooForm');
|
||||
->assertSchemaSet(['title' => 'value'], 'fooForm');
|
||||
});
|
||||
|
||||
it('can have disabled fields', function (): void {
|
||||
|
||||
@@ -818,7 +818,7 @@ test('components can set their own state after they are hydrated', function ():
|
||||
->statePath('data');
|
||||
}
|
||||
})
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'foo' => 'bar',
|
||||
]);
|
||||
});
|
||||
@@ -839,7 +839,7 @@ test('components can set their own state after they are updated', function (): v
|
||||
->fillForm([
|
||||
'foo' => 'baz',
|
||||
])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'foo' => 'bar',
|
||||
]);
|
||||
});
|
||||
@@ -860,7 +860,7 @@ test('components can inject their own state after they are updated', function ()
|
||||
->fillForm([
|
||||
'foo' => $state = Str::random(),
|
||||
])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'foo' => strrev($state),
|
||||
]);
|
||||
});
|
||||
@@ -881,7 +881,7 @@ test('components can get their own state from the component object', function ()
|
||||
->fillForm([
|
||||
'foo' => $state = Str::random(),
|
||||
])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'foo' => strrev($state),
|
||||
]);
|
||||
});
|
||||
@@ -930,7 +930,7 @@ test('components can inject their old state after it is updated', function (): v
|
||||
'foo' => $state = Str::random(),
|
||||
])
|
||||
->assertSet('storedOldState', $oldState)
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'foo' => $state,
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ it('can set the value of a field', function (): void {
|
||||
->fillForm([
|
||||
'bar' => $bar = Str::random(),
|
||||
])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'foo' => $bar,
|
||||
]);
|
||||
});
|
||||
@@ -54,7 +54,7 @@ it('can set the value of a field and call its updated hook', function (): void {
|
||||
->fillForm([
|
||||
'bar' => $bar = Str::random(),
|
||||
])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'foo' => $bar,
|
||||
'baz' => 'qux',
|
||||
]);
|
||||
@@ -82,7 +82,7 @@ it('can set the value of a nested field', function (): void {
|
||||
->fillForm([
|
||||
'bar' => $bar = Str::random(),
|
||||
])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'nested.foo' => $bar,
|
||||
]);
|
||||
});
|
||||
@@ -109,7 +109,7 @@ it('can set the value of a parent level field', function (): void {
|
||||
->fillForm([
|
||||
'nested.bar' => $bar = Str::random(),
|
||||
])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'foo' => $bar,
|
||||
]);
|
||||
});
|
||||
@@ -140,7 +140,7 @@ it('can set the value of a parent level field with a nested field', function ():
|
||||
->fillForm([
|
||||
'nestedTwo.bar' => $bar = Str::random(),
|
||||
])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'nestedOne.foo' => $bar,
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -27,7 +27,7 @@ it('can render page', function (): void {
|
||||
|
||||
it('can retrieve data', function (): void {
|
||||
livewire(EditProfile::class)
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'name' => $this->user->name,
|
||||
'email' => $this->user->email,
|
||||
]);
|
||||
@@ -83,7 +83,7 @@ it('can send email change verification', function (): void {
|
||||
->call('save')
|
||||
->assertHasNoFormErrors()
|
||||
->assertNotified('Email address change request sent')
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'email' => $oldEmail,
|
||||
]);
|
||||
|
||||
@@ -122,7 +122,7 @@ it('can save password', function (): void {
|
||||
->call('save')
|
||||
->assertHasNoFormErrors()
|
||||
->assertNotified('Saved')
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'password' => '',
|
||||
'passwordConfirmation' => '',
|
||||
]);
|
||||
|
||||
@@ -59,7 +59,7 @@ it('can create another', function (): void {
|
||||
->call('create', true)
|
||||
->assertHasNoFormErrors()
|
||||
->assertNoRedirect()
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'author_id' => null,
|
||||
'content' => null,
|
||||
'tags' => [],
|
||||
@@ -109,7 +109,7 @@ it('can create another and preserve data', function (): void {
|
||||
->call('create', true)
|
||||
->assertHasNoFormErrors()
|
||||
->assertNoRedirect()
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'author_id' => null,
|
||||
'content' => null,
|
||||
'tags' => $newData->tags,
|
||||
|
||||
@@ -38,7 +38,7 @@ it('can retrieve data', function (): void {
|
||||
livewire(EditPost::class, [
|
||||
'record' => $post->getKey(),
|
||||
])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'author_id' => $post->author->getKey(),
|
||||
'content' => $post->content,
|
||||
'tags' => $post->tags,
|
||||
@@ -104,7 +104,7 @@ it('can refresh data', function (): void {
|
||||
|
||||
$originalPostTitle = $post->title;
|
||||
|
||||
$page->assertFormSet([
|
||||
$page->assertSchemaSet([
|
||||
'title' => $originalPostTitle,
|
||||
]);
|
||||
|
||||
@@ -113,13 +113,13 @@ it('can refresh data', function (): void {
|
||||
$post->title = $newPostTitle;
|
||||
$post->save();
|
||||
|
||||
$page->assertFormSet([
|
||||
$page->assertSchemaSet([
|
||||
'title' => $originalPostTitle,
|
||||
]);
|
||||
|
||||
$page->call('refreshTitle');
|
||||
|
||||
$page->assertFormSet([
|
||||
$page->assertSchemaSet([
|
||||
'title' => $newPostTitle,
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ it('can retrieve data', function (): void {
|
||||
livewire(ViewPost::class, [
|
||||
'record' => $post->getKey(),
|
||||
])
|
||||
->assertFormSet([
|
||||
->assertSchemaSet([
|
||||
'author_id' => $post->author->getKey(),
|
||||
'content' => $post->content,
|
||||
'tags' => $post->tags,
|
||||
@@ -53,7 +53,7 @@ it('can refresh data', function (): void {
|
||||
|
||||
$originalPostTitle = $post->title;
|
||||
|
||||
$page->assertFormSet([
|
||||
$page->assertSchemaSet([
|
||||
'title' => $originalPostTitle,
|
||||
]);
|
||||
|
||||
@@ -62,13 +62,13 @@ it('can refresh data', function (): void {
|
||||
$post->title = $newPostTitle;
|
||||
$post->save();
|
||||
|
||||
$page->assertFormSet([
|
||||
$page->assertSchemaSet([
|
||||
'title' => $originalPostTitle,
|
||||
]);
|
||||
|
||||
$page->call('refreshTitle');
|
||||
|
||||
$page->assertFormSet([
|
||||
$page->assertSchemaSet([
|
||||
'title' => $newPostTitle,
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user