From 51c06591a50bc5a57ecceb8d40f7120224da5441 Mon Sep 17 00:00:00 2001 From: Dennis Elsinga Date: Sat, 16 Mar 2024 18:31:49 +0100 Subject: [PATCH] refactor: Refactor resource stub to use data providers --- stubs/Resource.stub | 60 +++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/stubs/Resource.stub b/stubs/Resource.stub index 36528265..56e0912f 100644 --- a/stubs/Resource.stub +++ b/stubs/Resource.stub @@ -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$); + +