Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sidebar_inherit_date_spec.js « date « components « sidebar « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a7556b9110c1b00945a5ea9f92fc2a7bdae75323 (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
import { GlFormRadio } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import SidebarFormattedDate from '~/sidebar/components/date/sidebar_formatted_date.vue';
import SidebarInheritDate from '~/sidebar/components/date/sidebar_inherit_date.vue';

describe('SidebarInheritDate', () => {
  let wrapper;
  const findFixedFormattedDate = () => wrapper.findAllComponents(SidebarFormattedDate).at(0);
  const findInheritFormattedDate = () => wrapper.findAllComponents(SidebarFormattedDate).at(1);
  const findFixedRadio = () => wrapper.findAllComponents(GlFormRadio).at(0);
  const findInheritRadio = () => wrapper.findAllComponents(GlFormRadio).at(1);

  const createComponent = ({ dueDateIsFixed = false } = {}) => {
    wrapper = shallowMount(SidebarInheritDate, {
      provide: {
        canUpdate: true,
      },
      propsData: {
        issuable: {
          dueDate: '2021-04-15',
          dueDateIsFixed,
          dueDateFixed: '2021-04-15',
          dueDateFromMilestones: '2021-05-15',
        },
        dateType: 'dueDate',
      },
    });
  };

  beforeEach(() => {
    createComponent();
  });

  afterEach(() => {
    wrapper.destroy();
  });

  it('displays formatted fixed and inherited dates with radio buttons', () => {
    expect(wrapper.findAllComponents(SidebarFormattedDate)).toHaveLength(2);
    expect(wrapper.findAllComponents(GlFormRadio)).toHaveLength(2);
    expect(findFixedFormattedDate().props('formattedDate')).toBe('Apr 15, 2021');
    expect(findInheritFormattedDate().props('formattedDate')).toBe('May 15, 2021');
    expect(findFixedRadio().text()).toBe('Fixed:');
    expect(findInheritRadio().text()).toBe('Inherited:');
  });

  it('does not emit set-date if fixed value does not change', () => {
    createComponent({ dueDateIsFixed: true });
    findFixedRadio().vm.$emit('input', true);

    expect(wrapper.emitted('set-date')).toBeUndefined();
  });

  it('emits set-date event on click on radio button', () => {
    findFixedRadio().vm.$emit('input', true);

    expect(wrapper.emitted('set-date')).toEqual([[true]]);
  });
});