summaryrefslogtreecommitdiff
path: root/spec/javascripts/boards/components/issue_due_date_spec.js
blob: 9e49330c052d0c40850031924ea14b72ef3513d1 (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
import Vue from 'vue';
import dateFormat from 'dateformat';
import IssueDueDate from '~/boards/components/issue_due_date.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';

describe('Issue Due Date component', () => {
  let vm;
  let date;
  const Component = Vue.extend(IssueDueDate);
  const createComponent = (dueDate = new Date()) =>
    mountComponent(Component, { date: dateFormat(dueDate, 'yyyy-mm-dd', true) });

  beforeEach(() => {
    date = new Date();
    vm = createComponent();
  });

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

  it('should render "Today" if the due date is today', () => {
    const timeContainer = vm.$el.querySelector('time');

    expect(timeContainer.textContent.trim()).toEqual('Today');
  });

  it('should render "Yesterday" if the due date is yesterday', () => {
    date.setDate(date.getDate() - 1);
    vm = createComponent(date);

    expect(vm.$el.querySelector('time').textContent.trim()).toEqual('Yesterday');
  });

  it('should render "Tomorrow" if the due date is one day from now', () => {
    date.setDate(date.getDate() + 1);
    vm = createComponent(date);

    expect(vm.$el.querySelector('time').textContent.trim()).toEqual('Tomorrow');
  });

  it('should render day of the week if due date is one week away', () => {
    date.setDate(date.getDate() + 5);
    vm = createComponent(date);

    expect(vm.$el.querySelector('time').textContent.trim()).toEqual(dateFormat(date, 'dddd', true));
  });

  it('should render month and day for other dates', () => {
    date.setDate(date.getDate() + 17);
    vm = createComponent(date);

    expect(vm.$el.querySelector('time').textContent.trim()).toEqual(
      dateFormat(date, 'mmm d', true),
    );
  });

  it('should contain the correct `.text-danger` css class for overdue issue', () => {
    date.setDate(date.getDate() - 17);
    vm = createComponent(date);

    expect(vm.$el.querySelector('time').classList.contains('text-danger')).toEqual(true);
  });
});