|
| 1 | +function appendSerialChild(parent, child) { |
| 2 | + if (child instanceof axe.SerialVirtualNode === false) { |
| 3 | + child = new axe.SerialVirtualNode(child); |
| 4 | + } |
| 5 | + child.parent = parent; |
| 6 | + parent.children ??= []; |
| 7 | + parent.children.push(child); |
| 8 | + return child; |
| 9 | +} |
| 10 | + |
| 11 | +describe('summary-name virtual-rule', () => { |
| 12 | + let vDetails; |
| 13 | + beforeEach(() => { |
| 14 | + vDetails = new axe.SerialVirtualNode({ |
| 15 | + nodeName: 'details', |
| 16 | + attributes: {} |
| 17 | + }); |
| 18 | + appendSerialChild(vDetails, { nodeName: '#text', nodeValue: 'text' }); |
| 19 | + }); |
| 20 | + |
| 21 | + it('fails without children', () => { |
| 22 | + const vSummary = new axe.SerialVirtualNode({ |
| 23 | + nodeName: 'summary', |
| 24 | + attributes: {} |
| 25 | + }); |
| 26 | + vSummary.children = []; |
| 27 | + appendSerialChild(vDetails, vSummary); |
| 28 | + const results = axe.runVirtualRule('summary-name', vSummary); |
| 29 | + console.log(results); |
| 30 | + assert.lengthOf(results.passes, 0); |
| 31 | + assert.lengthOf(results.violations, 1); |
| 32 | + assert.lengthOf(results.incomplete, 0); |
| 33 | + }); |
| 34 | + |
| 35 | + it('passes with text content', () => { |
| 36 | + const vSummary = new axe.SerialVirtualNode({ |
| 37 | + nodeName: 'summary', |
| 38 | + attributes: {} |
| 39 | + }); |
| 40 | + appendSerialChild(vSummary, { nodeName: '#text', nodeValue: 'text' }); |
| 41 | + appendSerialChild(vDetails, vSummary); |
| 42 | + |
| 43 | + const results = axe.runVirtualRule('summary-name', vSummary); |
| 44 | + assert.lengthOf(results.passes, 1); |
| 45 | + assert.lengthOf(results.violations, 0); |
| 46 | + assert.lengthOf(results.incomplete, 0); |
| 47 | + }); |
| 48 | + |
| 49 | + it('passes with aria-label', () => { |
| 50 | + const vSummary = new axe.SerialVirtualNode({ |
| 51 | + nodeName: 'summary', |
| 52 | + attributes: { 'aria-label': 'foobar' } |
| 53 | + }); |
| 54 | + appendSerialChild(vDetails, vSummary); |
| 55 | + const results = axe.runVirtualRule('summary-name', vSummary); |
| 56 | + assert.lengthOf(results.passes, 1); |
| 57 | + assert.lengthOf(results.violations, 0); |
| 58 | + assert.lengthOf(results.incomplete, 0); |
| 59 | + }); |
| 60 | + |
| 61 | + it('passes with title', () => { |
| 62 | + const vSummary = new axe.SerialVirtualNode({ |
| 63 | + nodeName: 'summary', |
| 64 | + attributes: { title: 'foobar' } |
| 65 | + }); |
| 66 | + appendSerialChild(vDetails, vSummary); |
| 67 | + const results = axe.runVirtualRule('summary-name', vSummary); |
| 68 | + assert.lengthOf(results.passes, 1); |
| 69 | + assert.lengthOf(results.violations, 0); |
| 70 | + assert.lengthOf(results.incomplete, 0); |
| 71 | + }); |
| 72 | + |
| 73 | + it('incompletes with aria-labelledby', () => { |
| 74 | + const vSummary = new axe.SerialVirtualNode({ |
| 75 | + nodeName: 'summary', |
| 76 | + attributes: { 'aria-labelledby': 'foobar' } |
| 77 | + }); |
| 78 | + appendSerialChild(vDetails, vSummary); |
| 79 | + const results = axe.runVirtualRule('summary-name', vSummary); |
| 80 | + assert.lengthOf(results.passes, 0); |
| 81 | + assert.lengthOf(results.violations, 0); |
| 82 | + assert.lengthOf(results.incomplete, 1); |
| 83 | + }); |
| 84 | + |
| 85 | + it('throws without a parent', () => { |
| 86 | + const vSummary = new axe.SerialVirtualNode({ |
| 87 | + nodeName: 'summary', |
| 88 | + attributes: { 'aria-labelledby': 'foobar' } |
| 89 | + }); |
| 90 | + vSummary.children = []; |
| 91 | + assert.throws(() => { |
| 92 | + axe.runVirtualRule('summary-name', vSummary); |
| 93 | + }); |
| 94 | + }); |
| 95 | +}); |
0 commit comments