|
| 1 | +const test = require('ava') |
| 2 | +const analyze = require('../../../src/analyzer/selectors/accessibility') |
| 3 | + |
| 4 | +test('it responds with the correct structure', t => { |
| 5 | + const fixture = [] |
| 6 | + const {total, totalUnique, unique} = analyze(fixture) |
| 7 | + |
| 8 | + t.is(total, 0) |
| 9 | + t.is(totalUnique, 0) |
| 10 | + t.deepEqual(unique, []) |
| 11 | +}) |
| 12 | + |
| 13 | +test('it counts the total of all accessibility selectors', t => { |
| 14 | + const fixture = ['[aria-hidden]', '[aria-hidden]', 'img[role="presentation"]'] |
| 15 | + const {total: actual} = analyze(fixture) |
| 16 | + const expected = 3 |
| 17 | + |
| 18 | + t.is(actual, expected) |
| 19 | +}) |
| 20 | + |
| 21 | +test('it counts the total of all unique accessibility selectors', t => { |
| 22 | + const fixture = ['[aria-hidden]', '[aria-hidden]', 'img[role="presentation"]'] |
| 23 | + const {totalUnique: actual} = analyze(fixture) |
| 24 | + const expected = 2 |
| 25 | + |
| 26 | + t.is(actual, expected) |
| 27 | +}) |
| 28 | + |
| 29 | +test('it finds all unique accessibility selectors, sorts them and adds a count', t => { |
| 30 | + const fixture = ['[aria-hidden]', '[aria-hidden]', 'img[role="presentation"]'] |
| 31 | + const {unique: actual} = analyze(fixture) |
| 32 | + const expected = [ |
| 33 | + { |
| 34 | + value: '[aria-hidden]', |
| 35 | + count: 2 |
| 36 | + }, |
| 37 | + { |
| 38 | + value: 'img[role="presentation"]', |
| 39 | + count: 1 |
| 40 | + } |
| 41 | + ] |
| 42 | + |
| 43 | + t.deepEqual(actual, expected) |
| 44 | +}) |
| 45 | + |
| 46 | +test('it does not report selectors that are not accessibility selectors', t => { |
| 47 | + const fixture = ['img[data-lazy]', '[hidden]'] |
| 48 | + const {total, totalUnique, unique} = analyze(fixture) |
| 49 | + |
| 50 | + t.is(total, 0) |
| 51 | + t.is(totalUnique, 0) |
| 52 | + t.deepEqual(unique, []) |
| 53 | +}) |
0 commit comments