summaryrefslogtreecommitdiff
path: root/spec/frontend/packages_and_registries/settings/project/settings/components/expiration_run_text_spec.js
blob: 653f2a8b40e1714f6cf979d2d256f9d7fefab72e (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
import { GlFormInput } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { GlFormGroup } from 'jest/packages_and_registries/shared/stubs';
import component from '~/packages_and_registries/settings/project/components/expiration_run_text.vue';
import {
  NEXT_CLEANUP_LABEL,
  NOT_SCHEDULED_POLICY_TEXT,
} from '~/packages_and_registries/settings/project/constants';

describe('ExpirationToggle', () => {
  let wrapper;
  const value = 'foo';

  const findInput = () => wrapper.findComponent(GlFormInput);
  const findFormGroup = () => wrapper.findComponent(GlFormGroup);

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

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

  describe('structure', () => {
    it('has an input component', () => {
      mountComponent();

      expect(findInput().exists()).toBe(true);
    });
  });

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

      expect(findFormGroup().attributes()).toMatchObject({
        label: NEXT_CLEANUP_LABEL,
      });
    });
  });

  describe('formattedValue', () => {
    it.each`
      valueProp    | enabled  | expected
      ${value}     | ${true}  | ${value}
      ${value}     | ${false} | ${NOT_SCHEDULED_POLICY_TEXT}
      ${undefined} | ${false} | ${NOT_SCHEDULED_POLICY_TEXT}
      ${undefined} | ${true}  | ${NOT_SCHEDULED_POLICY_TEXT}
    `(
      'when value is $valueProp and enabled is $enabled the input value is $expected',
      ({ valueProp, enabled, expected }) => {
        mountComponent({ value: valueProp, enabled });

        expect(findInput().attributes('value')).toBe(expected);
      },
    );
  });
});