Commit b2674aea authored by Phil Hughes's avatar Phil Hughes

Merge branch '9594-fix-uses-with-project-avatar' into 'master'

Remove getChildInstances in project_header_spec and project_search_spec

See merge request gitlab-org/gitlab-ee!9433
parents 51543856 727f7d80
import Vue from 'vue'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import ProjectHeader from 'ee/operations/components/dashboard/project_header.vue'; import ProjectHeader from 'ee/operations/components/dashboard/project_header.vue';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue';
import { removeWhitespace } from 'spec/helpers/vue_component_helper'; import { removeWhitespace } from 'spec/helpers/vue_component_helper';
import { getChildInstances } from '../../helpers';
import { mockOneProject, mockText } from '../../mock_data'; import { mockOneProject, mockText } from '../../mock_data';
const localVue = createLocalVue();
describe('project header component', () => { describe('project header component', () => {
const ProjectHeaderComponent = Vue.extend(ProjectHeader); let wrapper;
const ProjectAvatarComponent = Vue.extend(ProjectAvatar);
let vm;
beforeEach(() => { const factory = () => {
vm = mountComponentWithStore(ProjectHeaderComponent, { wrapper = shallowMount(localVue.extend(ProjectHeader), {
props: { propsData: {
project: mockOneProject, project: mockOneProject,
}, },
localVue,
sync: false,
}); });
};
beforeEach(() => {
factory();
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); wrapper.destroy();
}); });
it('renders project name with namespace', () => { it('renders project name with namespace', () => {
const name = vm.$el.querySelector('.js-name-with-namespace').innerText; const name = wrapper.find('.js-name-with-namespace').text();
expect(removeWhitespace(name).trim()).toBe(mockOneProject.name_with_namespace); expect(removeWhitespace(name).trim()).toBe(mockOneProject.name_with_namespace);
}); });
...@@ -32,35 +36,37 @@ describe('project header component', () => { ...@@ -32,35 +36,37 @@ describe('project header component', () => {
it('links project name to project', () => { it('links project name to project', () => {
const path = mockOneProject.web_url; const path = mockOneProject.web_url;
expect(vm.$el.querySelector('.js-project-link').href).toBe(path); expect(wrapper.find('.js-project-link').attributes('href')).toBe(path);
}); });
describe('wrapped components', () => { describe('wrapped components', () => {
describe('project avatar', () => { describe('project avatar', () => {
it('renders', () => { it('renders', () => {
expect(getChildInstances(vm, ProjectAvatarComponent).length).toBe(1); expect(wrapper.findAll(ProjectAvatar).length).toBe(1);
}); });
it('binds project', () => { it('binds project', () => {
const [avatar] = getChildInstances(vm, ProjectAvatarComponent); expect(wrapper.find(ProjectAvatar).props('project')).toEqual(mockOneProject);
expect(avatar.project).toEqual(vm.project);
}); });
}); });
}); });
describe('dropdown menu', () => { describe('dropdown menu', () => {
it('renders removal button', () => { it('renders removal button', () => {
expect(vm.$el.querySelector('.js-remove-button').innerText.trim()).toBe( expect(
mockText.REMOVE_PROJECT, wrapper
); .find('.js-remove-button')
.text()
.trim(),
).toBe(mockText.REMOVE_PROJECT);
}); });
it('emits project removal link on click', () => { it('emits project removal link on click', () => {
const spy = spyOn(vm, '$emit'); wrapper.find('.js-remove-button').trigger('click');
vm.$el.querySelector('.js-remove-button').click();
expect(spy).toHaveBeenCalledWith('remove', mockOneProject.remove_path); expect(wrapper.emittedByOrder()).toEqual([
{ name: 'remove', args: [mockOneProject.remove_path] },
]);
}); });
}); });
}); });
import Vue from 'vue'; import Vue from 'vue';
import store from 'ee/operations/store/index'; import store from 'ee/operations/store/index';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue';
import ProjectSearch from 'ee/operations/components/dashboard/project_search.vue'; import ProjectSearch from 'ee/operations/components/dashboard/project_search.vue';
import TokenizedInput from 'ee/operations/components/tokenized_input/input.vue'; import TokenizedInput from 'ee/operations/components/tokenized_input/input.vue';
import { mockText, mockProjectData } from '../../mock_data'; import { mockText, mockProjectData } from '../../mock_data';
...@@ -10,7 +9,6 @@ import { getChildInstances, mouseEvent, clearState } from '../../helpers'; ...@@ -10,7 +9,6 @@ import { getChildInstances, mouseEvent, clearState } from '../../helpers';
describe('project search component', () => { describe('project search component', () => {
const ProjectSearchComponent = Vue.extend(ProjectSearch); const ProjectSearchComponent = Vue.extend(ProjectSearch);
const TokenizedInputComponent = Vue.extend(TokenizedInput); const TokenizedInputComponent = Vue.extend(TokenizedInput);
const ProjectAvatarComponent = Vue.extend(ProjectAvatar);
const mockProjects = mockProjectData(1); const mockProjects = mockProjectData(1);
const [mockOneProject] = mockProjects; const [mockOneProject] = mockProjects;
...@@ -157,7 +155,7 @@ describe('project search component', () => { ...@@ -157,7 +155,7 @@ describe('project search component', () => {
beforeEach(() => { beforeEach(() => {
store.state.projectSearchResults = mockProjects; store.state.projectSearchResults = mockProjects;
vm = mount(); vm = mount();
avatars = getChildInstances(vm, ProjectAvatarComponent); avatars = vm.$el.querySelectorAll('.project-avatar');
}); });
it('renders project avatar component', () => { it('renders project avatar component', () => {
...@@ -166,8 +164,10 @@ describe('project search component', () => { ...@@ -166,8 +164,10 @@ describe('project search component', () => {
it('binds project to project', () => { it('binds project to project', () => {
const [avatar] = avatars; const [avatar] = avatars;
const identicon = avatar.querySelector('.identicon');
const [identiconLetter] = mockOneProject.name;
expect(avatar.project).toEqual(mockOneProject); expect(identicon.textContent.trim()).toEqual(identiconLetter.toUpperCase());
}); });
}); });
}); });
......
...@@ -4,6 +4,11 @@ export function clearState(store) { ...@@ -4,6 +4,11 @@ export function clearState(store) {
store.replaceState(state()); store.replaceState(state());
} }
/**
* @deprecated
* DO NOT USE! This causes issues when `vue-test-utils` is used elsewhere.
* This function will be removed in https://gitlab.com/gitlab-org/gitlab-ee/issues/9594.
*/
export function getChildInstances(vm, WrappedComponent) { export function getChildInstances(vm, WrappedComponent) {
return vm.$children.filter(child => child instanceof WrappedComponent); return vm.$children.filter(child => child instanceof WrappedComponent);
} }
......
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