Skip to content

Commit

Permalink
refactor(checks/navigation): improve internal-link-present-evaluate (
Browse files Browse the repository at this point in the history
…dequelabs#3128)

Make `internal-link-present-evaluate` work with virtualNode rather than actualNode.

Closes issue dequelabs#2466
  • Loading branch information
dan-tripp committed Aug 31, 2021
1 parent 7215dc4 commit 035c148
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 87 deletions.
20 changes: 10 additions & 10 deletions lib/checks/navigation/internal-link-present-evaluate.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { querySelectorAll } from '../../core/utils';

function internalLinkPresentEvaluate(node, options, virtualNode) {
const links = querySelectorAll(virtualNode, 'a[href]');
return links.some(vLink => {
return /^#[^/!]/.test(vLink.actualNode.getAttribute('href'));
});
}

export default internalLinkPresentEvaluate;
import { querySelectorAll } from '../../core/utils';

function internalLinkPresentEvaluate(node, options, virtualNode) {
const links = querySelectorAll(virtualNode, 'a[href]');
return links.some(vLink => {
return /^#[^/!]/.test(vLink.attr('href'));
});
}

export default internalLinkPresentEvaluate;
155 changes: 78 additions & 77 deletions test/checks/navigation/internal-link-present.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,78 @@
describe('internal-link-present', function() {
'use strict';

var fixture = document.getElementById('fixture');
var shadowSupported = axe.testUtils.shadowSupport.v1;
var checkContext = axe.testUtils.MockCheckContext();
var checkSetup = axe.testUtils.checkSetup;
var shadowCheckSetup = axe.testUtils.shadowCheckSetup;

afterEach(function() {
fixture.innerHTML = '';
axe._tree = undefined;
checkContext.reset();
});

it('should return true when an internal link is found', function() {
var params = checkSetup('<div id="target"><a href="#haha">hi</a></div>');
assert.isTrue(
axe.testUtils
.getCheckEvaluate('internal-link-present')
.apply(checkContext, params)
);
});

it('should return false when a hashbang URL was used', function() {
var params = checkSetup('<div id="target"><a href="#!foo">hi</a></div>');
assert.isFalse(
axe.testUtils
.getCheckEvaluate('internal-link-present')
.apply(checkContext, params)
);
});

it('should return false when a hash route URL was used', function() {
var params = checkSetup('<div id="target"><a href="#/home">hi</a></div>');
assert.isFalse(
axe.testUtils
.getCheckEvaluate('internal-link-present')
.apply(checkContext, params)
);
});

it('should return false when a hashbang + slash route URL was used', function() {
var params = checkSetup('<div id="target"><a href="#!/home">hi</a></div>');
assert.isFalse(
axe.testUtils
.getCheckEvaluate('internal-link-present')
.apply(checkContext, params)
);
});

it('should otherwise return false', function() {
var params = checkSetup(
'<div id="target"><a href="http://www.deque.com/#haha">hi</a></div>'
);
assert.isFalse(
axe.testUtils
.getCheckEvaluate('internal-link-present')
.apply(checkContext, params)
);
});

(shadowSupported ? it : xit)(
'should return true when internal link is found in shadow dom',
function() {
var params = shadowCheckSetup(
'<div id="target"></div>',
'<a href="#haha">hi</a>'
);
assert.isTrue(
axe.testUtils
.getCheckEvaluate('internal-link-present')
.apply(checkContext, params)
);
}
);
});
describe('internal-link-present', function() {
'use strict';

var fixture = document.getElementById('fixture');
var shadowSupported = axe.testUtils.shadowSupport.v1;
var checkContext = axe.testUtils.MockCheckContext();
var shadowCheckSetup = axe.testUtils.shadowCheckSetup;
var queryFixture = axe.testUtils.queryFixture;

afterEach(function() {
fixture.innerHTML = '';
axe._tree = undefined;
checkContext.reset();
});

it('should return true when an internal link is found', function() {
var vNode = queryFixture('<div id="target"><a href="#haha">hi</a></div>');
assert.isTrue(
axe.testUtils
.getCheckEvaluate('internal-link-present')
.call(checkContext, null, {}, vNode)
);
});

it('should return false when a hashbang URL was used', function() {
var vNode = queryFixture('<div id="target"><a href="#!foo">hi</a></div>');
assert.isFalse(
axe.testUtils
.getCheckEvaluate('internal-link-present')
.call(checkContext, null, {}, vNode)
);
});

it('should return false when a hash route URL was used', function() {
var vNode = queryFixture('<div id="target"><a href="#/home">hi</a></div>');
assert.isFalse(
axe.testUtils
.getCheckEvaluate('internal-link-present')
.call(checkContext, null, {}, vNode)
);
});

it('should return false when a hashbang + slash route URL was used', function() {
var vNode = queryFixture('<div id="target"><a href="#!/home">hi</a></div>');
assert.isFalse(
axe.testUtils
.getCheckEvaluate('internal-link-present')
.call(checkContext, null, {}, vNode)
);
});

it('should otherwise return false', function() {
var vNode = queryFixture(
'<div id="target"><a href="http://www.deque.com/#haha">hi</a></div>'
);
assert.isFalse(
axe.testUtils
.getCheckEvaluate('internal-link-present')
.call(checkContext, null, {}, vNode)
);
});

(shadowSupported ? it : xit)(
'should return true when internal link is found in shadow dom',
function() {
var params = shadowCheckSetup(
'<div id="target"></div>',
'<a href="#haha">hi</a>'
);
var vNode = params[2];
assert.isTrue(
axe.testUtils
.getCheckEvaluate('internal-link-present')
.call(checkContext, null, {}, vNode)
);
}
);
});

0 comments on commit 035c148

Please sign in to comment.