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

active_checkbox_spec.js « components « edit « integrations « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0dc31616166519dab7231d0724b4393802e9a98d (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
87
88
89
import { GlFormCheckbox } from '@gitlab/ui';
import { mount } from '@vue/test-utils';

import ActiveCheckbox from '~/integrations/edit/components/active_checkbox.vue';
import { createStore } from '~/integrations/edit/store';

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

  const createComponent = (customStateProps = {}, { isInheriting = false } = {}) => {
    wrapper = mount(ActiveCheckbox, {
      store: createStore({
        customState: { ...customStateProps },
        override: !isInheriting,
        defaultState: isInheriting ? {} : undefined,
      }),
    });
  };

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

  const findGlFormCheckbox = () => wrapper.findComponent(GlFormCheckbox);
  const findInputInCheckbox = () => findGlFormCheckbox().find('input');

  describe('template', () => {
    describe('is inheriting adminSettings', () => {
      it('renders GlFormCheckbox as disabled', () => {
        createComponent({}, { isInheriting: true });

        expect(findGlFormCheckbox().exists()).toBe(true);
        expect(findInputInCheckbox().attributes('disabled')).toBe('disabled');
      });
    });

    describe('initialActivated is `false`', () => {
      beforeEach(() => {
        createComponent({
          initialActivated: false,
        });
      });

      it('renders GlFormCheckbox as unchecked', () => {
        expect(findGlFormCheckbox().exists()).toBe(true);
        expect(findGlFormCheckbox().vm.$attrs.checked).toBe(false);
        expect(findInputInCheckbox().attributes('disabled')).toBeUndefined();
      });

      it('emits `toggle-integration-active` event with `false` on mount', () => {
        expect(wrapper.emitted('toggle-integration-active')[0]).toEqual([false]);
      });
    });

    describe('initialActivated is true', () => {
      beforeEach(() => {
        createComponent({
          initialActivated: true,
        });
      });

      it('renders GlFormCheckbox as checked', () => {
        expect(findGlFormCheckbox().exists()).toBe(true);
        expect(findGlFormCheckbox().vm.$attrs.checked).toBe(true);
      });

      describe('on checkbox click', () => {
        it('switches the form value', async () => {
          findInputInCheckbox().trigger('click');

          await wrapper.vm.$nextTick();
          expect(findGlFormCheckbox().vm.$attrs.checked).toBe(false);
        });
      });

      it('emits `toggle-integration-active` event with `true` on mount', () => {
        expect(wrapper.emitted('toggle-integration-active')[0]).toEqual([true]);
      });

      describe('on checkbox `change` event', () => {
        it('emits `toggle-integration-active` event', () => {
          findGlFormCheckbox().vm.$emit('change', false);

          expect(wrapper.emitted('toggle-integration-active')[1]).toEqual([false]);
        });
      });
    });
  });
});