summaryrefslogtreecommitdiff
path: root/spec/frontend/packages_and_registries/settings/project/settings/components/expiration_toggle_spec.js
blob: 45039614e49a62ceb1d37d74770ee3d2dfe57b1b (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
import { GlToggle, GlSprintf } 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_toggle.vue';
import {
  ENABLED_TOGGLE_DESCRIPTION,
  DISABLED_TOGGLE_DESCRIPTION,
} from '~/packages_and_registries/settings/project/constants';

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

  const findToggle = () => wrapper.find(GlToggle);
  const findDescription = () => wrapper.find('[data-testid="description"]');

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

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

  describe('structure', () => {
    it('has a toggle component', () => {
      mountComponent();

      expect(findToggle().props('label')).toBe(component.i18n.toggleLabel);
    });

    it('has a description', () => {
      mountComponent();

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

  describe('model', () => {
    it('assigns the right props to the toggle component', () => {
      mountComponent({ value: true, disabled: true });

      expect(findToggle().props()).toMatchObject({
        value: true,
        disabled: true,
      });
    });

    it('emits input event when toggle is updated', () => {
      mountComponent();

      findToggle().vm.$emit('change', false);

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

  describe('toggle description', () => {
    it('says enabled when the toggle is on', () => {
      mountComponent({ value: true });

      expect(findDescription().text()).toMatchInterpolatedText(ENABLED_TOGGLE_DESCRIPTION);
    });

    it('says disabled when the toggle is off', () => {
      mountComponent({ value: false });

      expect(findDescription().text()).toMatchInterpolatedText(DISABLED_TOGGLE_DESCRIPTION);
    });
  });
});