summaryrefslogtreecommitdiff
path: root/spec/frontend/ide/components/cannot_push_code_alert_spec.js
blob: ff659ecdf3fe2d0016dfa6597607cd93d87217f5 (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
import { GlButton, GlAlert } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { stubComponent } from 'helpers/stub_component';
import CannotPushCodeAlert from '~/ide/components/cannot_push_code_alert.vue';

const TEST_MESSAGE = 'Hello test message!';
const TEST_HREF = '/test/path/to/fork';
const TEST_BUTTON_TEXT = 'Fork text';

describe('ide/components/cannot_push_code_alert', () => {
  let wrapper;

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

  const createComponent = (props = {}) => {
    wrapper = shallowMount(CannotPushCodeAlert, {
      propsData: {
        message: TEST_MESSAGE,
        ...props,
      },
      stubs: {
        GlAlert: {
          ...stubComponent(GlAlert),
          template: `<div><slot></slot><slot name="actions"></slot></div>`,
        },
      },
    });
  };

  const findAlert = () => wrapper.findComponent(GlAlert);
  const findButtonData = () => {
    const button = findAlert().findComponent(GlButton);

    if (!button.exists()) {
      return null;
    }

    return {
      href: button.attributes('href'),
      method: button.attributes('data-method'),
      text: button.text(),
    };
  };

  describe('without actions', () => {
    beforeEach(() => {
      createComponent();
    });

    it('shows alert with message', () => {
      expect(findAlert().props()).toMatchObject({ dismissible: false });
      expect(findAlert().text()).toBe(TEST_MESSAGE);
    });
  });

  describe.each`
    action                                                       | buttonData
    ${{}}                                                        | ${null}
    ${{ href: TEST_HREF, text: TEST_BUTTON_TEXT }}               | ${{ href: TEST_HREF, text: TEST_BUTTON_TEXT }}
    ${{ href: TEST_HREF, text: TEST_BUTTON_TEXT, isForm: true }} | ${{ href: TEST_HREF, text: TEST_BUTTON_TEXT, method: 'post' }}
  `('with action=$action', ({ action, buttonData }) => {
    beforeEach(() => {
      createComponent({ action });
    });

    it(`show button=${JSON.stringify(buttonData)}`, () => {
      expect(findButtonData()).toEqual(buttonData);
    });
  });
});