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:

  1. The o365_sharepoint_field/autocomplete library uses the jQuery, Drupal and drupalSettings globals but does not declare core/jquery, core/drupal or core/drupalSettings as dependencies. It only works today because the widget happens to attach core/drupal.ajax alongside it, which pulls those globals in transitively. If that ever changes, the behavior breaks silently.
  2. There was no way to exercise the behavior in a browser test, because the widget only renders its markup when AuthenticationService::checkForOfficeLogin() returns TRUE (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 autocomplete library:
    dependencies:
      - core/jquery
      - core/drupal
      - core/drupalSettings
  • Add a FunctionalJavascript test (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

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

fabianderijk created an issue. See original summary.

fabianderijk’s picture

Status: Active » Fixed

Fix is being merged into 6.0.x branch.

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.