Skip to content

Commit

Permalink
chore: resolve feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers committed Jun 9, 2021
1 parent 0295cdd commit c08955c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
21 changes: 10 additions & 11 deletions lib/core/utils/merge-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,17 @@ function mergeResults(frameResults, options) {
}

function nodeIndexSort(nodeIndexesA, nodeIndexesB) {
const indexA = nodeIndexesA[0];
const indexB = nodeIndexesB[0];
if (typeof indexA === 'undefined') {
return typeof indexB === 'undefined' ? 0 : -1;
}
if (typeof indexB === 'undefined') {
return 1;
}
if (indexA !== indexB) {
return indexA - indexB;
for (let i = 0; i <= nodeIndexesA.length; i++) {
const indexA = nodeIndexesA[i];
const indexB = nodeIndexesB[i];
if (typeof indexB === 'undefined') {
return 1;
}
if (indexA !== indexB) {
return indexA - indexB;
}
}
return nodeIndexSort(nodeIndexesA.slice(1), nodeIndexesB.slice(1));
return -1;
}

export default mergeResults;
2 changes: 1 addition & 1 deletion test/core/utils/dq-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('DqElement', function() {
assert.deepEqual(dqElm.nodeIndexes, [123, 456]);
});

it('is [] when the element is unknown.', function() {
it('is [] when the element is not in the virtual tree.', function() {
var div = document.createElement('div');
var dqElm = new DqElement(div);
assert.deepEqual(dqElm.nodeIndexes, []);
Expand Down
8 changes: 7 additions & 1 deletion test/core/utils/flattened-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,21 @@ describe('axe.utils.getFlattenedTree', function() {
});

it('creates virtual nodes in the correct order', function() {
fixture.innerHTML = '<p><b><i></i></b><p><u><s></s></u>';
fixture.innerHTML = '<p><b><i></i></b></p><u><s></s></u>';

var vNode = axe.utils.getFlattenedTree(fixture)[0];
assert.equal(vNode.nodeIndex, 0);
assert.equal(vNode.props.nodeName, 'div');
assert.equal(vNode.children[0].nodeIndex, 1);
assert.equal(vNode.children[0].props.nodeName, 'p');
assert.equal(vNode.children[0].children[0].nodeIndex, 2);
assert.equal(vNode.children[0].children[0].props.nodeName, 'b');
assert.equal(vNode.children[0].children[0].children[0].nodeIndex, 3);
assert.equal(vNode.children[0].children[0].children[0].props.nodeName, 'i');
assert.equal(vNode.children[1].nodeIndex, 4);
assert.equal(vNode.children[1].props.nodeName, 'u');
assert.equal(vNode.children[1].children[0].nodeIndex, 5);
assert.equal(vNode.children[1].children[0].props.nodeName, 's');
});

if (shadowSupport.v0) {
Expand Down

0 comments on commit c08955c

Please sign in to comment.