Commit 07016c97 authored by Jacques Erasmus's avatar Jacques Erasmus

Merge branch '327291-compare-dropdown-same-group-default' into 'master'

Make  default target repo same as source repo

See merge request gitlab-org/gitlab!58997
parents b08486ce 98f40050
...@@ -46,14 +46,7 @@ export default { ...@@ -46,14 +46,7 @@ export default {
this.emitTargetProject(repo.name); this.emitTargetProject(repo.name);
}, },
setDefaultRepo() { setDefaultRepo() {
if (this.isSourceRevision) {
this.selectedRepo = this.projectTo; this.selectedRepo = this.projectTo;
return;
}
const [defaultTargetProject] = this.projectsFrom;
this.emitTargetProject(defaultTargetProject.name);
this.selectedRepo = defaultTargetProject;
}, },
emitTargetProject(name) { emitTargetProject(name) {
if (!this.isSourceRevision) { if (!this.isSourceRevision) {
......
import { GlDropdown } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import RepoDropdown from '~/projects/compare/components/repo_dropdown.vue'; import RepoDropdown from '~/projects/compare/components/repo_dropdown.vue';
...@@ -69,12 +69,12 @@ describe('RepoDropdown component', () => { ...@@ -69,12 +69,12 @@ describe('RepoDropdown component', () => {
createComponent({ paramsName: 'from' }); createComponent({ paramsName: 'from' });
}); });
it('set hidden input of the first project', () => { it('set hidden input of the selected project', () => {
expect(findHiddenInput().attributes('value')).toBe(projectFromId); expect(findHiddenInput().attributes('value')).toBe(projectToId);
}); });
it('displays the first project name initially in the dropdown', () => { it('displays matching project name of the source revision initially in the dropdown', () => {
expect(findGlDropdown().props('text')).toBe(projectFromName); expect(findGlDropdown().props('text')).toBe(projectToName);
}); });
it('updates the hiddin input value when onClick method is triggered', async () => { it('updates the hiddin input value when onClick method is triggered', async () => {
...@@ -84,15 +84,13 @@ describe('RepoDropdown component', () => { ...@@ -84,15 +84,13 @@ describe('RepoDropdown component', () => {
expect(findHiddenInput().attributes('value')).toBe(repoId); expect(findHiddenInput().attributes('value')).toBe(repoId);
}); });
it('emits initial `changeTargetProject` event with target project', () => {
expect(wrapper.emitted('changeTargetProject')).toEqual([[projectFromName]]);
});
it('emits `changeTargetProject` event when another target project is selected', async () => { it('emits `changeTargetProject` event when another target project is selected', async () => {
const newTargetProject = 'new-from-name'; const index = 1;
wrapper.vm.$emit('changeTargetProject', newTargetProject); const { projectsFrom } = defaultProvide;
findGlDropdown().findAll(GlDropdownItem).at(index).vm.$emit('click');
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
expect(wrapper.emitted('changeTargetProject')[1]).toEqual([newTargetProject]);
expect(wrapper.emitted('changeTargetProject')[0][0]).toEqual(projectsFrom[index].name);
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment