summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/pikaday_spec.js
blob: 1c6876c282c58ff2e441e2f8a008133e85e95a3c (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
import { shallowMount } from '@vue/test-utils';
import { GlDatepicker } from '@gitlab/ui';
import datePicker from '~/vue_shared/components/pikaday.vue';

describe('datePicker', () => {
  let wrapper;

  const buildWrapper = (propsData = {}) => {
    wrapper = shallowMount(datePicker, {
      propsData,
    });
  };

  afterEach(() => {
    wrapper.destroy();
    wrapper = null;
  });
  it('should emit newDateSelected when GlDatePicker emits the input event', () => {
    const minDate = new Date();
    const maxDate = new Date();
    const selectedDate = new Date();
    const theDate = selectedDate.toISOString().slice(0, 10);

    buildWrapper({ minDate, maxDate, selectedDate });

    expect(wrapper.find(GlDatepicker).props()).toMatchObject({
      minDate,
      maxDate,
      value: selectedDate,
    });
    wrapper.find(GlDatepicker).vm.$emit('input', selectedDate);
    expect(wrapper.emitted('newDateSelected')[0][0]).toBe(theDate);
  });
  it('should emit the hidePicker event when GlDatePicker emits the close event', () => {
    buildWrapper();

    wrapper.find(GlDatepicker).vm.$emit('close');

    expect(wrapper.emitted('hidePicker')).toHaveLength(1);
  });
});