diff --git a/app/assets/javascripts/ide/components/ide_project_header.vue b/app/assets/javascripts/ide/components/ide_project_header.vue index 2d8a171661adcbd0dc7815ee32ed51e95f7fd74a..1c25a8e634d7ae4ccca33ee089a17694fb323545 100644 --- a/app/assets/javascripts/ide/components/ide_project_header.vue +++ b/app/assets/javascripts/ide/components/ide_project_header.vue @@ -16,7 +16,7 @@ export default { <template> <div class="context-header ide-context-header"> - <a :href="project.web_url" :title="s__('IDE|Go to project')"> + <a :href="project.web_url" :title="s__('IDE|Go to project')" data-testid="go-to-project-link"> <project-avatar :project-name="project.name" :project-avatar-url="project.avatar_url" diff --git a/spec/frontend/ide/components/ide_project_header_spec.js b/spec/frontend/ide/components/ide_project_header_spec.js new file mode 100644 index 0000000000000000000000000000000000000000..fc39651c661fa5aaafc2db57545f0b2e7fa577ec --- /dev/null +++ b/spec/frontend/ide/components/ide_project_header_spec.js @@ -0,0 +1,44 @@ +import { shallowMount } from '@vue/test-utils'; +import IDEProjectHeader from '~/ide/components/ide_project_header.vue'; +import ProjectAvatar from '~/vue_shared/components/project_avatar.vue'; + +const mockProject = { + name: 'test proj', + avatar_url: 'https://gitlab.com', + path_with_namespace: 'path/with-namespace', + web_url: 'https://gitlab.com/project', +}; + +describe('IDE project header', () => { + let wrapper; + + const findProjectAvatar = () => wrapper.findComponent(ProjectAvatar); + const findProjectLink = () => wrapper.find('[data-testid="go-to-project-link"'); + + const createComponent = () => { + wrapper = shallowMount(IDEProjectHeader, { propsData: { project: mockProject } }); + }; + + afterEach(() => { + wrapper.destroy(); + }); + + describe('template', () => { + beforeEach(() => { + createComponent(); + }); + + it('renders ProjectAvatar with correct props', () => { + expect(findProjectAvatar().props()).toMatchObject({ + projectName: mockProject.name, + projectAvatarUrl: mockProject.avatar_url, + }); + }); + + it('renders a link to the project URL', () => { + const link = findProjectLink(); + expect(link.exists()).toBe(true); + expect(link.attributes('href')).toBe(mockProject.web_url); + }); + }); +});