Skip to content

Commit

Permalink
refactor: Refactor resource stub to use data providers
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithDennis committed Mar 16, 2024
1 parent 44e25dc commit 51c0659
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions stubs/Resource.stub
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,32 @@ it('can render page', function () {
livewire(List$modelPluralName$::class)->assertSuccessful();
});

foreach ($resourceTableColumns$ as $column) {
it('can render '.$column.' column', function () use ($column) {
$modelSingularName$::factory()->count(3)->create();

livewire(List$modelPluralName$::class)->assertCanRenderTableColumn($column);
});
}

foreach ($resourceTableSortableColumns$ as $column) {
it('can sort by '.$column, function () use ($column) {
$records = $modelSingularName$::factory()->count(3)->create();

livewire(List$modelPluralName$::class)
->sortTable($column)
->assertCanSeeTableRecords($records->sortBy($column), inOrder: true)
->sortTable($column, 'desc')
->assertCanSeeTableRecords($records->sortByDesc($column), inOrder: true);
});
}

foreach ($resourceTableSearchableColumns$ as $column) {
it('can search by '.$column, function () use ($column) {
$records = $modelSingularName$::factory()->count(3)->create();

$search = $records->first()->{$column};

livewire(List$modelPluralName$::class)
->searchTable($search)
->assertCanSeeTableRecords($records->where($column, $search))
->assertCanNotSeeTableRecords($records->where($column, '!=', $search));
});
}
it('can render column', function (string $column) {
$modelSingularName$::factory()->count(3)->create();

livewire(List$modelPluralName$::class)->assertCanRenderTableColumn($column);
})->with($resourceTableColumns$);

it('can sort column', function (string $column) {
$records = $modelSingularName$::factory()->count(3)->create();

livewire(List$modelPluralName$::class)
->sortTable($column)
->assertCanSeeTableRecords($records->sortBy($column), inOrder: true)
->sortTable($column, 'desc')
->assertCanSeeTableRecords($records->sortByDesc($column), inOrder: true);
})->with($resourceTableSortableColumns$);

it('can search column', function (string $column) {
$records = $modelSingularName$::factory()->count(3)->create();

$search = $records->first()->{$column};

livewire(List$modelPluralName$::class)
->searchTable($search)
->assertCanSeeTableRecords($records->where($column, $search))
->assertCanNotSeeTableRecords($records->where($column, '!=', $search));
})->with($resourceTableSearchableColumns$);



0 comments on commit 51c0659

Please sign in to comment.