summaryrefslogtreecommitdiff
path: root/spec/javascripts/vue_shared/components/time_ago_tooltip_spec.js
blob: bf28019ef241a27342409254d6451c5f5da2cc02 (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
import Vue from 'vue';
import timeagoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import '~/lib/utils/datetime_utility';

describe('Time ago with tooltip component', () => {
  let TimeagoTooltip;
  let vm;

  beforeEach(() => {
    TimeagoTooltip = Vue.extend(timeagoTooltip);
  });

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

  it('should render timeago with a bootstrap tooltip', () => {
    vm = new TimeagoTooltip({
      propsData: {
        time: '2017-05-08T14:57:39.781Z',
      },
    }).$mount();

    expect(vm.$el.tagName).toEqual('TIME');
    expect(vm.$el.classList.contains('js-timeago')).toEqual(true);
    expect(
      vm.$el.getAttribute('data-original-title'),
    ).toEqual(gl.utils.formatDate('2017-05-08T14:57:39.781Z'));
    expect(vm.$el.getAttribute('data-placement')).toEqual('top');

    const timeago = gl.utils.getTimeago();

    expect(vm.$el.textContent.trim()).toEqual(timeago.format('2017-05-08T14:57:39.781Z'));
  });

  it('should render tooltip placed in bottom', () => {
    vm = new TimeagoTooltip({
      propsData: {
        time: '2017-05-08T14:57:39.781Z',
        tooltipPlacement: 'bottom',
      },
    }).$mount();

    expect(vm.$el.getAttribute('data-placement')).toEqual('bottom');
  });

  it('should render short format class', () => {
    vm = new TimeagoTooltip({
      propsData: {
        time: '2017-05-08T14:57:39.781Z',
        shortFormat: true,
      },
    }).$mount();

    expect(vm.$el.classList.contains('js-short-timeago')).toEqual(true);
  });

  it('should render provided html class', () => {
    vm = new TimeagoTooltip({
      propsData: {
        time: '2017-05-08T14:57:39.781Z',
        cssClass: 'foo',
      },
    }).$mount();

    expect(vm.$el.classList.contains('foo')).toEqual(true);
  });
});