Commit 8d2e3a28 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'pb-resolve-tech-debt-sidebar-detail-row' into 'master'

Refactor sidebar detail row and spec

See merge request gitlab-org/gitlab!53411
parents 9d7837f5 c355ebf5
...@@ -34,12 +34,12 @@ export default { ...@@ -34,12 +34,12 @@ export default {
}; };
</script> </script>
<template> <template>
<p class="build-detail-row"> <p class="gl-display-flex gl-justify-content-space-between gl-mb-2">
<span v-if="hasTitle" class="font-weight-bold">{{ title }}:</span> {{ value }} <span v-if="hasTitle"
<span v-if="hasHelpURL" class="help-button float-right"> ><b>{{ title }}:</b> {{ value }}</span
<gl-link :href="helpUrl" target="_blank" rel="noopener noreferrer nofollow"> >
<gl-icon name="question-o" /> <gl-link v-if="hasHelpURL" :href="helpUrl" target="_blank">
</gl-link> <gl-icon name="question-o" />
</span> </gl-link>
</p> </p>
</template> </template>
import Vue from 'vue'; import { shallowMount } from '@vue/test-utils';
import sidebarDetailRow from '~/jobs/components/sidebar_detail_row.vue'; import { GlLink } from '@gitlab/ui';
import SidebarDetailRow from '~/jobs/components/sidebar_detail_row.vue';
describe('Sidebar detail row', () => { describe('Sidebar detail row', () => {
let SidebarDetailRow; let wrapper;
let vm;
beforeEach(() => { const title = 'this is the title';
SidebarDetailRow = Vue.extend(sidebarDetailRow); const value = 'this is the value';
}); const helpUrl = '/help/ci/runners/README.html';
afterEach(() => { const findHelpLink = () => wrapper.findComponent(GlLink);
vm.$destroy();
});
it('should render no title', () => { const createComponent = (props) => {
vm = new SidebarDetailRow({ wrapper = shallowMount(SidebarDetailRow, {
propsData: { propsData: {
value: 'this is the value', ...props,
}, },
}).$mount(); });
};
expect(vm.$el.textContent.replace(/\s+/g, ' ').trim()).toEqual('this is the value'); afterEach(() => {
wrapper.destroy();
wrapper = null;
}); });
beforeEach(() => { describe('with title/value and without helpUrl', () => {
vm = new SidebarDetailRow({ beforeEach(() => {
propsData: { createComponent({ title, value });
title: 'this is the title', });
value: 'this is the value',
},
}).$mount();
});
it('should render provided title and value', () => { it('should render the provided title and value', () => {
expect(vm.$el.textContent.replace(/\s+/g, ' ').trim()).toEqual( expect(wrapper.text()).toBe(`${title}: ${value}`);
'this is the title: this is the value', });
);
});
describe('when helpUrl not provided', () => { it('should not render the help link', () => {
it('should not render help', () => { expect(findHelpLink().exists()).toBe(false);
expect(vm.$el.querySelector('.help-button')).toBeNull();
}); });
}); });
describe('when helpUrl provided', () => { describe('when helpUrl provided', () => {
beforeEach(() => { beforeEach(() => {
vm = new SidebarDetailRow({ createComponent({
propsData: { helpUrl,
helpUrl: 'help url', title,
value: 'foo', value,
}, });
}).$mount();
}); });
it('should render help', () => { it('should render the help link', () => {
expect(vm.$el.querySelector('.help-button a').getAttribute('href')).toEqual('help url'); expect(findHelpLink().exists()).toBe(true);
expect(findHelpLink().attributes('href')).toBe(helpUrl);
}); });
}); });
}); });
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