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

[6.x] Add Testing assertions for actions (javascript render) #1701

Merged
merged 3 commits into from
Sep 27, 2024

Conversation

luanfreitasdev
Copy link
Collaborator

Since the actions are not rendered with PHP but with JavaScript, it isn't easy to test the complete flow, but we can ensure that the data that is being expected in PowerGrid remains intact with some assertions.

Example:

  • Component
public function actions($row): array
{
    return [
        Button::add('view')
            ->icon('default-eye', [
                'class' => '!text-green-500',
            ])
            ->slot('View')
            ->class('text-slate-500 flex gap-2 hover:text-slate-700 hover:bg-slate-100 font-bold p-1 px-2 rounded')
            ->dispatch('clickToEdit', ['dishId' => $row?->id, 'dishName' => $row?->name]),
    ];
}
  • Test file
livewire(DishesCollectionTable::class)
        ->call('setTestThemeClass', $params->theme)
        ->assertHasAction('view')
        ->assertActionContainsAttribute('view', 'class', 'flex gap-2 hover:text-slate-700')
        ->assertActionContainsAttribute('view', 'wire:click', 'clickToEdit', ['dishId' => 29, 'dishName' => 'Luan'])
        ->assertActionHasIcon('view', 'default-eye', '!text-green-500')

@luanfreitasdev luanfreitasdev changed the title [6.x] Add Testing assertions for actions [6.x] Add Testing assertions for actions (javascript render) Sep 26, 2024
@luanfreitasdev luanfreitasdev merged commit 41db144 into 6.x Sep 27, 2024
20 checks passed
@luanfreitasdev luanfreitasdev deleted the testing-testcolumns branch September 27, 2024 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant