aboutsummaryrefslogtreecommitdiff
path: root/src/ui/color/color.models.test.ts
blob: 256c100579c96470edbddce56da5a39e7088f232 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { describe, expect, test } from 'vitest';
import { darken, lighten, setOpacity } from './color.models';

describe('color models', () => {
  describe('lighten', () => {
    test('lightens a color', () => {
      expect(lighten('#000000', 10)).toBe('#0a0a0a');
      expect(lighten('#000000', 20)).toBe('#141414');
      expect(lighten('#ffffff', 30)).toBe('#ffffff');
    });

    test('lightens a color with alpha', () => {
      expect(lighten('#00000080', 10)).toBe('#0a0a0a80');
      expect(lighten('#00000080', 20)).toBe('#14141480');
      expect(lighten('#ffffff80', 30)).toBe('#ffffff80');
    });
  });

  describe('darken', () => {
    test('darkens a color', () => {
      expect(darken('#ffffff', 10)).toBe('#f5f5f5');
      expect(darken('#ffffff', 20)).toBe('#ebebeb');
      expect(darken('#000000', 30)).toBe('#000000');
    });

    test('darkens a color with alpha', () => {
      expect(darken('#ffffff80', 10)).toBe('#f5f5f580');
    });
  });

  describe('setOpacity', () => {
    test('sets the opacity of a color', () => {
      expect(setOpacity('#000000', 0.5)).toBe('#00000080');
    });

    test('sets the opacity of a color with alpha', () => {
      expect(setOpacity('#00000000', 0.5)).toBe('#00000080');
    });
  });
});