From 63323d86c3f9ed8cd64295aa4f2ea9bb428d2a3f Mon Sep 17 00:00:00 2001 From: Constantin Graf Date: Thu, 18 Jul 2024 13:17:00 +0200 Subject: [PATCH] Added tests for FailedJobResource and renamed to singular --- ...JobsResource.php => FailedJobResource.php} | 7 ++- .../Pages}/ListFailedJobs.php | 6 +- .../Pages/ViewFailedJobs.php | 13 +++++ app/Models/FailedJob.php | 3 + database/factories/FailedJobFactory.php | Bin 0 -> 5937 bytes tests/Unit/Filament/FailedJobResourceTest.php | 53 ++++++++++++++++++ 6 files changed, 77 insertions(+), 5 deletions(-) rename app/Filament/Resources/{FailedJobsResource.php => FailedJobResource.php} (94%) rename app/Filament/Resources/{FailedJobsResource => FailedJobResource/Pages}/ListFailedJobs.php (88%) create mode 100644 app/Filament/Resources/FailedJobResource/Pages/ViewFailedJobs.php create mode 100644 database/factories/FailedJobFactory.php create mode 100644 tests/Unit/Filament/FailedJobResourceTest.php diff --git a/app/Filament/Resources/FailedJobsResource.php b/app/Filament/Resources/FailedJobResource.php similarity index 94% rename from app/Filament/Resources/FailedJobsResource.php rename to app/Filament/Resources/FailedJobResource.php index e552d59e..8b33a28a 100644 --- a/app/Filament/Resources/FailedJobsResource.php +++ b/app/Filament/Resources/FailedJobResource.php @@ -4,7 +4,8 @@ namespace App\Filament\Resources; -use App\Filament\Resources\FailedJobsResource\ListFailedJobs; +use App\Filament\Resources\FailedJobResource\Pages\ListFailedJobs; +use App\Filament\Resources\FailedJobResource\Pages\ViewFailedJobs; use App\Models\FailedJob; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; @@ -24,7 +25,7 @@ /** * @source https://gitlab.com/amvisor/filament-failed-jobs */ -class FailedJobsResource extends Resource +class FailedJobResource extends Resource { protected static ?string $model = FailedJob::class; @@ -107,6 +108,8 @@ public static function getPages(): array { return [ 'index' => ListFailedJobs::route('/'), + 'view' => ViewFailedJobs::route('/{record}'), + ]; } } diff --git a/app/Filament/Resources/FailedJobsResource/ListFailedJobs.php b/app/Filament/Resources/FailedJobResource/Pages/ListFailedJobs.php similarity index 88% rename from app/Filament/Resources/FailedJobsResource/ListFailedJobs.php rename to app/Filament/Resources/FailedJobResource/Pages/ListFailedJobs.php index f992fba1..c9cae25c 100644 --- a/app/Filament/Resources/FailedJobsResource/ListFailedJobs.php +++ b/app/Filament/Resources/FailedJobResource/Pages/ListFailedJobs.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace App\Filament\Resources\FailedJobsResource; +namespace App\Filament\Resources\FailedJobResource\Pages; -use App\Filament\Resources\FailedJobsResource; +use App\Filament\Resources\FailedJobResource; use App\Models\FailedJob; use Filament\Notifications\Notification; use Filament\Pages\Actions\Action; @@ -13,7 +13,7 @@ class ListFailedJobs extends ListRecords { - protected static string $resource = FailedJobsResource::class; + protected static string $resource = FailedJobResource::class; public function getHeaderActions(): array { diff --git a/app/Filament/Resources/FailedJobResource/Pages/ViewFailedJobs.php b/app/Filament/Resources/FailedJobResource/Pages/ViewFailedJobs.php new file mode 100644 index 00000000..6bb78f54 --- /dev/null +++ b/app/Filament/Resources/FailedJobResource/Pages/ViewFailedJobs.php @@ -0,0 +1,13 @@ +N4_% zCUi*!TfC!g5^?&pve!I_iMDA$(Hv)kZ$~tCTy|q{Wgfcr7TPe zH`&t;+!=?58aX7d*j2(pPY?yQd$IRBhh{?qvH}}3u*{0odTG}hfj{XJ9}dYIw(>(p zk~Je6B-|IoV=I~l2@wgfJdzyd>kA&s=KsPjIiUgH1$35k~~Y+zR>3@`jv5gjvrwfq-*%e;Q!u# zz=l2=^~uY*^6|Xd=tg14BnfHK_p+$+vXBOzFXDji z&LM#m4(17@hFDxMk;or-tD(xC|G;M)U%!+;e<0t*DGdVo=bpVH#?s}KO6eBOaLgTpqEVchiSs}Cy?VL`+kHCcg!DV zUvIW_%-Kytrhl$xVePfg@&s3b+~>PPkOnM3g6^4jMEsB#-zhh?+pV!qHi1Fo*Z>1z zpr!nQw6dPNT)O z8$=@I>;^emkLFYYl+;e_HfqS;anf+hY5ab5s#qWi`-hXT$897^bR7rvxby+Jj2_Kp z9}77hlZo}8sUZHiBmV1D7;j(`qlvp_Ttb`HaU1lWqdvzuK;TJ7;NSh21+XfN{6S%l zMpbO!w*;Oy|;oOrMEyYqLD9WaiBxYARZK3revc&8v zr+3Gzrl|Pm^=|Q~hH2DQSrs+8w`W`W zz#P_=P%EWe-OR4Ks?h&}av)RHkzJD$g^m31zyPNsKO1mYMZE=SA2&iOQu;jRkqbqe zoaC<3c?;8=Vog(0X*J9olcymJRzh}_Mg<8wk%$6jpyN|@22d*1Jk2@2N7)9?tB_ZZ z)W|k`t2xD#`JzNupTlG*UdYGlDwq2`xw*W&6^d-;s#J<<)9R{^1&{xs-0Uil1*uZK zCKIJYy=iq-$#xdq3r?%6E*50=PjW&YT5(!kr4eA|(k(Ar%dBlydv3)UrKmZr7Ks$Q z%_<6ahFe8|6PUatki)d5HBrpy0FE@$=j@8PX(BfttE(Y!k)4eMBWj`rM2DOv7xF z5!7xGy!$}S36AO^pc1XCti8iCyPQ-!$jik2jq#AF1GRbbfEmc*Y1hS!^28T39Mr|2 zfZpebf-c_<*fzP|!1Y4?+N7_pJibtMmsh=lg#j_V=^Gpr7b~A<@{;vNyV3pyVuwithPersonalOrganization()->create([ + 'email' => 'admin@example.com', + ]); + + $this->actingAs($user); + } + + public function test_can_list_failed_jobs(): void + { + // Arrange + $failedJobs = FailedJob::factory()->createMany(5); + + // Act + $response = Livewire::test(FailedJobResource\Pages\ListFailedJobs::class); + + // Assert + $response->assertSuccessful(); + $response->assertCanSeeTableRecords($failedJobs); + } + + public function test_can_see_view_page_of_failed_job(): void + { + // Arrange + $failedJob = FailedJob::factory()->create(); + + // Act + $response = Livewire::test(ViewFailedJobs::class, ['record' => $failedJob->getKey()]); + + // Assert + $response->assertSuccessful(); + } +}