Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ jobs:
env:
CREATE_SNAPSHOTS: "false"

# Panel/authorization tests, nothing database specific, so the sqlite job covers them.
- name: Filament tests
run: vendor/bin/pest tests/Filament --parallel --do-not-fail-on-phpunit-warning
env:
CREATE_SNAPSHOTS: "false"

mysql:
name: MySQL
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<testsuite name="Unit">
<directory>./tests/Unit</directory>
</testsuite>
<testsuite name="Filament">
<directory>./tests/Filament</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
Expand Down
13 changes: 9 additions & 4 deletions tests/Filament/Admin/ListEggsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
use App\Filament\Admin\Resources\Eggs\Pages\ListEggs;
use App\Models\Egg;
use App\Models\Role;
use Filament\Facades\Filament;
use Spatie\Permission\Models\Permission;

use function Pest\Livewire\livewire;

// These tables live on the admin panel; without this the default 'app' panel is
// used and the resources' action urls fail to resolve.
beforeEach(fn () => Filament::setCurrentPanel(Filament::getPanel('admin')));
afterEach(fn () => Filament::setCurrentPanel(null));

it('root admin can see all eggs', function () {
$eggs = Egg::all();
[$admin] = generateTestAccount([]);
Expand All @@ -22,8 +29,7 @@
it('non root admin cannot see any eggs', function () {
$role = Role::factory()->create(['name' => 'Node Viewer', 'guard_name' => 'web']);
// Node Permission is on purpose, we check the wrong permissions.
$permission = Permission::factory()->create(['name' => RolePermissionModels::Node->viewAny(), 'guard_name' => 'web']);
$role->permissions()->attach($permission);
$role->givePermissionTo(Permission::findOrCreate(RolePermissionModels::Node->viewAny(), 'web'));
[$user] = generateTestAccount([]);

$this->actingAs($user);
Expand All @@ -33,8 +39,7 @@

it('non root admin with permissions can see eggs', function () {
$role = Role::factory()->create(['name' => 'Egg Viewer', 'guard_name' => 'web']);
$permission = Permission::factory()->create(['name' => RolePermissionModels::Egg->viewAny(), 'guard_name' => 'web']);
$role->permissions()->attach($permission);
$role->givePermissionTo(Permission::findOrCreate(RolePermissionModels::Egg->viewAny(), 'web'));

$eggs = Egg::all();
[$user] = generateTestAccount([]);
Expand Down
16 changes: 11 additions & 5 deletions tests/Filament/Admin/ListNodesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@
use App\Models\Role;
use App\Models\Server;
use Filament\Actions\CreateAction;
use Filament\Actions\Testing\TestAction;
use Filament\Facades\Filament;
use Spatie\Permission\Models\Permission;

use function Pest\Livewire\livewire;

// These tables live on the admin panel; without this the default 'app' panel is
// used and the resources' action urls fail to resolve.
beforeEach(fn () => Filament::setCurrentPanel(Filament::getPanel('admin')));
afterEach(fn () => Filament::setCurrentPanel(null));

it('root admin can see all nodes', function () {
[$admin] = generateTestAccount([]);
$admin = $admin->syncRoles(Role::getRootAdmin());
Expand All @@ -24,8 +32,7 @@
it('non root admin cannot see any nodes', function () {
$role = Role::factory()->create(['name' => 'Egg Viewer', 'guard_name' => 'web']);
// Egg Permission is on purpose, we check the wrong permissions.
$permission = Permission::factory()->create(['name' => RolePermissionModels::Egg->viewAny(), 'guard_name' => 'web']);
$role->permissions()->attach($permission);
$role->givePermissionTo(Permission::findOrCreate(RolePermissionModels::Egg->viewAny(), 'web'));
[$user] = generateTestAccount();

$this->actingAs($user);
Expand All @@ -35,8 +42,7 @@

it('non root admin with permissions can see nodes', function () {
$role = Role::factory()->create(['name' => 'Node Viewer', 'guard_name' => 'web']);
$permission = Permission::factory()->create(['name' => RolePermissionModels::Node->viewAny(), 'guard_name' => 'web']);
$role->permissions()->attach($permission);
$role->givePermissionTo(Permission::findOrCreate(RolePermissionModels::Node->viewAny(), 'web'));

[$user] = generateTestAccount();
$nodes = Node::all();
Expand All @@ -61,5 +67,5 @@
livewire(ListNodes::class)
->assertSuccessful()
->assertHeaderMissing(CreateAction::class)
->assertActionExists(CreateAction::class);
->assertActionExists(TestAction::make('create')->table());
});
Loading