total_time_component_spec.js 1.36 KB
Newer Older
1 2
import Vue from 'vue';
import component from '~/cycle_analytics/components/total_time_component.vue';
3
import mountComponent from 'spec/helpers/vue_mount_component_helper';
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

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,
        },
      });

Filipa Lacerda's avatar
Filipa Lacerda committed
26
      expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toEqual('3 days 4 hrs');
27 28 29 30 31 32 33 34 35 36
    });

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

Filipa Lacerda's avatar
Filipa Lacerda committed
37
      expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toEqual('4 hrs 35 mins');
38 39 40 41 42 43 44 45 46
    });

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

Filipa Lacerda's avatar
Filipa Lacerda committed
47
      expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toEqual('45 s');
48 49 50 51 52 53 54 55 56 57 58
    });
  });

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

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