2018-10-19 15:17:02 +00:00
|
|
|
import domClickFirstAnchor from 'consul-ui/utils/dom/click-first-anchor';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
|
|
|
module('Unit | Utility | dom/click first anchor');
|
|
|
|
|
|
|
|
test('it does nothing if the clicked element is generally a clickable thing', function(assert) {
|
|
|
|
const closest = function() {
|
|
|
|
return {
|
|
|
|
querySelector: function() {
|
|
|
|
assert.ok(false);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const click = domClickFirstAnchor(closest);
|
|
|
|
['INPUT', 'LABEL', 'A', 'Button'].forEach(function(item) {
|
|
|
|
const expected = null;
|
|
|
|
const actual = click({
|
|
|
|
target: {
|
|
|
|
nodeName: item,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
assert.equal(actual, expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
test("it does nothing if an anchor isn't found", function(assert) {
|
|
|
|
const closest = function() {
|
|
|
|
return {
|
|
|
|
querySelector: function() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const click = domClickFirstAnchor(closest);
|
|
|
|
const expected = null;
|
|
|
|
const actual = click({
|
|
|
|
target: {
|
|
|
|
nodeName: 'DIV',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
assert.equal(actual, expected);
|
|
|
|
});
|
2019-05-15 13:48:16 +00:00
|
|
|
test('it dispatches the result of `mouseup`, `mousedown`, `click` if an anchor is found', function(assert) {
|
|
|
|
assert.expect(3);
|
|
|
|
const expected = ['mousedown', 'mouseup', 'click'];
|
2018-10-19 15:17:02 +00:00
|
|
|
const closest = function() {
|
|
|
|
return {
|
|
|
|
querySelector: function() {
|
|
|
|
return {
|
|
|
|
dispatchEvent: function(ev) {
|
|
|
|
const actual = ev.type;
|
2019-05-15 13:48:16 +00:00
|
|
|
assert.equal(actual, expected.shift());
|
2018-10-19 15:17:02 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const click = domClickFirstAnchor(closest);
|
|
|
|
click({
|
|
|
|
target: {
|
|
|
|
nodeName: 'DIV',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|