Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gl_countdown_spec.js « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 38d54eff87247253d38770c7dd711234710e1928 (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
import Vue, { nextTick } from 'vue';
import { mount } from '@vue/test-utils';
import GlCountdown from '~/vue_shared/components/gl_countdown.vue';

describe('GlCountdown', () => {
  let wrapper;
  let now = '2000-01-01T00:00:00Z';

  beforeEach(() => {
    jest.spyOn(Date, 'now').mockImplementation(() => new Date(now).getTime());
  });

  describe('when there is time remaining', () => {
    beforeEach(() => {
      wrapper = mount(GlCountdown, {
        propsData: {
          endDateString: '2000-01-01T01:02:03Z',
        },
      });
    });

    it('displays remaining time', () => {
      expect(wrapper.text()).toContain('01:02:03');
    });

    it('updates remaining time', async () => {
      now = '2000-01-01T00:00:01Z';
      jest.advanceTimersByTime(1000);

      await nextTick();
      expect(wrapper.text()).toContain('01:02:02');
    });
  });

  describe('when there is no time remaining', () => {
    beforeEach(() => {
      wrapper = mount(GlCountdown, {
        propsData: {
          endDateString: '1900-01-01T00:00:00Z',
        },
      });
    });

    it('displays 00:00:00', () => {
      expect(wrapper.text()).toContain('00:00:00');
    });
  });

  describe('when an invalid date is passed', () => {
    beforeEach(() => {
      Vue.config.warnHandler = jest.fn();
    });

    afterEach(() => {
      Vue.config.warnHandler = null;
    });

    it('throws a validation error', () => {
      wrapper = mount(GlCountdown, {
        propsData: {
          endDateString: 'this is invalid',
        },
      });

      expect(Vue.config.warnHandler).toHaveBeenCalledTimes(1);
      const [errorMessage] = Vue.config.warnHandler.mock.calls[0];

      expect(errorMessage).toMatch(/^Invalid prop: .* "endDateString"/);
    });
  });
});