11module ( "LowContrast" ) ;
22
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 ( [ ] , 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 ( [ ] , 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 ( [ ] , fixture ) ,
37+ { elements : [ div ] , result : axs . constants . AuditResult . FAIL }
38+ ) ;
39+ } ) ;
40+
341test ( "Opacity is handled" , function ( ) {
442 // Setup fixture
543 var fixtures = document . getElementById ( 'qunit-fixture' ) ;
@@ -12,3 +50,16 @@ test("Opacity is handled", function() {
1250 { elements : [ elementWithOpacity ] , result : axs . constants . AuditResult . FAIL }
1351 ) ;
1452} ) ;
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 ( [ ] , fixture ) ,
63+ { elements : [ ] , result : axs . constants . AuditResult . PASS }
64+ ) ;
65+ } ) ;
0 commit comments