Skip to content

Commit

Permalink
Added tests for FailedJobResource and renamed to singular
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Jul 18, 2024
1 parent 8db0a7d commit 63323d8
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -107,6 +108,8 @@ public static function getPages(): array
{
return [
'index' => ListFailedJobs::route('/'),
'view' => ViewFailedJobs::route('/{record}'),

];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,7 +13,7 @@

class ListFailedJobs extends ListRecords
{
protected static string $resource = FailedJobsResource::class;
protected static string $resource = FailedJobResource::class;

public function getHeaderActions(): array
{
Expand Down
13 changes: 13 additions & 0 deletions app/Filament/Resources/FailedJobResource/Pages/ViewFailedJobs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\FailedJobResource\Pages;

use App\Filament\Resources\FailedJobResource;
use Filament\Resources\Pages\ViewRecord;

class ViewFailedJobs extends ViewRecord
{
protected static string $resource = FailedJobResource::class;
}
3 changes: 3 additions & 0 deletions app/Models/FailedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;

Expand All @@ -15,6 +16,8 @@
*/
class FailedJob extends Model
{
use HasFactory;

/**
* Indicates if the model should be timestamped.
*
Expand Down
Binary file added database/factories/FailedJobFactory.php
Binary file not shown.
53 changes: 53 additions & 0 deletions tests/Unit/Filament/FailedJobResourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace Tests\Unit\Filament;

use App\Filament\Resources\FailedJobResource;
use App\Filament\Resources\FailedJobResource\Pages\ViewFailedJobs;
use App\Models\FailedJob;
use App\Models\User;
use Illuminate\Support\Facades\Config;
use Livewire\Livewire;
use PHPUnit\Framework\Attributes\UsesClass;

#[UsesClass(FailedJobResource::class)]
class FailedJobResourceTest extends FilamentTestCase
{
protected function setUp(): void
{
parent::setUp();
Config::set('auth.super_admins', ['[email protected]']);
$user = User::factory()->withPersonalOrganization()->create([
'email' => '[email protected]',
]);

$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();
}
}

0 comments on commit 63323d8

Please sign in to comment.