summaryrefslogtreecommitdiff
path: root/spec/frontend/packages_and_registries/settings/project/settings/components/expiration_dropdown_spec.js
blob: 5c9ade7f7854641b884fc421da99c4fdb76c5fd8 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { shallowMount } from '@vue/test-utils';
import { GlFormGroup, GlFormSelect } from 'jest/packages_and_registries/shared/stubs';
import component from '~/packages_and_registries/settings/project/components/expiration_dropdown.vue';

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

  const defaultProps = {
    name: 'foo',
    label: 'label-bar',
    formOptions: [
      { key: 'foo', label: 'bar' },
      { key: 'baz', label: 'zab' },
    ],
  };

  const findFormSelect = () => wrapper.find(GlFormSelect);
  const findFormGroup = () => wrapper.find(GlFormGroup);
  const findOptions = () => wrapper.findAll('[data-testid="option"]');

  const mountComponent = (props) => {
    wrapper = shallowMount(component, {
      stubs: {
        GlFormGroup,
        GlFormSelect,
      },
      propsData: {
        ...defaultProps,
        ...props,
      },
    });
  };

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

  describe('structure', () => {
    it('has a form-select component', () => {
      mountComponent();
      expect(findFormSelect().exists()).toBe(true);
    });

    it('has the correct options', () => {
      mountComponent();

      expect(findOptions()).toHaveLength(defaultProps.formOptions.length);
    });
  });

  describe('model', () => {
    it('assign the right props to the form-select component', () => {
      const value = 'foobar';
      const disabled = true;

      mountComponent({ value, disabled });

      expect(findFormSelect().props()).toMatchObject({
        value,
        disabled,
      });
      expect(findFormSelect().attributes('id')).toBe(defaultProps.name);
    });

    it('assign the right props to the form-group component', () => {
      mountComponent();

      expect(findFormGroup().attributes()).toMatchObject({
        id: `${defaultProps.name}-form-group`,
        'label-for': defaultProps.name,
        label: defaultProps.label,
      });
    });

    it('emits input event when form-select emits input', () => {
      const emittedValue = 'barfoo';

      mountComponent();

      findFormSelect().vm.$emit('input', emittedValue);

      expect(wrapper.emitted('input')).toEqual([[emittedValue]]);
    });
  });
});