2021-04-29 21:17:54 +05:30
|
|
|
import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
|
2021-04-17 20:07:23 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2021-04-17 20:07:23 +05:30
|
|
|
import RepoDropdown from '~/projects/compare/components/repo_dropdown.vue';
|
2021-06-08 01:23:25 +05:30
|
|
|
import { revisionCardDefaultProps as defaultProps } from './mock_data';
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
describe('RepoDropdown component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
const createComponent = (props = {}) => {
|
2021-04-17 20:07:23 +05:30
|
|
|
wrapper = shallowMount(RepoDropdown, {
|
|
|
|
propsData: {
|
|
|
|
...defaultProps,
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
const findGlDropdown = () => wrapper.findComponent(GlDropdown);
|
2021-04-17 20:07:23 +05:30
|
|
|
const findHiddenInput = () => wrapper.find('input[type="hidden"]');
|
|
|
|
|
|
|
|
describe('Source Revision', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('set hidden input', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findHiddenInput().attributes('value')).toBe(defaultProps.selectedProject.id);
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the project name in the disabled dropdown', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findGlDropdown().props('text')).toBe(defaultProps.selectedProject.name);
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(findGlDropdown().props('disabled')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not emit `changeTargetProject` event', async () => {
|
|
|
|
wrapper.vm.emitTargetProject('foo');
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(wrapper.emitted('changeTargetProject')).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Target Revision', () => {
|
|
|
|
beforeEach(() => {
|
2021-06-08 01:23:25 +05:30
|
|
|
const projects = [
|
|
|
|
{
|
|
|
|
name: 'some-to-name',
|
|
|
|
id: '1',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
createComponent({ paramsName: 'from', projects });
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it('set hidden input of the selected project', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findHiddenInput().attributes('value')).toBe(defaultProps.selectedProject.id);
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it('displays matching project name of the source revision initially in the dropdown', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(findGlDropdown().props('text')).toBe(defaultProps.selectedProject.name);
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('updates the hidden input value when onClick method is triggered', async () => {
|
|
|
|
const repoId = '1';
|
2021-04-17 20:07:23 +05:30
|
|
|
wrapper.vm.onClick({ id: repoId });
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(findHiddenInput().attributes('value')).toBe(repoId);
|
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('emits `selectProject` event when another target project is selected', async () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
findGlDropdown().findAllComponents(GlDropdownItem).at(0).vm.$emit('click');
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(wrapper.emitted('selectProject')[0][0]).toEqual({
|
|
|
|
direction: 'from',
|
|
|
|
project: { id: '1', name: 'some-to-name' },
|
|
|
|
});
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|