summaryrefslogtreecommitdiff
path: root/spec/frontend/projects/details/upload_button_spec.js
blob: e9b11ce544a6bbdccc3e4c5567ba95f82fa3af5e (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
import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import UploadButton from '~/projects/details/upload_button.vue';
import UploadBlobModal from '~/repository/components/upload_blob_modal.vue';

const MODAL_ID = 'details-modal-upload-blob';

describe('UploadButton', () => {
  let wrapper;
  let glModalDirective;

  const createComponent = () => {
    glModalDirective = jest.fn();

    return shallowMount(UploadButton, {
      directives: {
        glModal: {
          bind(_, { value }) {
            glModalDirective(value);
          },
        },
      },
    });
  };

  beforeEach(() => {
    wrapper = createComponent();
  });

  it('displays an upload button', () => {
    expect(wrapper.findComponent(GlButton).exists()).toBe(true);
  });

  it('contains a modal', () => {
    const modal = wrapper.findComponent(UploadBlobModal);

    expect(modal.exists()).toBe(true);
    expect(modal.props('modalId')).toBe(MODAL_ID);
  });

  describe('when clickinig the upload file button', () => {
    beforeEach(() => {
      wrapper.findComponent(GlButton).vm.$emit('click');
    });

    it('opens the modal', () => {
      expect(glModalDirective).toHaveBeenCalledWith(MODAL_ID);
    });
  });
});