Add minimumContrastRatio to DOM renderer

Part of #322
This commit is contained in:
Daniel Imms
2019-11-11 19:03:12 -08:00
parent 339d4d6a73
commit e46ff9ec85
8 changed files with 209 additions and 30 deletions
+23 -1
View File
@@ -4,7 +4,7 @@
*/
import { assert } from 'chai';
import { blend, fromCss, toPaddedHex, toCss, toRgba } from 'browser/Color';
import { blend, fromCss, toPaddedHex, toCss, toRgba, rgbRelativeLuminance, contrastRatio } from 'browser/Color';
describe('Color', () => {
describe('blend', () => {
@@ -135,4 +135,26 @@ describe('Color', () => {
assert.equal(toRgba(0xff, 0xff, 0xff, 0xff), 0xffffffff);
});
});
describe('rgbRelativeLuminance', () => {
it('should calculate the relative luminance of the color', () => {
assert.equal(rgbRelativeLuminance(0x000000), 0);
// TODO: Fill in tests
assert.equal(rgbRelativeLuminance(0xFFFFFF), 1);
});
});
describe('contrastRatio', () => {
it('should calculate the relative luminance of the color', () => {
assert.equal(contrastRatio(0, 0), 1);
// TODO: Fill in tests
assert.equal(contrastRatio(0, 1), 21);
});
it('should work regardless of the parameter order', () => {
assert.equal(contrastRatio(0, 1), 21);
assert.equal(contrastRatio(1, 0), 21);
});
});
});