Skip to content

Commit

Permalink
More cleanup and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers committed Sep 2, 2022
1 parent a25d7a0 commit f6b97df
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 34 deletions.
4 changes: 0 additions & 4 deletions lib/commons/math/split-rects.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ function splitRect(inputRect, clipRect) {

const rects = [];
if (between(clipRect.top, top, bottom) && xAligned) {
// console.log('top')
rects.push({ top, left, bottom: clipRect.top, right });
}
if (between(clipRect.right, left, right) && yAligned) {
// console.log('right', clipRect.right, left, right, top, clipRect.bottom, bottom, inputRect.top)
rects.push({ top, left: clipRect.right, bottom, right });
}
if (between(clipRect.bottom, top, bottom) && xAligned) {
// console.log('bottom')
rects.push({ top: clipRect.bottom, right, bottom, left });
}
if (between(clipRect.left, left, right) && yAligned) {
// console.log('left', clipRect.left, left, right)
rects.push({ top, left, bottom, right: clipRect.left });
}
if (rects.length === 0) {
Expand Down
2 changes: 0 additions & 2 deletions lib/rules/widget-not-inline-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ const matchesFns = [

function isWidgetType(vNode) {
const role = getRole(vNode);
// TODO: These needs tests
if ('option' === role) {
return false;
} else if (['combobox', 'listbox'].includes(role)) {
return true;
}

const roleType = getRoleType(role);
return roleType === 'widget';
}
Expand Down
24 changes: 12 additions & 12 deletions test/checks/mobile/target-offset.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ describe('target-offset tests', function () {

it('returns true when there are no other nearby targets', function () {
var checkArgs = checkSetup(
'<button id="target" style="' +
'<a href="#" id="target" style="' +
'display: inline-block; width:16px; height:16px;' +
'">x</button>'
'">x</a>'
);

assert.isTrue(check.evaluate.apply(checkContext, checkArgs));
Expand All @@ -23,12 +23,12 @@ describe('target-offset tests', function () {

it('returns true when the offset is 24px', function () {
var checkArgs = checkSetup(
'<button id="target" style="' +
'<a href="#" id="target" style="' +
'display: inline-block; width:16px; height:16px; margin-right: 8px' +
'">x</button>' +
'<button style="' +
'">x</a>' +
'<a href="#" style="' +
'display: inline-block; width:16px; height:16px;' +
'">x</button>'
'">x</a>'
);

assert.isTrue(check.evaluate.apply(checkContext, checkArgs));
Expand All @@ -38,12 +38,12 @@ describe('target-offset tests', function () {

it('returns false when the offset is 23px', function () {
var checkArgs = checkSetup(
'<button id="target" style="' +
'<a href="#" id="target" style="' +
'display: inline-block; width:16px; height:16px; margin-right: 7px' +
'">x</button>' +
'<button style="' +
'">x</a>' +
'<a href="#" style="' +
'display: inline-block; width:16px; height:16px;' +
'">x</button>'
'">x</a>'
);

assert.isFalse(check.evaluate.apply(checkContext, checkArgs));
Expand All @@ -53,9 +53,9 @@ describe('target-offset tests', function () {

it('ignores non-widget elements as neighbors', function () {
var checkArgs = checkSetup(
'<button id="target" style="' +
'<a href="#" id="target" style="' +
'display: inline-block; width:16px; height:16px; margin-right: 7px' +
'">x</button>' +
'">x</a>' +
'<div style="' +
'display: inline-block; width:16px; height:16px;' +
'">x</div>'
Expand Down
8 changes: 0 additions & 8 deletions test/commons/math/has-visual-overlap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,22 @@ describe('hasVisualOverlap', function () {
var fixtureSetup = axe.testUtils.fixtureSetup;
var hasVisualOverlap = axe.commons.math.hasVisualOverlap;

// hasVisualOverlap requires the grid to be set up
// For performance reasons axe-core does not do this in setup,
// so we'll need to call it ourselves.
var createGrid = axe.commons.dom.createGrid;

it('returns false if there is no overlap', function () {
var rootNode = fixtureSetup('<a>foo</a><b>bar</b>');
createGrid();
var vNodeA = rootNode.children[0];
var vNodeB = rootNode.children[1];
assert.isFalse(hasVisualOverlap(vNodeA, vNodeB));
});

it('returns true if B overlaps A', function () {
var rootNode = fixtureSetup('<a><b>bar</b></a>');
createGrid();
var vNodeA = rootNode.children[0];
var vNodeB = vNodeA.children[0];
assert.isTrue(hasVisualOverlap(vNodeA, vNodeB));
});

it('returns true A overlaps B', function () {
var rootNode = fixtureSetup('<b><a>bar</a></b>');
createGrid();
var vNodeB = rootNode.children[0];
var vNodeA = vNodeB.children[0];
assert.isFalse(hasVisualOverlap(vNodeA, vNodeB));
Expand Down
48 changes: 40 additions & 8 deletions test/rule-matches/widget-not-inline-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ describe('widget-not-inline-matches', function () {
assert.isTrue(rule.matches(node, vNode));
});

it('returns true for non-native widgets', function () {
var vNode = queryFixture(
'<div role="button" tabindex="0" id="target"></div>'
);
var node = vNode.actualNode;
assert.isTrue(rule.matches(node, vNode));
});

it('returns false for non-widget elements', function () {
var vNode = queryFixture('<div role="banner" id="target"></div>');
var node = vNode.actualNode;
Expand All @@ -39,6 +31,46 @@ describe('widget-not-inline-matches', function () {
assert.isFalse(rule.matches(node, vNode));
});

describe('non-native components', function () {
it('returns true for a tabbable button', function () {
var vNode = queryFixture(
'<div role="button" tabindex="0" id="target"></div>'
);
var node = vNode.actualNode;
assert.isTrue(rule.matches(node, vNode));
});

it('returns false for a non-tabbable button (widgets)', function () {
var vNode = queryFixture('<div role="button" id="target"></div>');
var node = vNode.actualNode;
assert.isFalse(rule.matches(node, vNode));
});

it('returns false for a non-tabbable button (widgets)', function () {
var vNode = queryFixture(
'<div role="option" tabindex="0" id="target"></div>'
);
var node = vNode.actualNode;
assert.isFalse(rule.matches(node, vNode));
});

it('returns true for a listbox (component)', function () {
var vNode = queryFixture(
'<div role="listbox" tabindex="0" id="target"></div>'
);
var node = vNode.actualNode;
assert.isTrue(rule.matches(node, vNode));
});

it('returns true for a combobox (component)', function () {
var vNode = queryFixture(
'<div role="combobox" tabindex="0" id="target"></div>'
);
var node = vNode.actualNode;
assert.isTrue(rule.matches(node, vNode));
});
});

describe('inline components', function () {
it('returns false for elements inline with text', function () {
var vNode = queryFixture(
Expand Down

0 comments on commit f6b97df

Please sign in to comment.