1
+ /* global sinon */
2
+
1
3
describe ( 'color.getForegroundColor' , function ( ) {
2
4
'use strict' ;
3
5
@@ -42,6 +44,39 @@ describe('color.getForegroundColor', function() {
42
44
assert . equal ( actual . alpha , expected . alpha ) ;
43
45
} ) ;
44
46
47
+ it ( 'should take into account parent opacity tree' , function ( ) {
48
+ fixture . innerHTML =
49
+ '<div style="background-color: #fafafa">' +
50
+ '<div style="height: 40px; width: 30px; opacity: 0.6">' +
51
+ '<div id="target" style="height: 20px; width: 15px; color: rgba(0, 0, 0, 0.87);">' +
52
+ 'This is my text' +
53
+ '</div></div></div>' ;
54
+ var target = fixture . querySelector ( '#target' ) ;
55
+ var actual = axe . commons . color . getForegroundColor ( target ) ;
56
+ var expected = new axe . commons . color . Color ( 119.5 , 119.5 , 119.5 , 1 ) ;
57
+ assert . closeTo ( actual . red , expected . red , 0.8 ) ;
58
+ assert . closeTo ( actual . green , expected . green , 0.8 ) ;
59
+ assert . closeTo ( actual . blue , expected . blue , 0.8 ) ;
60
+ assert . closeTo ( actual . alpha , expected . alpha , 0.1 ) ;
61
+ } ) ;
62
+
63
+ it ( 'should take into account entire parent opacity tree' , function ( ) {
64
+ fixture . innerHTML =
65
+ '<div style="background-color: #fafafa">' +
66
+ '<div style="height: 40px; width: 30px; opacity: 0.75">' +
67
+ '<div style="height: 40px; width: 30px; opacity: 0.8">' +
68
+ '<div id="target" style="height: 20px; width: 15px; color: rgba(0, 0, 0, 0.87);">' +
69
+ 'This is my text' +
70
+ '</div></div></div></div>' ;
71
+ var target = fixture . querySelector ( '#target' ) ;
72
+ var actual = axe . commons . color . getForegroundColor ( target ) ;
73
+ var expected = new axe . commons . color . Color ( 119.5 , 119.5 , 119.5 , 1 ) ;
74
+ assert . closeTo ( actual . red , expected . red , 0.8 ) ;
75
+ assert . closeTo ( actual . green , expected . green , 0.8 ) ;
76
+ assert . closeTo ( actual . blue , expected . blue , 0.8 ) ;
77
+ assert . closeTo ( actual . alpha , expected . alpha , 0.1 ) ;
78
+ } ) ;
79
+
45
80
it ( 'should return null if containing parent has a background image and is non-opaque' , function ( ) {
46
81
fixture . innerHTML =
47
82
'<div style="height: 40px; width: 30px;' +
@@ -68,6 +103,15 @@ describe('color.getForegroundColor', function() {
68
103
assert . equal ( actual . alpha , expected . alpha ) ;
69
104
} ) ;
70
105
106
+ it ( 'should not recalculate bgColor if passed in' , function ( ) {
107
+ var spy = sinon . spy ( axe . commons . color , 'getBackgroundColor' ) ;
108
+ var bgColor = new axe . commons . color . Color ( 255 , 255 , 255 , 1 ) ;
109
+ var node = document . createElement ( 'div' ) ;
110
+ axe . commons . color . getForegroundColor ( node , false , bgColor ) ;
111
+ assert . isFalse ( spy . called ) ;
112
+ spy . restore ( ) ;
113
+ } ) ;
114
+
71
115
( shadowSupported ? it : xit ) (
72
116
'should return the fgcolor from inside of Shadow DOM' ,
73
117
function ( ) {
0 commit comments