Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devsquad-luan-freitas committed Jul 18, 2024
1 parent 57720b1 commit e72c4f6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Components/Actions/Macros.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function boot(): void
"component" => "button",
"attribute" => "wire:click",
"value" => function ($component, $row) {
return 'toggleDetail(\'' . data_get($row, $component->primaryKey) . '\')';
return 'toggleDetail(\'' . data_get($row, $component->realPrimaryKey) . '\')';
},
];

Expand Down
58 changes: 48 additions & 10 deletions tests/Feature/Buttons/ToggleDetailTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

use Illuminate\Database\Eloquent\Builder;
use PowerComponents\LivewirePowerGrid\Button;
use PowerComponents\LivewirePowerGrid\Tests\Concerns\Components\DishTableBase;

use PowerComponents\LivewirePowerGrid\Tests\Concerns\Models\Dish;

use function PowerComponents\LivewirePowerGrid\Tests\Plugins\livewire;

$component = new class () extends DishTableBase {
Expand All @@ -16,17 +19,32 @@ public function actions($row): array
}
};

dataset('action:toggleDetail', [
'tailwind' => [$component::class, (object) ['theme' => 'tailwind', 'join' => false]],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => false]],
'tailwind join' => [$component::class, (object) ['theme' => 'tailwind', 'join' => true]],
'bootstrap join' => [$component::class, (object) ['theme' => 'bootstrap', 'join' => true]],
]);
$dotNotationPrimaryKeyComponent = new class () extends DishTableBase {
public string $primaryKey = 'dishes.id';

public ?string $primaryKeyAlias = 'id';

public function dataSource(): Builder
{
return Dish::query()
->join('categories as newCategories', function ($categories) {
$categories->on('dishes.category_id', '=', 'newCategories.id');
})
->select('dishes.*', 'newCategories.name as category_name');
}

public function actions($row): array
{
return [
Button::make('toggleDetail')
->slot('toggleDetail: ' . $row->id)
->toggleDetail(),
];
}
};

it('properly displays "toggleDetail" on edit button', function (string $component, object $params) {
livewire($component, [
'join' => $params->join,
])
livewire($component)
->call($params->theme)
->set('setUp.footer.perPage', 6)
->assertSeeHtml("wire:click=\"toggleDetail(&#039;1&#039;)\">toggleDetail: 1</button>")
Expand All @@ -36,5 +54,25 @@ public function actions($row): array
->assertSeeHtml("wire:click=\"toggleDetail(&#039;7&#039;)\">toggleDetail: 7</button>")
->assertDontSeeHtml("wire:click=\"toggleDetail(&#039;1&#039;)\">toggleDetail: 1</button>");
})
->with('action:toggleDetail')
->with([
'tailwind' => [$component::class, (object) ['theme' => 'tailwind']],
'bootstrap' => [$component::class, (object) ['theme' => 'bootstrap']],
])
->group('action');

it('properly displays "toggleDetail" on edit button using dot notation in primaryKey', function (string $component, object $params) {
livewire($component)
->call($params->theme)
->set('setUp.footer.perPage', 6)
->assertSeeHtml("\"toggleDetail(&#039;1&#039;)\">toggleDetail: 1</button>")
->assertSeeHtml("\"toggleDetail(&#039;2&#039;)\">toggleDetail: 2</button>")
->assertDontSeeHtml("wire:click=\"toggleDetail(&#039;7&#039;)\">toggleDetail: 7</button>")
->call('setPage', 2)
->assertSeeHtml("wire:click=\"toggleDetail(&#039;7&#039;)\">toggleDetail: 7</button>")
->assertDontSeeHtml("wire:click=\"toggleDetail(&#039;1&#039;)\">toggleDetail: 1</button>");
})
->with([
'tailwind join primary key alias' => [$dotNotationPrimaryKeyComponent::class, (object) ['theme' => 'tailwind']],
'bootstrap join primary key alias' => [$dotNotationPrimaryKeyComponent::class, (object) ['theme' => 'bootstrap']],
])
->group('action');
4 changes: 2 additions & 2 deletions tests/Feature/DetailRowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
}

$component->assertSeeHtmlInOrder($xData);
})->skip();
});

it('collapse detail row with collapseOthers', function () {
livewire(RulesToggleDetailTable::class, [
Expand Down Expand Up @@ -184,4 +184,4 @@
4 => false,
5 => false,
]);
})->skip();
});

0 comments on commit e72c4f6

Please sign in to comment.