Импорт в Filament
Давайте проверим импорт. Кнопка в шапке на /admin/posts принимает файл и создаёт строки по его содержимому.
На ListPosts вызовем
callAction с именем
импорта, передадим тестовый
файл и убедимся, что новая
запись появилась в базе.
Скелет проверки импорта:
<?php
use App\Filament\Resources\Posts\Pages\ListPosts;
use App\Models\Post;
use App\Models\User;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use function Pest\Livewire\livewire;
beforeEach(function () {
$this->actingAs(User::factory()->create());
Storage::fake('local');
});
it('imports posts from a file', function () {
$file = UploadedFile::fake()->createWithContent(
'posts.csv',
"title\nImported Post\n"
);
livewire(ListPosts::class)
->callAction('import', data: [
'file' => $file,
]);
expect(Post::query()->where('title', 'Imported Post')->exists())
->toBeTrue();
});
?>
Проверьте, что загрузка файла добавляет работника в список.