summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/confirm_fork_modal_spec.js
blob: 1cde92cf522c825fa4b9f040509c1fccf803b9ea (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
import { GlModal } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ConfirmForkModal, { i18n } from '~/vue_shared/components/confirm_fork_modal.vue';

describe('vue_shared/components/confirm_fork_modal', () => {
  let wrapper = null;

  const forkPath = '/fake/fork/path';
  const modalId = 'confirm-fork-modal';
  const defaultProps = { modalId, forkPath };

  const findModal = () => wrapper.findComponent(GlModal);
  const findModalProp = (prop) => findModal().props(prop);
  const findModalActionProps = () => findModalProp('actionPrimary');

  const createComponent = (props = {}) =>
    shallowMountExtended(ConfirmForkModal, {
      propsData: {
        ...defaultProps,
        ...props,
      },
    });

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

  describe('visible = false', () => {
    beforeEach(() => {
      wrapper = createComponent();
    });

    it('sets the visible prop to `false`', () => {
      expect(findModalProp('visible')).toBe(false);
    });

    it('sets the modal title', () => {
      const title = findModalProp('title');
      expect(title).toBe(i18n.title);
    });

    it('sets the modal id', () => {
      const fakeModalId = findModalProp('modalId');
      expect(fakeModalId).toBe(modalId);
    });

    it('has the fork path button', () => {
      const modalProps = findModalActionProps();
      expect(modalProps.text).toBe(i18n.btnText);
      expect(modalProps.attributes.variant).toBe('confirm');
    });

    it('sets the correct fork path', () => {
      const modalProps = findModalActionProps();
      expect(modalProps.attributes.href).toBe(forkPath);
    });

    it('has the fork message', () => {
      expect(findModal().text()).toContain(i18n.message);
    });
  });

  describe('visible = true', () => {
    beforeEach(() => {
      wrapper = createComponent({ visible: true });
    });

    it('sets the visible prop to `true`', () => {
      expect(findModalProp('visible')).toBe(true);
    });

    it('emits the `change` event if the modal is hidden', () => {
      expect(wrapper.emitted('change')).toBeUndefined();

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

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