aboutsummaryrefslogtreecommitdiff
path: root/src/lib/animations/blink.test.ts
blob: 32dc872c980c443a1656180919b90c8b8b9c426a (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
 * @jest-environment jsdom
 */

import { blink } from './blink';
import { sineOut } from 'svelte/easing';

const internals = {
  response: null
};

describe('blink', () => {

  test('it has a default delay of 0ms', () => {

    const response = blink(document.createElement('div'), {});

    expect(response.delay).toBe(0);
  });

  test('it allows delay to be overridden', () => {

    const response = blink(document.createElement('div'), {
      delay: 300
    });

    expect(response.delay).toBe(300);
  });

  test('it has a default duration of 400ms', () => {

    const response = blink(document.createElement('div'), {});

    expect(response.duration).toBe(400);
  });

  test('it allows delay to be overridden', () => {

    const response = blink(document.createElement('div'), {
      duration: 999
    });

    expect(response.duration).toBe(999);
  });

  test('it uses sineOut as the default easing function', () => {

    const response = blink(document.createElement('div'), {});

    expect(response.easing).toBe(sineOut);
  });

  test('it allows easing function to be overridden', () => {

    const response = blink(document.createElement('div'), {
      easing: () => 666
    });

    expect(response.easing(0)).toBe(666);
  });

  describe('css animation function', () => {

    beforeEach(() => {

      const div = document.createElement('div');
      div.style.width = '100px';
      div.style.height = '200px';
      internals.response = blink(div, {});
    });

    test('It starts with with zeroed width and height', () => {

      const css = internals.response.css(0, 1);
      expect(css).toContain('width: 0px');
      expect(css).toContain('height: 0px');
    });

    test('It grows to full height and 0 width in first 20%', () => {

      const css = internals.response.css(0.2, 0.8);
      expect(css).toContain('width: 0px');
      expect(css).toContain('height: 200px');
    });

    test('It expands to full height by the end', () => {

      const css = internals.response.css(1, 0);
      expect(css).toContain('width: 100px');
      expect(css).toContain('height: 200px');
    });

    test('It keeps element vertically centered by adjusting the margin', () => {

      const css = internals.response.css(0.1, 0.9);
      expect(css).toContain('margin: 50px 50px');
      expect(css).toContain('height: 100px');
    });

    test('It keeps element horizontally centered by adjusting the margin', () => {

      const css = internals.response.css(0.6, 0.4);
      expect(css).toContain('margin: 0px 25px');
      expect(css).toContain('width: 50px');
    });
  });
});