-
Notifications
You must be signed in to change notification settings - Fork 763
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for common color utility fns
- Loading branch information
Showing
4 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
describe('color.elementHasBackgroundImage', function() { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
var queryFixture = axe.testUtils.queryFixture; | ||
var elementHasBackgroundImage = axe.commons.color.elementHasBackgroundImage; | ||
|
||
afterEach(function() { | ||
fixture.innerHTML = ''; | ||
axe._tree = undefined; | ||
}); | ||
|
||
it('returns true when `HTMLElement` is of graphical type', function() { | ||
['img', 'canvas', 'object', 'iframe', 'video', 'svg'].forEach(function( | ||
nodeName | ||
) { | ||
var vNode = queryFixture( | ||
'<' + nodeName + ' id="target"></' + nodeName + '>' | ||
); | ||
var actual = elementHasBackgroundImage(vNode.actualNode); | ||
assert.isTrue(actual); | ||
}); | ||
}); | ||
|
||
it('returns false when `HTMLElement` has no background-image style set', function() { | ||
var vNode = queryFixture( | ||
'<div id="target" style="height: 40px; width: 30px;">No background style</div>' | ||
); | ||
var actual = elementHasBackgroundImage(vNode.actualNode); | ||
assert.isFalse(actual); | ||
}); | ||
|
||
it('returns false when `HTMLElement` has background-image style set to none', function() { | ||
var vNode = queryFixture( | ||
'<div id="target" style="height: 40px; width: 30px; background-image: none "> Some text... </div>' | ||
); | ||
var actual = elementHasBackgroundImage(vNode.actualNode); | ||
assert.isFalse(actual); | ||
}); | ||
|
||
it('returns true when `HTMLElement` has background-image (url)', function() { | ||
var vNode = queryFixture( | ||
'<div id="target" style="height: 40px; width: 30px; background-image: url(london.png)"> Some text... </div>' | ||
); | ||
var actual = elementHasBackgroundImage(vNode.actualNode); | ||
assert.isTrue(actual); | ||
|
||
var bgColorIncompleteData = axe.commons.color.incompleteData.get('bgColor'); | ||
assert.equal(bgColorIncompleteData, 'bgImage'); | ||
}); | ||
|
||
it('returns true when `HTMLElement` has background-image (gradient)', function() { | ||
var vNode = queryFixture( | ||
'<div id="target" style="height: 40px; width: 30px; background-image: linear-gradient(red, orange);"> Some text... </div>' | ||
); | ||
var actual = elementHasBackgroundImage(vNode.actualNode); | ||
assert.isTrue(actual); | ||
|
||
var bgColorIncompleteData = axe.commons.color.incompleteData.get('bgColor'); | ||
assert.equal(bgColorIncompleteData, 'bgGradient'); | ||
}); | ||
}); |
69 changes: 69 additions & 0 deletions
69
test/commons/color/get-non-alpha-blended-background-color.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
describe('color.getNonAlphaBlendedBackgroundColor', function() { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
var queryFixture = axe.testUtils.queryFixture; | ||
var getNonAlphaBlendedBackgroundColor = | ||
axe.commons.color.getNonAlphaBlendedBackgroundColor; | ||
var isPhantom = window.PHANTOMJS ? true : false; | ||
|
||
afterEach(function() { | ||
fixture.innerHTML = ''; | ||
axe._tree = undefined; | ||
}); | ||
|
||
it('returns `new axe.commons.color.Color` instance when no background is set', function() { | ||
var vNode = queryFixture( | ||
'<div id="target" style="height: 40px; width: 30px;">' + '</div>' | ||
); | ||
var actual = getNonAlphaBlendedBackgroundColor(vNode.actualNode); | ||
assert.equal(actual.red, 0); | ||
assert.equal(actual.green, 0); | ||
assert.equal(actual.blue, 0); | ||
if (!isPhantom) { | ||
assert.equal(actual.alpha, 0); | ||
} | ||
}); | ||
|
||
it('returns the non-blended color with rgba values of specified background-color value', function() { | ||
var vNode = queryFixture( | ||
'<div id="target" style="height: 40px; width: 30px; background-color: pink;">' + | ||
'</div>' | ||
); | ||
var actual = getNonAlphaBlendedBackgroundColor(vNode.actualNode); | ||
assert.equal(actual.red, 255); | ||
assert.equal(actual.green, 192); | ||
assert.equal(actual.blue, 203); | ||
if (!isPhantom) { | ||
assert.equal(actual.alpha, 1); | ||
} | ||
}); | ||
|
||
it('returns the non-blended color with rgba values excluding alpha (for blending)', function() { | ||
var vNode = queryFixture( | ||
'<div id="target" style="height: 20px; width: 15px; background-color: rgba(0, 128, 0, 0.5);">' + | ||
'</div>' | ||
); | ||
var actual = getNonAlphaBlendedBackgroundColor(vNode.actualNode); | ||
assert.equal(actual.red, 0); | ||
assert.equal(actual.green, 128); | ||
assert.equal(actual.blue, 0); | ||
if (!isPhantom) { | ||
assert.equal(actual.alpha, 0.5); | ||
} | ||
}); | ||
|
||
it('returns the non-blended color with rgba values excluding opacity (for blending)', function() { | ||
var vNode = queryFixture( | ||
'<div id="target" style="height: 20px; width: 15px; opacity: 0.5; background-color: green;">' + | ||
'</div>' | ||
); | ||
var actual = getNonAlphaBlendedBackgroundColor(vNode.actualNode); | ||
assert.equal(actual.red, 0); | ||
assert.equal(actual.green, 128); | ||
assert.equal(actual.blue, 0); | ||
if (!isPhantom) { | ||
assert.equal(actual.alpha, 1); | ||
} | ||
}); | ||
}); |