2023-06-20 00:43:36 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
|
2022-08-27 11:52:29 +05:30
|
|
|
import NewDropdown from '~/ide/components/new_dropdown/index.vue';
|
|
|
|
import Button from '~/ide/components/new_dropdown/button.vue';
|
2023-06-20 00:43:36 +05:30
|
|
|
import Modal from '~/ide/components/new_dropdown/modal.vue';
|
|
|
|
import { stubComponent } from 'helpers/stub_component';
|
|
|
|
|
|
|
|
Vue.use(Vuex);
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
describe('new dropdown component', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
let wrapper;
|
2023-06-20 00:43:36 +05:30
|
|
|
const openMock = jest.fn();
|
|
|
|
const deleteEntryMock = jest.fn();
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
const findAllButtons = () => wrapper.findAllComponents(Button);
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
const mountComponent = (props = {}) => {
|
|
|
|
const fakeStore = () => {
|
|
|
|
return new Vuex.Store({
|
|
|
|
actions: {
|
|
|
|
deleteEntry: deleteEntryMock,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2022-08-27 11:52:29 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
wrapper = mountExtended(NewDropdown, {
|
|
|
|
store: fakeStore(),
|
2022-08-27 11:52:29 +05:30
|
|
|
propsData: {
|
|
|
|
branch: 'main',
|
|
|
|
path: '',
|
|
|
|
mouseOver: false,
|
|
|
|
type: 'tree',
|
2023-06-20 00:43:36 +05:30
|
|
|
...props,
|
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
NewModal: stubComponent(Modal, {
|
|
|
|
methods: {
|
|
|
|
open: openMock,
|
|
|
|
},
|
|
|
|
}),
|
2022-08-27 11:52:29 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
2022-08-27 11:52:29 +05:30
|
|
|
};
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
mountComponent();
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders new file, upload and new directory links', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(findAllButtons().at(0).text()).toBe('New file');
|
|
|
|
expect(findAllButtons().at(1).text()).toBe('Upload file');
|
|
|
|
expect(findAllButtons().at(2).text()).toBe('New directory');
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('createNewItem', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
it('opens modal for a blob when new file is clicked', () => {
|
2023-06-20 00:43:36 +05:30
|
|
|
findAllButtons().at(0).vm.$emit('click');
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
expect(openMock).toHaveBeenCalledWith('blob', '');
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('opens modal for a tree when new directory is clicked', () => {
|
2023-06-20 00:43:36 +05:30
|
|
|
findAllButtons().at(2).vm.$emit('click');
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
expect(openMock).toHaveBeenCalledWith('tree', '');
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe('isOpen', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
it('scrolls dropdown into view', async () => {
|
2023-06-20 00:43:36 +05:30
|
|
|
const dropdownMenu = wrapper.findByTestId('dropdown-menu');
|
|
|
|
const scrollIntoViewSpy = jest.spyOn(dropdownMenu.element, 'scrollIntoView');
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
await wrapper.setProps({ isOpen: true });
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
expect(scrollIntoViewSpy).toHaveBeenCalledWith({ block: 'nearest' });
|
2018-10-15 14:42:47 +05:30
|
|
|
});
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
describe('delete entry', () => {
|
|
|
|
it('calls delete action', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
findAllButtons().at(4).trigger('click');
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
expect(deleteEntryMock).toHaveBeenCalledWith(expect.anything(), '');
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|