Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { module, test, skip } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, triggerKeyEvent } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import sinon from 'sinon';

module('Integration | Component | hds/interactive/index', function (hooks) {
setupRenderingTest(hooks);
Expand Down Expand Up @@ -131,10 +130,12 @@ module('Integration | Component | hds/interactive/index', function (hooks) {
assert.dom('button#test-interactive').hasAttribute('type', 'submit');
});
test('it should dispatch a click event when pressing space key on a link', async function (assert) {
await render(hbs`<Hds::Interactive @href="#" id="test-interactive"/>`);
var interactiveComponent = document.querySelector('#test-interactive');
var keyUpSpy = sinon.spy(interactiveComponent, 'click');
await triggerKeyEvent(interactiveComponent, 'keyup', ' ');
assert.true(keyUpSpy.calledOnce);
let clicked = false;
this.set('clickHandler', () => (clicked = true));
await render(
hbs`<div {{on "click" this.clickHandler}}><Hds::Interactive @href="javascript:;" id="test-interactive"/></div>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we rely on the click event bubbling up, then capture it at the parent level using a boolean. Given we only use sinon for this test I'm happy with the change. We may get back to square one if we won't manage to use this pattern for future scenarios, but that's a problem for tomorrow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may get back to square one if we won't manage to use this pattern for future scenarios

That was my fear with "fixing" it this way as well.

);
await triggerKeyEvent('#test-interactive', 'keyup', ' ');
assert.ok(clicked);
});
});