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

expiration_run_text_spec.js « components « settings « registry « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d023f1fd05a2d8aa9836327593e168ce19f3aba1 (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
import { shallowMount } from '@vue/test-utils';
import { GlFormInput } from '@gitlab/ui';
import { GlFormGroup } from 'jest/registry/shared/stubs';
import component from '~/registry/settings/components/expiration_run_text.vue';
import { NEXT_CLEANUP_LABEL, NOT_SCHEDULED_POLICY_TEXT } from '~/registry/settings/constants';

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

  const findInput = () => wrapper.find(GlFormInput);
  const findFormGroup = () => wrapper.find(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 input component', () => {
      mountComponent({ value, disabled: true });

      expect(findInput().attributes()).toMatchObject({
        value,
      });
    });

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

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

  describe('formattedValue', () => {
    it('displays the values when it exists', () => {
      mountComponent({ value });

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

    it('displays a placeholder when no value is present', () => {
      mountComponent();

      expect(findInput().attributes('value')).toBe(NOT_SCHEDULED_POLICY_TEXT);
    });
  });
});