You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/ui-v2/tests/unit/utils/dom/click-first-anchor-test.js

64 lines
1.7 KiB

import domClickFirstAnchor from 'consul-ui/utils/dom/click-first-anchor';
import { module, test } from 'qunit';
module('Unit | Utility | dom/click first anchor', function() {
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);
});
test('it dispatches the result of `mouseup`, `mousedown`, `click` if an anchor is found', function(assert) {
assert.expect(3);
const expected = ['mousedown', 'mouseup', 'click'];
const closest = function() {
return {
querySelector: function() {
return {
dispatchEvent: function(ev) {
const actual = ev.type;
assert.equal(actual, expected.shift());
},
};
},
};
};
const click = domClickFirstAnchor(closest);
click({
target: {
nodeName: 'DIV',
},
});
});
});