Skip to content

TestHelper selector for grouped actions does not work. #7518

@GregoireGiraud

Description

@GregoireGiraud

Describe the bug

Test helper method getActionSelector of EasyCorp\Bundle\EasyAdminBundle\Test\Trait\CrudTestSelectors did not get updated to work with new grouped actions from latest updates : https://symfony.com/bundles/EasyAdminBundle/current/actions.html#grouping-actions

In my application tests, I test which action was visible in my index page like this.

$this->assertIndexEntityActionExists('createPlan', $entityId);

Before switching to grouped actions, it worked, and after, it broke.

To Reproduce
Easy admin version : v5.0.2

Adding an action group with actions in my crud controller :

 #[\Override] public function configureActions(Actions $actions): Actions { $integrationActions = ActionGroup::new('integrations', 'Integrations') ->setIcon('fa-solid fa-plug') // [...] ->addAction($this->getCreatePlan()) ; return parent::configureActions($actions) ->add(Crud::PAGE_INDEX, $integrationActions) ->add(Crud::PAGE_DETAIL, $integrationActions) ; }

Additional context

Root cause : Grouped actions do not have the css class action-ACTION_NAME (ex: action-createPlan in my case).
They however do have a data-action-name=ACTION_NAME attribute.

I fixed the bug easily for my tests, by overriding the getActionSelector method like this :

namespace App\Tests\Application\Admin\TestHelpers; use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\CrudControllerInterface; use EasyCorp\Bundle\EasyAdminBundle\Test\AbstractCrudTestCase; /**  * @template Crud of CrudControllerInterface<object>  *  * @extends AbstractCrudTestCase<Crud>  */ abstract class MyCustomAbstractCrudTestCase extends AbstractCrudTestCase { #[\Override] protected function getActionSelector(string $action): string { return sprintf('[data-action-name="%1$s"], .action-%1$s', $action); } }

Please contact me if you need more details ! I would glady see the PR to correct this issue, and next time, i can contribute directly by submitting mine. Here, i feel like my solution might be too hacky.

Thanks a lot,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions