Problem/Motivation

FunctionJavascript tests take much longer to run than Functional tests, that's why they should stay focused on really testing the Javascript features of the module and more specifically: Try to test as much code from admin_toolbar_search.js as possible.

Currently, a lot of modules' logic tested in admin_toolbar_search FunctionalJavascript test classes could actually be tested with Functional tests and in fact has already been addressed in #3550604: Automated Tests: Add Functional tests for classes ExtraLinks and SearchLinks.

Most of the logic tested in \Drupal\Tests\admin_toolbar_search\FunctionalJavascript\AdminToolbarSearchTest has already been moved to Drupal\Tests\admin_toolbar_search\Functional\AdminToolbarSearchSettingsFormTest, so it could grealy be simplified, to focus mostly on testing the JS search autocomplete features of the module.

All the logic related with the creation of entity type bundles, such as Media types, Content types or Menus could be removed in files:
admin_toolbar_search/tests/src/FunctionalJavascript/AdminToolbarSearchTestBase.php
admin_toolbar_search/tests/src/FunctionalJavascript/AdminToolbarToolsSearchTest.php

Since all of these tests should now be addressed and covered by Functional test classes in 'admin_toolbar_tools', see related issue.

The same goes for any logic related with creating, updating or deleting entity type bundles.

Steps to reproduce

Run PHPUNIT Tests for the admin_toolbar_search module.
Run PHPUNIT FunctionalJavascript Test AdminToolbarToolsSearchTest.
Run PHPUNIT FunctionalJavascript Test AdminToolbarSearchTest.

Proposed resolution

Update existing FunctionJavascript classes to only really keep tests for the Javascript logic specific to the 'admin_toolbar_search' module.

In particular, try testing how the admin_toolbar_tools modules integrates with the JS logic of the module, by loading extra links via AJAX.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dydave created an issue. See original summary.

dydave’s picture

Status: Active » Needs review

Quick follow-up on this issue:

All the changes detailed in the issue summary have been implemented and described in the merge request MR !175 above at #2.

Since all the tests and jobs still seem to be passing 🟢, moving issue to Needs review as an attempt to get more testing feedback and reviews.

Feel free to let us know if you have any comments, questions or concerns on any aspects of this issue or the suggested changes in the merge request, we would surely be glad to help.
Thanks in advance!

dydave’s picture

This merge request only changes Admin Toolbar Search PHPUNIT Tests files.

Testing feedback or reviews would be greatly appreciated! 😊
Thanks in advance!

  • dydave committed ead152da on 3.x
    Issue #3550652 by dydave: Automated tests: Simplified '...
dydave’s picture

Status: Needs review » Fixed

Quick follow-up on this task:

Overall the Admin Toolbar Search module FunctionalJavascript tests were completely refactored to be mostly re-focused on testing the JS code of the module: admin_toolbar_search.js.
Basically, the tests install the required modules, then perform several searches and ensure the expected results are found in the HTML of the suggestions updated by the JS code.

All the current logic of the integration tests with 'admin_toolbar_tools' was moved out of the 'admin_toolbar_search' module to Functional tests in the 'admin_toolbar_tools' module, in related issue #3550604: Automated Tests: Add Functional tests for classes ExtraLinks and SearchLinks with merge request:
https://git.drupalcode.org/project/admin_toolbar/-/merge_requests/173

In particular, any logic related with SearchLinks and loading of extra links in the search autocomplete was moved to the integration Functional test class AdminToolbarToolsExtraLinksTest, along with any creation of entity bundles, etc...
See also trait AdminToolbarToolsEntityCreationTrait in related issue's merge request.
 

Fixed tests for query strings striped in search for issue #3552640: Exclude random token string in link from Admin Toolbar Search:

To test the issue locally: restore the query string in the search with the following JS test code:

              // Strip query strings from link URLs for searching to prevent generated
              // tokens or destinations from appearing in the search results.
              // const linkUrl = element.linkUrl.split('?')[0].toLowerCase();
              const linkUrl = element.linkUrl.toLowerCase();

and run the test to confirm it fails the check on assertSuggestionsNotContain in class AdminToolbarToolsSearchTest.
 

Since all the tests and jobs still seemed to be passing 🟢, I went ahead and merged the changes above at #5.

Only tests files were changed in this issue so it should not have any impact on the module.
We'll see how to make these tests evolve in the future, as more changes are made to project's code.

Marking issue as Fixed, for now. 🥳

Feel free to let us know if you have any questions or concerns on any of the latest code changes or the project in general, we would be glad to help.
Thanks in advance!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.