How to test a simple resource CRUD functionality?

I read the documentation but I can't find any sample how to test the simple resource? In the docs all you need to is to call CreatePost::class from resource page but in the simple resource all you can see is a ManagePost::class . How do I test it? Below code is my test:
it('can create apps', function () {
$mailchimp = App::factory()->make([
'name' => Constant::MAILCHIMP,
'app_code' => Constant::APP_CODE[Constant::MAILCHIMP],
]);

livewire(ManageApps::class)
->fillForm([
'name' => $mailchimp->name,
'app_code' => $mailchimp->app_code,
'description' => $mailchimp->description,
'is_active' => $mailchimp->is_active
])
->call('create')
->assertHasNoFormErrors();

$this->assertDatabaseHas(App::class, [
'title' => $mailchimp->name,
'app_code' => $mailchimp->app_code,
'description' => $mailchimp->description,
'is_active' => $mailchimp->is_active
]);
});
it('can create apps', function () {
$mailchimp = App::factory()->make([
'name' => Constant::MAILCHIMP,
'app_code' => Constant::APP_CODE[Constant::MAILCHIMP],
]);

livewire(ManageApps::class)
->fillForm([
'name' => $mailchimp->name,
'app_code' => $mailchimp->app_code,
'description' => $mailchimp->description,
'is_active' => $mailchimp->is_active
])
->call('create')
->assertHasNoFormErrors();

$this->assertDatabaseHas(App::class, [
'title' => $mailchimp->name,
'app_code' => $mailchimp->app_code,
'description' => $mailchimp->description,
'is_active' => $mailchimp->is_active
]);
});
Solution:
Hi ! This is my code for testing simple resource : ```php it('can create a new origin', function(){ $newData = AccountOrigin::factory()->make(); livewire(AccountOriginResource\Pages\ManageAccountOrigins::class) ->mountAction('create')...
Jump to solution
3 Replies
jaocero
jaocero9mo ago
Up
Solution
Jonathan G
Jonathan G8mo ago
Hi ! This is my code for testing simple resource :
it('can create a new origin', function(){
$newData = AccountOrigin::factory()->make();
livewire(AccountOriginResource\Pages\ManageAccountOrigins::class)
->mountAction('create')
->setActionData([
'name' => $newData->name,
'description' => $newData->description,
])
->callMountedAction();

$this->assertDatabaseHas(AccountOrigin::class, [
'name' => $newData->name,
'description' => $newData->description,
]);
});
it('can create a new origin', function(){
$newData = AccountOrigin::factory()->make();
livewire(AccountOriginResource\Pages\ManageAccountOrigins::class)
->mountAction('create')
->setActionData([
'name' => $newData->name,
'description' => $newData->description,
])
->callMountedAction();

$this->assertDatabaseHas(AccountOrigin::class, [
'name' => $newData->name,
'description' => $newData->description,
]);
});
groenewege
groenewege6mo ago
This is how I test modal actions on a relation page, which is similar to a simple (modal) resource :
test('superadmin can create sub-tag', function () {
$this->signInAsSuperAdmin();
$tag = Tag::where('name', 'Prévention')->first();
livewire(ManageTagChildren::class, ['record' => $tag->id])
->callTableAction('create', null, [
'name' => 'tag bis',
]);

$this->assertDatabaseHas(Tag::class, [
'name' => 'tag bis',
]);
});

test('superadmin can edit sub-tag', function () {
$this->signInAsSuperAdmin();
$tag = Tag::where('name', 'Prévention')->first();
$subTag = Tag::where('name', 'Vaccination')->first();
livewire(ManageTagChildren::class, ['record' => $tag->id])
->callTableAction('edit', $subTag, [
'name' => 'tag ter',
]);

$this->assertDatabaseHas(Tag::class, [
'name' => 'tag ter',
]);
});
test('superadmin can create sub-tag', function () {
$this->signInAsSuperAdmin();
$tag = Tag::where('name', 'Prévention')->first();
livewire(ManageTagChildren::class, ['record' => $tag->id])
->callTableAction('create', null, [
'name' => 'tag bis',
]);

$this->assertDatabaseHas(Tag::class, [
'name' => 'tag bis',
]);
});

test('superadmin can edit sub-tag', function () {
$this->signInAsSuperAdmin();
$tag = Tag::where('name', 'Prévention')->first();
$subTag = Tag::where('name', 'Vaccination')->first();
livewire(ManageTagChildren::class, ['record' => $tag->id])
->callTableAction('edit', $subTag, [
'name' => 'tag ter',
]);

$this->assertDatabaseHas(Tag::class, [
'name' => 'tag ter',
]);
});