mirror of
https://github.com/filamentphp/filament.git
synced 2026-10-28 03:44:19 +08:00
tests
This commit is contained in:
@@ -17,4 +17,11 @@ class EditPost extends EditRecord
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public function refreshTitle()
|
||||
{
|
||||
$this->refreshFormData([
|
||||
'title',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,11 @@ class ViewPost extends ViewRecord
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public function refreshTitle()
|
||||
{
|
||||
$this->refreshFormData([
|
||||
'title',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ use Filament\Pages\Actions\DeleteAction;
|
||||
use Filament\Tests\Admin\Fixtures\Resources\PostResource;
|
||||
use Filament\Tests\Admin\Resources\TestCase;
|
||||
use Filament\Tests\Models\Post;
|
||||
use Illuminate\Support\Str;
|
||||
use function Pest\Livewire\livewire;
|
||||
|
||||
uses(TestCase::class);
|
||||
@@ -83,3 +84,32 @@ it('can delete', function () {
|
||||
|
||||
$this->assertModelMissing($post);
|
||||
});
|
||||
|
||||
it('can refresh data', function () {
|
||||
$post = Post::factory()->create();
|
||||
|
||||
$page = livewire(PostResource\Pages\EditPost::class, [
|
||||
'record' => $post->getKey(),
|
||||
]);
|
||||
|
||||
$originalPostTitle = $post->title;
|
||||
|
||||
$page->assertFormSet([
|
||||
'title' => $originalPostTitle,
|
||||
]);
|
||||
|
||||
$newPostTitle = Str::random();
|
||||
|
||||
$post->title = $newPostTitle;
|
||||
$post->save();
|
||||
|
||||
$page->assertFormSet([
|
||||
'title' => $originalPostTitle,
|
||||
]);
|
||||
|
||||
$page->call('refreshTitle');
|
||||
|
||||
$page->assertFormSet([
|
||||
'title' => $newPostTitle,
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ use Filament\Facades\Filament;
|
||||
use Filament\Tests\Admin\Fixtures\Resources\PostResource;
|
||||
use Filament\Tests\Admin\Resources\TestCase;
|
||||
use Filament\Tests\Models\Post;
|
||||
use Illuminate\Support\Str;
|
||||
use function Pest\Livewire\livewire;
|
||||
|
||||
uses(TestCase::class);
|
||||
@@ -33,3 +34,32 @@ it('can retrieve data', function () {
|
||||
'title' => $post->title,
|
||||
]);
|
||||
});
|
||||
|
||||
it('can refresh data', function () {
|
||||
$post = Post::factory()->create();
|
||||
|
||||
$page = livewire(PostResource\Pages\ViewPost::class, [
|
||||
'record' => $post->getKey(),
|
||||
]);
|
||||
|
||||
$originalPostTitle = $post->title;
|
||||
|
||||
$page->assertFormSet([
|
||||
'title' => $originalPostTitle,
|
||||
]);
|
||||
|
||||
$newPostTitle = Str::random();
|
||||
|
||||
$post->title = $newPostTitle;
|
||||
$post->save();
|
||||
|
||||
$page->assertFormSet([
|
||||
'title' => $originalPostTitle,
|
||||
]);
|
||||
|
||||
$page->call('refreshTitle');
|
||||
|
||||
$page->assertFormSet([
|
||||
'title' => $newPostTitle,
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user