|
1 | | -import { getContrast, isLight } from './colour'; |
| 1 | +import { addAlpha, getContrast, isLight } from './colour'; |
2 | 2 |
|
3 | 3 | const round = (value: number): number => Math.round(value * 100) / 100; |
4 | 4 |
|
@@ -55,3 +55,18 @@ describe('getContrast', () => { |
55 | 55 | expect(round(getContrast('#559861', '#1a1a1a'))).toEqual(5.01); |
56 | 56 | }); |
57 | 57 | }); |
| 58 | + |
| 59 | +describe('addAlpha', () => { |
| 60 | + it('should return new colour adjusted for opacity against background colour', () => { |
| 61 | + expect(addAlpha('#da020e', '#ffffff', 1)).toBe('#da020e'); |
| 62 | + expect(addAlpha('#da020e', '#1a1a1a', 1)).toBe('#da020e'); |
| 63 | + expect(addAlpha('#da020e', '#ffffff', 0.1)).toBe('#fbe6e7'); |
| 64 | + expect(addAlpha('#da020e', '#1a1a1a', 0.1)).toBe('#2d1819'); |
| 65 | + expect(addAlpha('#023474', '#ffffff', 0.1)).toBe('#e6ebf1'); |
| 66 | + expect(addAlpha('#023474', '#1a1a1a', 0.1)).toBe('#181d23'); |
| 67 | + }); |
| 68 | + it('should return fallback colour if invalid colour passed in', () => { |
| 69 | + expect(addAlpha('#xyz', '#ffffff', 1)).toBe('#7f7f7f'); |
| 70 | + expect(addAlpha('#ffffff', '#xyz', 1)).toBe('#7f7f7f'); |
| 71 | + }); |
| 72 | +}); |
0 commit comments