F
Filament2y ago
dyo

Assert button existence

How to assert "new" button existence in top right resource table in php test case? The button isn't always there due to role's permissions..
15 Replies
Dan Harrin
Dan Harrin2y ago
is there assertActionHidden() or something
dyo
dyoOP2y ago
Method Illuminate\Http\Response::assertActionHidden does not exist. 😕
Dan Harrin
Dan Harrin2y ago
assertPageActionHidden()
dyo
dyoOP2y ago
sadly, still method does not exist.. but i've found other way to assert in my case.. anyway, thanks for your suggestion before..
Kenneth Sese
Kenneth Sese2y ago
assertPageActionHidden() does exist. Here's the relevant section and example from the docs: https://filamentphp.com/docs/2.x/admin/testing#deleting
Filament
Testing - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
dyo
dyoOP2y ago
right.. thanks for your help men..
dyo
dyoOP2y ago
how to assert create button in relation manager?
Dan Harrin
Dan Harrin2y ago
use the relation manager as the livewire component to test then assertTableActionExists
dyo
dyoOP2y ago
$response = $this->actingAs($user)
->livewire(
CampaignRefRelationManager::class,
['ownerRecord' => Campaign::find($campaign_id)]
)->assertSuccessful();

if ($user->id_cms_privileges === 2 || $user->id_cms_privileges === 4) {
$response->assertPageActionDoesNotExist('buat');
} else {
$response->assertPageActionExists('buat');
}
$response = $this->actingAs($user)
->livewire(
CampaignRefRelationManager::class,
['ownerRecord' => Campaign::find($campaign_id)]
)->assertSuccessful();

if ($user->id_cms_privileges === 2 || $user->id_cms_privileges === 4) {
$response->assertPageActionDoesNotExist('buat');
} else {
$response->assertPageActionExists('buat');
}
why i'm getting error => getCachedAction does not exist?
Dan Harrin
Dan Harrin2y ago
its not a page action on a relation manager its always a table action
dyo
dyoOP2y ago
hmm okey.. thanks for the correction.. how to assert data creation in relation manager modal form?
LeandroFerreira
You could try something like this:
->livewire(CampaignRefRelationManager::class)
->callPageAction('create', [
'field1' => 'value1',
'field2' => 'value2'
])
->assertHasNoPageActionErrors();
->livewire(CampaignRefRelationManager::class)
->callPageAction('create', [
'field1' => 'value1',
'field2' => 'value2'
])
->assertHasNoPageActionErrors();
dyo
dyoOP2y ago
I tried this
$this->actingAs($user)->livewire(
CampaignRefRelationManager::class,
['ownerRecord' => Campaign::find($campaign_id)]
)->callTableAction(ActionsCreateAction::class)
->fillForm([
'nama_ref' => $judul,
'channel' => 'Facebook',
'prioritas_id' => ($user->prioritas_id)
? $user->prioritas_id : Prioritas::aktif()->inRandomOrder()->first()
])->call('create')->assertHasNoFormErrors()
$this->actingAs($user)->livewire(
CampaignRefRelationManager::class,
['ownerRecord' => Campaign::find($campaign_id)]
)->callTableAction(ActionsCreateAction::class)
->fillForm([
'nama_ref' => $judul,
'channel' => 'Facebook',
'prioritas_id' => ($user->prioritas_id)
? $user->prioritas_id : Prioritas::aktif()->inRandomOrder()->first()
])->call('create')->assertHasNoFormErrors()
and i got => Unable to set component data. Public property [$nama_ref] not found on component: But i've reassure in the relation manager has got :
Forms\Components\TextInput::make('nama_ref')
Forms\Components\TextInput::make('nama_ref')
what should i do?
Dan Harrin
Dan Harrin2y ago
thats not how to fill an action form or call it you just have to pass the data as the third param of callTableAction() you dont need to call it
dyo
dyoOP2y ago
thanks.. solved.. Can someone help me how to assert options in filament form select component?
Want results from more Discord servers?
Add your server