testing panels in pest?

I have 2 panels with admin as the default panel. now, when I want to write tests for the App Panel, then im facing problems. 1. the routes are not correct SomeResource::getUrl() returns an admin route and not a App route. 2. If I use a route() instead, then the $tenant url parameter is missing. Is there any nice way to test the non default panel in filament without writing tons of pest setup code?
4 Replies
ConnorHowell
ConnorHowell13mo ago
You need to pass the panel id to the getUrl method In the argument list for getUrl just do panel: 'panel_id_here'
Mads Møller
Mads MøllerOP13mo ago
Hi Connor, I do: $this->get(TenantResource::getUrl(name:'index', panel:'app')) But it still returns the admin route which is a "route not defined" exception. wait.. it works. Thanks very much! But wait.. this still is not the solution, as the livewire helper is not working as expected: livewire(SomeResource\Pages\ListTextEntries::class) ->assertCanSeeTableRecords($textEntries); This still gets the wrong route.
tim_vdv
tim_vdv13mo ago
Hello, I'm writing my tests for both the Admin and App panels using a LoginHelper. The LoginHelper contains a login function for both the Admin and App panels. In each test file, I utilize the LoginHelper with the appropriate function based on the nature of the test (admin or app). Example below: LoginHelper.php:
trait LoginHelper
{
public function AdminLogin(){
$user = User::factory()
->create(['is_super_admin' => 1]);
$this->actingAs($user);
}

public function AppLogin(){
$user = User::factory()
->create(['is_admin' => 1]);
$this->actingAs($user);

$organization = Organization::factory()->create();

$user->teams()->attach($organization->id);
\Filament\Facades\Filament::setCurrentPanel(\Filament\Facades\Filament::getPanel('app'));
\Filament\Facades\Filament::setTenant($organization);
}
}
trait LoginHelper
{
public function AdminLogin(){
$user = User::factory()
->create(['is_super_admin' => 1]);
$this->actingAs($user);
}

public function AppLogin(){
$user = User::factory()
->create(['is_admin' => 1]);
$this->actingAs($user);

$organization = Organization::factory()->create();

$user->teams()->attach($organization->id);
\Filament\Facades\Filament::setCurrentPanel(\Filament\Facades\Filament::getPanel('app'));
\Filament\Facades\Filament::setTenant($organization);
}
}
TestFile:
uses(\Tests\LoginHelper::class);

beforeEach(function (){
$this->AppLogin();
});

it('can render table', function () {
livewire(\App\Filament\App\Resources\PresentResource\Pages\ManageTimes::class)->assertSuccessful();
});
uses(\Tests\LoginHelper::class);

beforeEach(function (){
$this->AppLogin();
});

it('can render table', function () {
livewire(\App\Filament\App\Resources\PresentResource\Pages\ManageTimes::class)->assertSuccessful();
});
Mads Møller
Mads MøllerOP13mo ago
Thank you @tim_vdv the below did the trick \Filament\Facades\Filament::setCurrentPanel(\Filament\Facades\Filament::getPanel('app')); \Filament\Facades\Filament::setTenant($organization);
Want results from more Discord servers?
Add your server