tim_vdv
tim_vdv
FFilament
Created by Hugo on 12/6/2023 in #❓┊help
[Tests] What's the way to fill a form that has a repeater ?
In this way, you populate a repeater; I haven't tested whether this also works in a relation manager.
livewire(CreateEmployee::class)
->fillForm([...])
->set('data.items', [
[
'name' => fake()->name,
'quantity' => fake()->randomNumber(1)
]
])
->call('create')
->assertHasNoFormErrors();
livewire(CreateEmployee::class)
->fillForm([...])
->set('data.items', [
[
'name' => fake()->name,
'quantity' => fake()->randomNumber(1)
]
])
->call('create')
->assertHasNoFormErrors();
2 replies
FFilament
Created by Hugo on 12/6/2023 in #❓┊help
[Testing] How to mount a table header action and make sure that the event was dispatched?
Can't you just test if you can create a record through the relation manager?
it('can create contract', function(): void {
$client = Client::query()->first();

livewire(ContractsRelationManager::class, [
'ownerRecord' => $client,
'pageClass' => EditClient::class,
])->callTableAction(CreateAction::class, data: [
'name' => 'John',
])->assertHasNoTableActionErrors();;
});
it('can create contract', function(): void {
$client = Client::query()->first();

livewire(ContractsRelationManager::class, [
'ownerRecord' => $client,
'pageClass' => EditClient::class,
])->callTableAction(CreateAction::class, data: [
'name' => 'John',
])->assertHasNoTableActionErrors();;
});
2 replies
FFilament
Created by ciorici on 10/19/2023 in #❓┊help
Repeater deleteAction
Repeater::make('members')
->schema([
// ...
])
->deleteAction(
fn (Action $action) => $action->after(fn() => yourFunction()),
)
Repeater::make('members')
->schema([
// ...
])
->deleteAction(
fn (Action $action) => $action->after(fn() => yourFunction()),
)
2 replies
FFilament
Created by Mads Møller on 11/3/2023 in #❓┊help
testing panels in pest?
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();
});
8 replies
FFilament
Created by Monarca on 9/30/2023 in #❓┊help
detect the removal of a repeater
Hello, there's an deleteAction which you can add to the Repeater component. In the deleteAction you return the $action with an ->after method. In this after method you can call your function to calculate the costs. Example below: Repeater::make('members') ->schema([ // ... ]) ->deleteAction( fn (Action $action) => $action->after(fn() => yourFunction()), )
2 replies