|
1 | 1 | module("LowContrast"); |
2 | 2 |
|
| 3 | +test("No text = no relevant elements", function() { |
| 4 | + var fixture = document.getElementById('qunit-fixture'); |
| 5 | + var div = document.createElement('div'); |
| 6 | + div.style.backgroundColor = 'white'; |
| 7 | + div.style.color = 'white'; |
| 8 | + fixture.appendChild(div); |
| 9 | + deepEqual( |
| 10 | + axs.AuditRules.getRule('lowContrastElements').run({ scope: fixture }), |
| 11 | + { result: axs.constants.AuditResult.NA } |
| 12 | + ); |
| 13 | +}); |
| 14 | + |
| 15 | +test("Black on white = no problem", function() { |
| 16 | + var fixture = document.getElementById('qunit-fixture'); |
| 17 | + var div = document.createElement('div'); |
| 18 | + div.style.backgroundColor = 'white'; |
| 19 | + div.style.color = 'black'; |
| 20 | + div.textContent = 'Some text'; |
| 21 | + fixture.appendChild(div); |
| 22 | + deepEqual( |
| 23 | + axs.AuditRules.getRule('lowContrastElements').run({ scope: fixture }), |
| 24 | + { elements: [], result: axs.constants.AuditResult.PASS } |
| 25 | + ); |
| 26 | +}); |
| 27 | + |
| 28 | +test("Low contrast = fail", function() { |
| 29 | + var fixture = document.getElementById('qunit-fixture'); |
| 30 | + var div = document.createElement('div'); |
| 31 | + div.style.backgroundColor = 'white'; |
| 32 | + div.style.color = '#aaa'; // Contrast ratio = 2.32 |
| 33 | + div.textContent = 'Some text'; |
| 34 | + fixture.appendChild(div); |
| 35 | + deepEqual( |
| 36 | + axs.AuditRules.getRule('lowContrastElements').run({ scope: fixture }), |
| 37 | + { elements: [div], result: axs.constants.AuditResult.FAIL } |
| 38 | + ); |
| 39 | +}); |
| 40 | + |
3 | 41 | test("Opacity is handled", function() { |
4 | 42 | // Setup fixture |
5 | | - var fixtures = document.getElementById('qunit-fixture'); |
| 43 | + var fixture = document.getElementById('qunit-fixture'); |
6 | 44 | var elementWithOpacity = document.createElement('div'); |
7 | 45 | elementWithOpacity.style.opacity = '0.4'; |
8 | 46 | elementWithOpacity.textContent = 'Some text'; |
9 | | - fixtures.appendChild(elementWithOpacity); |
| 47 | + fixture.appendChild(elementWithOpacity); |
10 | 48 | deepEqual( |
11 | | - axs.AuditRules.getRule('lowContrastElements').run([], fixtures), |
| 49 | + axs.AuditRules.getRule('lowContrastElements').run({ scope: fixture }), |
12 | 50 | { elements: [elementWithOpacity], result: axs.constants.AuditResult.FAIL } |
13 | 51 | ); |
14 | 52 | }); |
| 53 | + |
| 54 | +test("Uses tolerance value", function() { |
| 55 | + var fixture = document.getElementById('qunit-fixture'); |
| 56 | + var div = document.createElement('div'); |
| 57 | + div.style.backgroundColor = 'white'; |
| 58 | + div.style.color = '#777'; // Contrast ratio = 4.48 |
| 59 | + div.textContent = 'Some text'; |
| 60 | + fixture.appendChild(div); |
| 61 | + deepEqual( |
| 62 | + axs.AuditRules.getRule('lowContrastElements').run({ scope: fixture }), |
| 63 | + { elements: [], result: axs.constants.AuditResult.PASS } |
| 64 | + ); |
| 65 | +}); |
0 commit comments