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

index_spec.js « new_dropdown « components « ide « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a2371abe955011db8ecf3bb31615173598762fbe (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
import Vue from 'vue';
import Vuex from 'vuex';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import NewDropdown from '~/ide/components/new_dropdown/index.vue';
import Button from '~/ide/components/new_dropdown/button.vue';
import Modal from '~/ide/components/new_dropdown/modal.vue';
import { stubComponent } from 'helpers/stub_component';

Vue.use(Vuex);

describe('new dropdown component', () => {
  let wrapper;
  const openMock = jest.fn();
  const deleteEntryMock = jest.fn();

  const findAllButtons = () => wrapper.findAllComponents(Button);

  const mountComponent = (props = {}) => {
    const fakeStore = () => {
      return new Vuex.Store({
        actions: {
          deleteEntry: deleteEntryMock,
        },
      });
    };

    wrapper = mountExtended(NewDropdown, {
      store: fakeStore(),
      propsData: {
        branch: 'main',
        path: '',
        mouseOver: false,
        type: 'tree',
        ...props,
      },
      stubs: {
        NewModal: stubComponent(Modal, {
          methods: {
            open: openMock,
          },
        }),
      },
    });
  };

  beforeEach(() => {
    mountComponent();
  });

  it('renders new file, upload and new directory links', () => {
    expect(findAllButtons().at(0).text()).toBe('New file');
    expect(findAllButtons().at(1).text()).toBe('Upload file');
    expect(findAllButtons().at(2).text()).toBe('New directory');
  });

  describe('createNewItem', () => {
    it('opens modal for a blob when new file is clicked', () => {
      findAllButtons().at(0).vm.$emit('click');

      expect(openMock).toHaveBeenCalledWith('blob', '');
    });

    it('opens modal for a tree when new directory is clicked', () => {
      findAllButtons().at(2).vm.$emit('click');

      expect(openMock).toHaveBeenCalledWith('tree', '');
    });
  });

  describe('isOpen', () => {
    it('scrolls dropdown into view', async () => {
      const dropdownMenu = wrapper.findByTestId('dropdown-menu');
      const scrollIntoViewSpy = jest.spyOn(dropdownMenu.element, 'scrollIntoView');

      await wrapper.setProps({ isOpen: true });

      expect(scrollIntoViewSpy).toHaveBeenCalledWith({ block: 'nearest' });
    });
  });

  describe('delete entry', () => {
    it('calls delete action', () => {
      findAllButtons().at(4).trigger('click');

      expect(deleteEntryMock).toHaveBeenCalledWith(expect.anything(), '');
    });
  });
});