-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(table-duplicate-name): use virtual node (#3604)
- use virtual node references: #3473
- Loading branch information
Showing
6 changed files
with
172 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import { accessibleText } from '../../commons/text'; | ||
|
||
function sameCaptionSummaryEvaluate(node) { | ||
// passing node.caption to accessibleText instead of using | ||
// the logic in accessibleTextVirtual on virtualNode | ||
return ( | ||
!!(node.summary && node.caption) && | ||
node.summary.toLowerCase() === accessibleText(node.caption).toLowerCase() | ||
); | ||
} | ||
import { sanitize, subtreeText } from '../../commons/text'; | ||
|
||
export default sameCaptionSummaryEvaluate; | ||
|
||
function sameCaptionSummaryEvaluate(node, options, virtualNode) { | ||
if (virtualNode.children === undefined) { | ||
return undefined; | ||
} | ||
|
||
var summary = virtualNode.attr('summary'); | ||
var captionNode = virtualNode.children.find(isCaptionNode); | ||
var caption = captionNode ? sanitize(subtreeText(captionNode)) : false; | ||
|
||
if (!caption || !summary) { | ||
return false; | ||
} | ||
|
||
return sanitize(summary).toLowerCase() === sanitize(caption).toLowerCase(); | ||
} | ||
|
||
function isCaptionNode(virtualNode) { | ||
return virtualNode.props.nodeName === 'caption'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
describe('table-duplicate-name virtual-rule', function () { | ||
it('should incomplete on table element with children undefined', function () { | ||
var tableNode = new axe.SerialVirtualNode({ | ||
nodeName: 'table' | ||
}); | ||
tableNode.children = undefined; | ||
|
||
var results = axe.runVirtualRule('table-duplicate-name', tableNode); | ||
|
||
assert.lengthOf(results.passes, 0); | ||
assert.lengthOf(results.violations, 0); | ||
assert.lengthOf(results.incomplete, 1); | ||
}); | ||
|
||
it('should pass on table element', function () { | ||
var tableNode = new axe.SerialVirtualNode({ | ||
nodeName: 'table' | ||
}); | ||
|
||
tableNode.children = []; | ||
|
||
var results = axe.runVirtualRule('table-duplicate-name', tableNode); | ||
|
||
assert.lengthOf(results.passes, 1); | ||
assert.lengthOf(results.violations, 0); | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
|
||
it('should pass when table has empty summary', function () { | ||
var tableNode = new axe.SerialVirtualNode({ | ||
nodeName: 'table', | ||
attributes: { | ||
summary: '' | ||
} | ||
}); | ||
tableNode.children = []; | ||
|
||
var results = axe.runVirtualRule('table-duplicate-name', tableNode); | ||
|
||
assert.lengthOf(results.passes, 1); | ||
assert.lengthOf(results.violations, 0); | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
|
||
it('should pass when table has empty caption and summary', function () { | ||
var tableNode = new axe.SerialVirtualNode({ | ||
nodeName: 'table', | ||
attributes: { | ||
summary: '' | ||
} | ||
}); | ||
|
||
var captionNode = new axe.SerialVirtualNode({ | ||
nodeName: 'caption' | ||
}); | ||
captionNode.parent = tableNode; | ||
|
||
var textNode = new axe.SerialVirtualNode({ | ||
nodeName: '#text', | ||
nodeType: 3, | ||
nodeValue: '' | ||
}); | ||
textNode.parent = captionNode; | ||
|
||
captionNode.children = [textNode]; | ||
tableNode.children = [captionNode]; | ||
|
||
var results = axe.runVirtualRule('table-duplicate-name', tableNode); | ||
|
||
assert.lengthOf(results.passes, 1); | ||
assert.lengthOf(results.violations, 0); | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
|
||
it('should fail when table summary and <caption> have the same text', function () { | ||
var DUPLICATED_TEXT = 'foobar'; | ||
|
||
var tableNode = new axe.SerialVirtualNode({ | ||
nodeName: 'table', | ||
attributes: { | ||
summary: DUPLICATED_TEXT | ||
} | ||
}); | ||
|
||
var captionNode = new axe.SerialVirtualNode({ | ||
nodeName: 'caption' | ||
}); | ||
captionNode.parent = tableNode; | ||
|
||
var textNode = new axe.SerialVirtualNode({ | ||
nodeName: '#text', | ||
nodeType: 3, | ||
nodeValue: DUPLICATED_TEXT | ||
}); | ||
textNode.parent = captionNode; | ||
|
||
captionNode.children = [textNode]; | ||
tableNode.children = [captionNode]; | ||
|
||
var results = axe.runVirtualRule('table-duplicate-name', tableNode); | ||
|
||
assert.lengthOf(results.passes, 0); | ||
assert.lengthOf(results.violations, 1); | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
|
||
it('should fail when table summary and <caption> have the same text, excluding whitespace', function () { | ||
var DUPLICATED_TEXT = 'foobar'; | ||
|
||
var tableNode = new axe.SerialVirtualNode({ | ||
nodeName: 'table', | ||
attributes: { | ||
summary: ' ' + DUPLICATED_TEXT | ||
} | ||
}); | ||
|
||
var captionNode = new axe.SerialVirtualNode({ | ||
nodeName: 'caption' | ||
}); | ||
captionNode.parent = tableNode; | ||
|
||
var textNode = new axe.SerialVirtualNode({ | ||
nodeName: '#text', | ||
nodeType: 3, | ||
nodeValue: ' \t ' + DUPLICATED_TEXT | ||
}); | ||
textNode.parent = captionNode; | ||
|
||
captionNode.children = [textNode]; | ||
tableNode.children = [captionNode]; | ||
|
||
var results = axe.runVirtualRule('table-duplicate-name', tableNode); | ||
|
||
assert.lengthOf(results.passes, 0); | ||
assert.lengthOf(results.violations, 1); | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
}); |