diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 07:33:21 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 07:33:21 +0000 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/frontend/reports/components/report_link_spec.js | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) | |
download | gitlab-ce-15.0.0-rc42.tar.gz |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/frontend/reports/components/report_link_spec.js')
-rw-r--r-- | spec/frontend/reports/components/report_link_spec.js | 81 |
1 files changed, 34 insertions, 47 deletions
diff --git a/spec/frontend/reports/components/report_link_spec.js b/spec/frontend/reports/components/report_link_spec.js index fc21515ded6..2ed0617a598 100644 --- a/spec/frontend/reports/components/report_link_spec.js +++ b/spec/frontend/reports/components/report_link_spec.js @@ -1,69 +1,56 @@ -import Vue from 'vue'; -import mountComponent from 'helpers/vue_mount_component_helper'; -import component from '~/reports/components/report_link.vue'; +import { shallowMount } from '@vue/test-utils'; +import ReportLink from '~/reports/components/report_link.vue'; -describe('report link', () => { - let vm; - - const Component = Vue.extend(component); +describe('app/assets/javascripts/reports/components/report_link.vue', () => { + let wrapper; afterEach(() => { - vm.$destroy(); + wrapper.destroy(); }); - describe('With url', () => { - it('renders link', () => { - vm = mountComponent(Component, { - issue: { - path: 'Gemfile.lock', - urlPath: '/Gemfile.lock', - }, - }); + const defaultProps = { + issue: {}, + }; + + const createComponent = (props = {}) => { + wrapper = shallowMount(ReportLink, { + propsData: { ...defaultProps, ...props }, + }); + }; + + describe('When an issue prop has a $urlPath property', () => { + it('render a link that will take the user to the $urlPath', () => { + createComponent({ issue: { path: 'Gemfile.lock', urlPath: '/Gemfile.lock' } }); - expect(vm.$el.textContent.trim()).toContain('in'); - expect(vm.$el.querySelector('a').getAttribute('href')).toEqual('/Gemfile.lock'); - expect(vm.$el.querySelector('a').textContent.trim()).toEqual('Gemfile.lock'); + expect(wrapper.text()).toContain('in'); + expect(wrapper.find('a').attributes('href')).toBe('/Gemfile.lock'); + expect(wrapper.find('a').text()).toContain('Gemfile.lock'); }); }); - describe('Without url', () => { + describe('When an issue prop has no $urlPath property', () => { it('does not render link', () => { - vm = mountComponent(Component, { - issue: { - path: 'Gemfile.lock', - }, - }); + createComponent({ issue: { path: 'Gemfile.lock' } }); - expect(vm.$el.querySelector('a')).toBeNull(); - expect(vm.$el.textContent.trim()).toContain('in'); - expect(vm.$el.textContent.trim()).toContain('Gemfile.lock'); + expect(wrapper.find('a').exists()).toBe(false); + expect(wrapper.text()).toContain('in'); + expect(wrapper.text()).toContain('Gemfile.lock'); }); }); - describe('with line', () => { - it('renders line number', () => { - vm = mountComponent(Component, { - issue: { - path: 'Gemfile.lock', - urlPath: 'https://groups.google.com/forum/#!topic/rubyonrails-security/335P1DcLG00', - line: 22, - }, - }); + describe('When an issue prop has a $line property', () => { + it('render a line number', () => { + createComponent({ issue: { path: 'Gemfile.lock', urlPath: '/Gemfile.lock', line: 22 } }); - expect(vm.$el.querySelector('a').textContent.trim()).toContain('Gemfile.lock:22'); + expect(wrapper.find('a').text()).toContain('Gemfile.lock:22'); }); }); - describe('without line', () => { - it('does not render line number', () => { - vm = mountComponent(Component, { - issue: { - path: 'Gemfile.lock', - urlPath: 'https://groups.google.com/forum/#!topic/rubyonrails-security/335P1DcLG00', - }, - }); + describe('When an issue prop does not have a $line property', () => { + it('does not render a line number', () => { + createComponent({ issue: { urlPath: '/Gemfile.lock' } }); - expect(vm.$el.querySelector('a').textContent.trim()).not.toContain(':22'); + expect(wrapper.find('a').text()).not.toContain(':22'); }); }); }); |