debian-mirror-gitlab/spec/frontend/ide/components/ide_file_row_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

114 lines
2.6 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { mount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
2020-03-13 15:44:24 +05:30
import Vuex from 'vuex';
import FileRowExtra from '~/ide/components/file_row_extra.vue';
2021-03-11 19:13:27 +05:30
import IdeFileRow from '~/ide/components/ide_file_row.vue';
2020-03-13 15:44:24 +05:30
import { createStore } from '~/ide/stores';
2021-03-11 19:13:27 +05:30
import FileRow from '~/vue_shared/components/file_row.vue';
2020-03-13 15:44:24 +05:30
2022-04-04 11:22:00 +05:30
Vue.use(Vuex);
2020-03-13 15:44:24 +05:30
const TEST_EXTRA_PROPS = {
testattribute: 'abc',
};
const defaultComponentProps = (type = 'tree') => ({
level: 4,
file: {
type,
name: 'js',
},
});
describe('Ide File Row component', () => {
let wrapper;
const createComponent = (props = {}, options = {}) => {
wrapper = mount(IdeFileRow, {
propsData: {
...defaultComponentProps(),
...props,
},
store: createStore(),
...options,
});
};
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
2022-08-27 11:52:29 +05:30
const findFileRowExtra = () => wrapper.findComponent(FileRowExtra);
const findFileRow = () => wrapper.findComponent(FileRow);
2020-03-13 15:44:24 +05:30
const hasDropdownOpen = () => findFileRowExtra().props('dropdownOpen');
2022-04-04 11:22:00 +05:30
it('fileRow component has listeners', async () => {
2020-03-13 15:44:24 +05:30
const toggleTreeOpen = jest.fn();
createComponent(
{},
{
listeners: {
toggleTreeOpen,
},
},
);
findFileRow().vm.$emit('toggleTreeOpen');
2022-04-04 11:22:00 +05:30
await nextTick();
expect(toggleTreeOpen).toHaveBeenCalled();
2020-03-13 15:44:24 +05:30
});
describe('default', () => {
beforeEach(() => {
createComponent(TEST_EXTRA_PROPS);
});
it('renders file row component', () => {
const fileRow = findFileRow();
expect(fileRow.props()).toEqual(expect.objectContaining(defaultComponentProps()));
expect(fileRow.attributes()).toEqual(expect.objectContaining(TEST_EXTRA_PROPS));
});
it('renders file row extra', () => {
const extra = findFileRowExtra();
expect(extra.exists()).toBe(true);
expect(extra.props()).toEqual({
file: defaultComponentProps().file,
dropdownOpen: false,
});
});
});
describe('with open dropdown', () => {
2022-04-04 11:22:00 +05:30
beforeEach(async () => {
2020-03-13 15:44:24 +05:30
createComponent();
findFileRowExtra().vm.$emit('toggle', true);
2022-04-04 11:22:00 +05:30
await nextTick();
2020-03-13 15:44:24 +05:30
});
it('shows open dropdown', () => {
expect(hasDropdownOpen()).toBe(true);
});
2022-04-04 11:22:00 +05:30
it('hides dropdown when mouseleave', async () => {
2020-03-13 15:44:24 +05:30
findFileRow().vm.$emit('mouseleave');
2022-04-04 11:22:00 +05:30
await nextTick();
expect(hasDropdownOpen()).toEqual(false);
2020-03-13 15:44:24 +05:30
});
2022-04-04 11:22:00 +05:30
it('hides dropdown on toggle', async () => {
2020-03-13 15:44:24 +05:30
findFileRowExtra().vm.$emit('toggle', false);
2022-04-04 11:22:00 +05:30
await nextTick();
expect(hasDropdownOpen()).toEqual(false);
2020-03-13 15:44:24 +05:30
});
});
});