Problem/Motivation
The o365_sharepoint_field autocomplete widget ships a client-side behavior (Drupal.behaviors.o365SharePointSearchAutocomplete in js/o365_sharepoint_field.autocomplete.js) that, on selecting an autocomplete result, copies the selected item's hitId and driveId into the hidden .o365-sharepoint-hit-id and .o365-sharepoint-drive-id fields. This behavior currently has no automated test coverage.
While adding a test, two things surfaced:
- The
o365_sharepoint_field/autocompletelibrary uses thejQuery,DrupalanddrupalSettingsglobals but does not declarecore/jquery,core/drupalorcore/drupalSettingsas dependencies. It only works today because the widget happens to attachcore/drupal.ajaxalongside it, which pulls those globals in transitively. If that ever changes, the behavior breaks silently. - There was no way to exercise the behavior in a browser test, because the widget only renders its markup when
AuthenticationService::checkForOfficeLogin()returnsTRUE(which requires an active Microsoft 365 login and is not reliably reproducible in a functional-JS test).
Steps to reproduce (dependency issue)
Attach only o365_sharepoint_field/autocomplete to a page (without core/drupal.ajax) and select an autocomplete result — the behavior throws because jQuery/Drupal are undefined.
Proposed resolution
- Declare the missing dependencies on the
autocompletelibrary:
dependencies: - core/jquery - core/drupal - core/drupalSettings - Add a
FunctionalJavascripttest (SharePointAutocompleteBehaviorTest) that verifies selecting an autocomplete result populates the hidden hit-id/drive-id fields. - Add a small, hidden test-support module (
o365_sharepoint_field_test,hidden: true) that renders the same widget markup and attaches only the module's own library — so the test both exercises the real shipped JS and guards against the library dependencies regressing, without needing a Microsoft 365 login.
Remaining tasks
- Review the merge request.
- Confirm the GitLab CI pipeline (incl. the new functional-javascript job) passes.
Issue fork o365-3610574
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
Comment #3
fabianderijkFix is being merged into 6.0.x branch.