summaryrefslogtreecommitdiff
path: root/spec/javascripts/cycle_analytics/total_time_component_spec.js
blob: ad0fc38a856d53e3fd5b852f4893c39795c54e3f (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
import Vue from 'vue';
import component from '~/cycle_analytics/components/total_time_component.vue';
import mountComponent from '../helpers/vue_mount_component_helper';

describe('Total time component', () => {
  let vm;
  let Component;

  beforeEach(() => {
    Component = Vue.extend(component);
  });

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

  describe('With data', () => {
    it('should render information for days and hours', () => {
      vm = mountComponent(Component, {
        time: {
          days: 3,
          hours: 4,
        },
      });

      expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toEqual('3 days 4 hrs');
    });

    it('should render information for hours and minutes', () => {
      vm = mountComponent(Component, {
        time: {
          hours: 4,
          mins: 35,
        },
      });

      expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toEqual('4 hrs 35 mins');
    });

    it('should render information for seconds', () => {
      vm = mountComponent(Component, {
        time: {
          seconds: 45,
        },
      });

      expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toEqual('45 s');
    });
  });

  describe('Without data', () => {
    it('should render no information', () => {
      vm = mountComponent(Component);

      expect(vm.$el.textContent.trim()).toEqual('--');
    });
  });
});