Also added the ability to pass in a callback function to the assertTableBulkActionDataSet

This commit is contained in:
chester
2024-12-13 10:51:09 +08:00
parent 47350d10a4
commit 1c2657d7f2
3 changed files with 14 additions and 5 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ namespace Livewire\Features\SupportTesting {
public function setTableBulkActionData(array $data): static {}
public function assertTableBulkActionDataSet(array $data): static {}
public function assertTableBulkActionDataSet(array | Closure $state): static {}
public function callTableBulkAction(string $name, array | Collection $records, array $data = [], array $arguments = []): static {}
@@ -70,9 +70,15 @@ class TestsBulkActions
public function assertTableBulkActionDataSet(): Closure
{
return function (array $data): static {
foreach (Arr::dot($data, prepend: 'mountedTableBulkActionData.') as $key => $value) {
$this->assertSet($key, $value);
return function (array | Closure $state): static {
if ($state instanceof Closure) {
$state = $state($this->get('mountedTableBulkActionData'));
}
if (is_array($state)) {
foreach (Arr::dot($state, prepend: 'mountedTableBulkActionData.') as $key => $value) {
$this->assertSet($key, $value);
}
}
return $this;
+4 -1
View File
@@ -53,7 +53,10 @@ it('can set default bulk action data when mounted', function () {
->mountTableBulkAction('data', records: $posts)
->assertTableBulkActionDataSet([
'foo' => 'bar',
]);
])
->assertTableBulkActionDataSet(function (array $data): bool {
return $data['foo'] === 'bar';
});
});
it('can call a bulk action with arguments', function () {