Spin-off from #2996404-3: Replace old keypress workaround in AjaxFormImageButtonTest.

Problem/Motivation

AjaxFormImageButtonTest has a test to assert that ajax-enabled buttons are keyboard operable, by pressing the ENTER key when focussed. However buttons are expected to respond when either the enter OR spacebar key is pressed. Let's cover this situation too.

It's common to see faux-buttons like this in the wild:

<a href="#" role="button" onclick="foo()">Edit</a>

The button role tells screen readers to announce it as a button, yet it doesn't behave like a button because it can't be activated by the space key. That's a bug we can guard against by testing both keys.

Proposed resolution

Replicate the ENTER key press test in AjaxFormImageButtonTest, so we are testing the desired SPACE key behaviour too.

Remaining tasks

Patch for AjaxFormImageButtonTest.

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andrewmacpherson created an issue. See original summary.

andrewmacpherson’s picture

andrewmacpherson’s picture

Title: Add test to assert ajax buttons are operable with the enter key. » Add test to assert ajax buttons are operable with the spacebar key.

correct key in title.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Krzysztof Domański’s picture

Can we join both tests to improve test performance?

public function testAjaxImageButtonKeypress() {
  // Get a Field UI manage-display page.
  $this->drupalGet('ajax_forms_image_button_form');
  $assertSession = $this->assertSession();
  $session = $this->getSession();

  $button = $session->getPage()->findButton('Edit');
  // Press ENTER.
  $button->keyPress(13);

  $this->assertNotEmpty($assertSession->waitForElementVisible('css', '#ajax-1-more-div'), 'Page updated after image button pressed');

  // Refresh the page to test the next case.
  $this->drupalGet('ajax_forms_image_button_form');
  $assertSession = $this->assertSession();
  $session = $this->getSession();

  $button = $session->getPage()->findButton('Edit');
  // Press SPACE.
  $button->keyPress(32);

  $this->assertNotEmpty($assertSession->waitForElementVisible('css', '#ajax-1-more-div'), 'Page updated after image button pressed');
}
Krzysztof Domański’s picture

Status: Needs review » Reviewed & tested by the community

Without the previous one this looks good.

  • lauriii committed 9a3477e on 8.8.x
    Issue #3030363 by andrewmacpherson, Krzysztof Domański: Add test to...

  • lauriii committed d5142d9 on 8.7.x
    Issue #3030363 by andrewmacpherson, Krzysztof Domański: Add test to...
lauriii’s picture

Version: 8.8.x-dev » 8.7.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 9a3477e and pushed to 8.8.x. Since this changes only tests, also cherry-picked to 8.7.x. Thanks!

Status: Fixed » Closed (fixed)

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