You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing tests for my project, and was wondering how to best go about writing a smoke test for all Fabricator pages. I'm using Laravel Pest.
@Z3d0X You said the TestCase class included in the package wasn't extendable as a testcase for the fabrictator pages? Is there a preferred 'best' way of testing the pages generated by the plugin?
Currently I've created a couple of feature tests where I randomly grab a page, then insert it into a manually created Request object.
The tests are passing, though I'm wondering if this is the 'correct' way to do it.
It's also only really testing a single page row this way and I'd like to test the pages with every row of data I have.
Here is one of my tests' code:
TestCase.php
public function countryPage(): array
{
$page = Page::where('page_type','country')->inRandomOrder()->take(1)->get();
$country = Subdomain::where(['country_id' => $page[0]->country_id])->get('slug');
return ['page' => $this->insertFabricatorPage($page[0]->id), 'country' => $country];
}
public function insertFabricatorPage($pageId)
{
return FilamentFabricator::getPageModel()::query()
->where('id', $pageId)
->firstOrFail();
}
CountryTest.php
<?php
use App\Livewire\CountryContent;
use App\Livewire\CountryFooting;
use App\Livewire\CountryHeading;
use Livewire\Livewire;
beforeEach(closure: function() {
$this->request = new \Illuminate\Http\Request();
$this->request->merge(['filamentFabricatorPage' => $this->countryPage()['page'], 'subDomain' => $this->countryPage()['page']['sub_domain']]);
$this->withSession(['userIp' => '86.204.31.189']);
});
describe('Country', function () {
it('renders heading', function () {
Livewire::test(CountryHeading::class, ['request' => $this->request])
->assertStatus(200);
});
it('renders content', function () {
Livewire::test(CountryContent::class, ['request' => $this->request])
->assertStatus(200);
});
it('renders footing', function () {
Livewire::test(CountryFooting::class, ['request' => $this->request])
->assertStatus(200);
});
});
Generally I'm just looking for some tips, tricks, advice or whatever may help me improve my code! Thanks in advance.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi there,
I'm writing tests for my project, and was wondering how to best go about writing a smoke test for all Fabricator pages. I'm using Laravel Pest.
@Z3d0X You said the TestCase class included in the package wasn't extendable as a testcase for the fabrictator pages? Is there a preferred 'best' way of testing the pages generated by the plugin?
Currently I've created a couple of feature tests where I randomly grab a page, then insert it into a manually created Request object.
The tests are passing, though I'm wondering if this is the 'correct' way to do it.
It's also only really testing a single page row this way and I'd like to test the pages with every row of data I have.
Here is one of my tests' code:
TestCase.php
CountryTest.php
Generally I'm just looking for some tips, tricks, advice or whatever may help me improve my code! Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions