22
33namespace Tests \Feature \Filament \Resources ;
44
5- use App \Filament \Resources \GedcomResource ;
5+ use App \Filament \App \Resources \GedcomResource ;
6+ use App \Jobs \ExportGedCom ;
7+ use App \Models \Gedcom ;
68use App \Models \User ;
79use Illuminate \Foundation \Testing \RefreshDatabase ;
8- use Illuminate \Http \UploadedFile ;
9- use Illuminate \Support \Facades \Storage ;
10- use Livewire \Livewire ;
10+ use Illuminate \Support \Facades \Auth ;
11+ use Illuminate \Support \Facades \Queue ;
1112use Tests \TestCase ;
1213
1314class GedcomResourceTest extends TestCase
@@ -20,44 +21,43 @@ class GedcomResourceTest extends TestCase
2021 protected function setUp (): void
2122 {
2223 parent ::setUp ();
24+ Queue::fake ();
2325 $ this ->user = User::factory ()->create ();
2426 }
2527
26- public function test_form_schema_contains_correct_fields_and_validations (): void
28+ public function test_resource_has_correct_model (): void
2729 {
28- $ form = GedcomResource::form (Livewire::mock ());
29- $ schema = collect ($ form ->getSchema ());
30-
31- $ fileUpload = $ schema ->firstWhere ('name ' , 'attachment ' );
32- $ this ->assertNotNull ($ fileUpload );
33- $ this ->assertEquals ('private ' , $ fileUpload ->getVisibility ());
34- $ this ->assertEquals (100000 , $ fileUpload ->getMaxSize ());
35- $ this ->assertEquals ('gedcom-form-imports ' , $ fileUpload ->getDirectory ());
36- $ this ->assertTrue ($ fileUpload ->isRequired ());
30+ $ this ->assertEquals (Gedcom::class, GedcomResource::getModel ());
3731 }
3832
39- public function test_table_configuration (): void
33+ public function test_resource_navigation_is_configured (): void
4034 {
41- $ table = GedcomResource::table (Livewire::mock ());
42- $ this ->assertCount (0 , $ table ->getColumns ());
43- $ this ->assertCount (0 , $ table ->getFilters ());
35+ $ this ->assertNotEmpty (GedcomResource::getNavigationLabel ());
36+ $ this ->assertNotEmpty (GedcomResource::getNavigationIcon ());
37+ }
38+
39+ public function test_resource_has_pages_defined (): void
40+ {
41+ $ pages = GedcomResource::getPages ();
42+ $ this ->assertArrayHasKey ('index ' , $ pages );
43+ $ this ->assertArrayHasKey ('create ' , $ pages );
44+ }
45+
46+ public function test_export_gedcom_dispatches_job_with_authenticated_user (): void
47+ {
48+ Auth::login ($ this ->user );
49+
50+ GedcomResource::exportGedcom ();
4451
45- $ actions = $ table ->getActions ();
46- $ this ->assertNotEmpty ($ actions );
47- $ this ->assertArrayHasKey ('export ' , $ actions );
52+ Queue::assertPushed (ExportGedCom::class, fn ($ job ): bool => $ job ->user ->id === $ this ->user ->id );
4853 }
4954
50- public function test_file_upload_dispatches_import_gedcom_job (): void
55+ public function test_export_gedcom_does_not_dispatch_without_authenticated_user (): void
5156 {
52- Storage::fake ('private ' );
53- $ file = UploadedFile::fake ()->create ('document.ged ' , 500 );
57+ Auth::logout ();
5458
55- Livewire::actingAs ($ this ->user )
56- ->test (GedcomResource::class)
57- ->set ('attachment ' , $ file )
58- ->call ('save ' );
59+ GedcomResource::exportGedcom ();
5960
60- Storage::disk ('private ' )->assertExists ('gedcom-form-imports/ ' .$ file ->hashName ());
61- $ this ->assertDatabaseHas ('jobs ' , ['queue ' => 'default ' ]);
61+ Queue::assertNotPushed (ExportGedCom::class);
6262 }
6363}
0 commit comments