Commit fa3128b1 authored by David O'Regan's avatar David O'Regan

Merge branch 'nicolasdular/refactor-ci-empty-state-spec' into 'master'

Refactor pipeline empty state specs

See merge request gitlab-org/gitlab!48603
parents 3f41b08e 9b1c0308
...@@ -29,11 +29,13 @@ export default { ...@@ -29,11 +29,13 @@ export default {
</div> </div>
<div class="col-12"> <div class="col-12">
<div class="text-content"> <div class="gl-text-content">
<template v-if="canSetCi"> <template v-if="canSetCi">
<h4 class="text-center">{{ s__('Pipelines|Build with confidence') }}</h4> <h4 class="gl-text-center" data-testid="header-text">
{{ s__('Pipelines|Build with confidence') }}
</h4>
<p> <p data-testid="info-text">
{{ {{
s__(`Pipelines|Continuous Integration can help s__(`Pipelines|Continuous Integration can help
catch bugs by running your tests automatically, catch bugs by running your tests automatically,
...@@ -42,12 +44,11 @@ export default { ...@@ -42,12 +44,11 @@ export default {
}} }}
</p> </p>
<div class="text-center"> <div class="gl-text-center">
<gl-button <gl-button
:href="helpPagePath" :href="helpPagePath"
variant="info" variant="info"
category="primary" category="primary"
class="js-get-started-pipelines"
data-testid="get-started-pipelines" data-testid="get-started-pipelines"
> >
{{ s__('Pipelines|Get started with Pipelines') }} {{ s__('Pipelines|Get started with Pipelines') }}
...@@ -55,7 +56,7 @@ export default { ...@@ -55,7 +56,7 @@ export default {
</div> </div>
</template> </template>
<p v-else class="text-center"> <p v-else class="gl-text-center">
{{ s__('Pipelines|This project is not currently set up to run pipelines.') }} {{ s__('Pipelines|This project is not currently set up to run pipelines.') }}
</p> </p>
</div> </div>
......
import Vue from 'vue'; import { shallowMount } from '@vue/test-utils';
import emptyStateComp from '~/pipelines/components/pipelines_list/empty_state.vue'; import EmptyState from '~/pipelines/components/pipelines_list/empty_state.vue';
import mountComponent from '../helpers/vue_mount_component_helper';
describe('Pipelines Empty State', () => { describe('Pipelines Empty State', () => {
let component; let wrapper;
let EmptyStateComponent;
const findGetStartedButton = () => wrapper.find('[data-testid="get-started-pipelines"]');
const findInfoText = () => wrapper.find('[data-testid="info-text"]').text();
const createWrapper = () => {
wrapper = shallowMount(EmptyState, {
propsData: {
helpPagePath: 'foo',
emptyStateSvgPath: 'foo',
canSetCi: true,
},
});
};
beforeEach(() => { describe('renders', () => {
EmptyStateComponent = Vue.extend(emptyStateComp); beforeEach(() => {
createWrapper();
});
component = mountComponent(EmptyStateComponent, { afterEach(() => {
helpPagePath: 'foo', wrapper.destroy();
emptyStateSvgPath: 'foo', wrapper = null;
canSetCi: true,
}); });
});
afterEach(() => { it('should render empty state SVG', () => {
component.$destroy(); expect(wrapper.find('img').attributes('src')).toBe('foo');
}); });
it('should render empty state SVG', () => { it('should render empty state header', () => {
expect(component.$el.querySelector('.svg-content svg')).toBeDefined(); expect(wrapper.find('[data-testid="header-text"]').text()).toBe('Build with confidence');
}); });
it('should render empty state information', () => { it('should render a link with provided help path', () => {
expect(component.$el.querySelector('h4').textContent).toContain('Build with confidence'); expect(findGetStartedButton().attributes('href')).toBe('foo');
});
expect(
component.$el
.querySelector('p')
.innerHTML.trim()
.replace(/\n+\s+/m, ' ')
.replace(/\s\s+/g, ' '),
).toContain('Continuous Integration can help catch bugs by running your tests automatically,');
expect(
component.$el
.querySelector('p')
.innerHTML.trim()
.replace(/\n+\s+/m, ' ')
.replace(/\s\s+/g, ' '),
).toContain(
'while Continuous Deployment can help you deliver code to your product environment',
);
});
it('should render a link with provided help path', () => { it('should render empty state information', () => {
expect(component.$el.querySelector('.js-get-started-pipelines').getAttribute('href')).toEqual( expect(findInfoText()).toContain(
'foo', 'Continuous Integration can help catch bugs by running your tests automatically',
); 'while Continuous Deployment can help you deliver code to your product environment',
);
});
expect(component.$el.querySelector('.js-get-started-pipelines').textContent).toContain( it('should render a button', () => {
'Get started with Pipelines', expect(findGetStartedButton().text()).toBe('Get started with Pipelines');
); });
}); });
}); });
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