© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•6mo ago•
4 replies
acroninja

how to test outcome of an action?

I can't seem to find an example of how to test an actions outcome after submitting the form.

I have an action like this:-
    public static function applyConfiguration($action): void
    {
        $action
            ->name('bulk-update-lineitem-status')
            ->icon('heroicon-o-arrows-up-down')
            ->modalHeading('Change Line Item Status')
            ->modalDescription(static fn () => new HtmlString("<p class='text-start'>Are you sure you want to change the status of these line items?</p>"))
            ->schema([
                Select::make('status')
                    ->options(LineItemStatus::selectArray())
                    ->native(false)
                    ->preload(),
            ])
            ->modalWidth(Width::Medium)
            ->action(static function (array $data, Collection $records): void {
                foreach ($records as $record) {
                    $record->update($data);
                }
            });
    }
    public static function applyConfiguration($action): void
    {
        $action
            ->name('bulk-update-lineitem-status')
            ->icon('heroicon-o-arrows-up-down')
            ->modalHeading('Change Line Item Status')
            ->modalDescription(static fn () => new HtmlString("<p class='text-start'>Are you sure you want to change the status of these line items?</p>"))
            ->schema([
                Select::make('status')
                    ->options(LineItemStatus::selectArray())
                    ->native(false)
                    ->preload(),
            ])
            ->modalWidth(Width::Medium)
            ->action(static function (array $data, Collection $records): void {
                foreach ($records as $record) {
                    $record->update($data);
                }
            });
    }


And a test that gets so far to populate but I can't see how to now execute the action..

it('can update multiple line item statuses at once', function (): void {

    $this->actingAs(\App\Models\Admin::factory()->create());

    $order = Order::factory()->create();
    $product = Product::factory()->create();

    $lineItems = LineItem::factory()->count(3)->create([
        'order_id' => $order->id,
        'product_id' => $product->id,
        'status' => LineItemStatus::PENDING_ASSOCIATE_ASSIGNMENT,
    ]);

    $action = BulkChangeLineItemStatus::make();

    // Test that the action can be created and bulk update functionality exists
    expect($action)->toBeInstanceOf(BulkChangeLineItemStatus::class)
        ->and($lineItems)->toHaveCount(3)
        ->and($lineItems->first()->status)->toBe(LineItemStatus::PENDING_ASSOCIATE_ASSIGNMENT);

    //How to now open the action modal and set a new status?
});
it('can update multiple line item statuses at once', function (): void {

    $this->actingAs(\App\Models\Admin::factory()->create());

    $order = Order::factory()->create();
    $product = Product::factory()->create();

    $lineItems = LineItem::factory()->count(3)->create([
        'order_id' => $order->id,
        'product_id' => $product->id,
        'status' => LineItemStatus::PENDING_ASSOCIATE_ASSIGNMENT,
    ]);

    $action = BulkChangeLineItemStatus::make();

    // Test that the action can be created and bulk update functionality exists
    expect($action)->toBeInstanceOf(BulkChangeLineItemStatus::class)
        ->and($lineItems)->toHaveCount(3)
        ->and($lineItems->first()->status)->toBe(LineItemStatus::PENDING_ASSOCIATE_ASSIGNMENT);

    //How to now open the action modal and set a new status?
});
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How to test an action in the getFormAction
FilamentFFilament / ❓┊help
6mo ago
How to test Infolist Action?
FilamentFFilament / ❓┊help
2y ago
Test an Action with `requiresConfirmation()`
FilamentFFilament / ❓┊help
2y ago
How to test a custom action?
FilamentFFilament / ❓┊help
3y ago