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: 82d18c7fd3feed59fb7b1361ad69b7c02c9f9c0f (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
import Vue from 'vue';
import mountComponent from 'helpers/vue_mount_component_helper';
import GlCountdown from '~/vue_shared/components/gl_countdown.vue';

describe('GlCountdown', () => {
  const Component = Vue.extend(GlCountdown);
  let vm;
  let now = '2000-01-01T00:00:00Z';

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

  afterEach(() => {
    vm.$destroy();
    jest.clearAllTimers();
  });

  describe('when there is time remaining', () => {
    beforeEach((done) => {
      vm = mountComponent(Component, {
        endDateString: '2000-01-01T01:02:03Z',
      });

      Vue.nextTick().then(done).catch(done.fail);
    });

    it('displays remaining time', () => {
      expect(vm.$el.textContent).toContain('01:02:03');
    });

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

      Vue.nextTick()
        .then(() => {
          expect(vm.$el.textContent).toContain('01:02:02');
          done();
        })
        .catch(done.fail);
    });
  });

  describe('when there is no time remaining', () => {
    beforeEach((done) => {
      vm = mountComponent(Component, {
        endDateString: '1900-01-01T00:00:00Z',
      });

      Vue.nextTick().then(done).catch(done.fail);
    });

    it('displays 00:00:00', () => {
      expect(vm.$el.textContent).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', () => {
      vm = mountComponent(Component, {
        endDateString: 'this is invalid',
      });

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

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