Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add unmountTableBulkAction() testing method #15355

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/tables/.stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Livewire\Features\SupportTesting {

use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;

class Testable {
class Testable
{
public function mountTableAction(string | array $name, $record = null): static {}

public function unmountTableAction(): static {}
Expand Down Expand Up @@ -51,6 +51,8 @@ public function assertHasNoTableActionErrors(array $keys = []): static {}

public function mountTableBulkAction(string $name, array | Collection $records): static {}

public function unmountTableBulkAction(): static {}

public function setTableBulkActionData(array $data): static {}

public function assertTableBulkActionDataSet(array | Closure $state): static {}
Expand Down
9 changes: 9 additions & 0 deletions packages/tables/src/Testing/TestsBulkActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ function ($record) {
};
}

public function unmountTableBulkAction(): Closure
{
return function (): static {
$this->call('unmountTableBulkAction');

return $this;
};
}

public function setTableBulkActionData(): Closure
{
return function (array $data): static {
Expand Down
15 changes: 15 additions & 0 deletions tests/src/Tables/Actions/BulkActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Str;

use function Filament\Tests\livewire;
use function Pest\Laravel\assertNotSoftDeleted;
use function Pest\Laravel\assertSoftDeleted;

uses(TestCase::class);
Expand All @@ -22,6 +23,20 @@
}
});

it('can unmount bulk action', function () {
$posts = Post::factory()->count(10)->create();

livewire(PostsTable::class)
->mountTableBulkAction(DeleteBulkAction::class, $posts)
->assertTableBulkActionMounted(DeleteBulkAction::class)
->unmountTableBulkAction()
->assertTableBulkActionNotMounted(DeleteBulkAction::class);

foreach ($posts as $post) {
assertNotSoftDeleted($post);
}
});

it('can call a bulk action with data', function () {
$posts = Post::factory()->count(10)->create();

Expand Down