debian-mirror-gitlab/spec/javascripts/pipelines/header_component_spec.js

109 lines
3 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
import headerComponent from '~/pipelines/components/header_component.vue';
import eventHub from '~/pipelines/event_hub';
describe('Pipeline details header', () => {
let HeaderComponent;
let vm;
let props;
beforeEach(() => {
2020-03-09 13:42:32 +05:30
spyOn(eventHub, '$emit');
2017-09-10 17:25:29 +05:30
HeaderComponent = Vue.extend(headerComponent);
const threeWeeksAgo = new Date();
threeWeeksAgo.setDate(threeWeeksAgo.getDate() - 21);
props = {
pipeline: {
details: {
status: {
group: 'failed',
2018-11-18 11:00:15 +05:30
icon: 'status_failed',
2017-09-10 17:25:29 +05:30
label: 'failed',
text: 'failed',
details_path: 'path',
},
},
id: 123,
created_at: threeWeeksAgo.toISOString(),
user: {
web_url: 'path',
name: 'Foo',
username: 'foobar',
email: 'foo@bar.com',
avatar_url: 'link',
},
2020-03-09 13:42:32 +05:30
retry_path: 'retry',
cancel_path: 'cancel',
delete_path: 'delete',
2017-09-10 17:25:29 +05:30
},
isLoading: false,
};
vm = new HeaderComponent({ propsData: props }).$mount();
});
afterEach(() => {
2020-03-09 13:42:32 +05:30
eventHub.$off();
2017-09-10 17:25:29 +05:30
vm.$destroy();
});
2020-03-09 13:42:32 +05:30
const findDeleteModal = () => document.getElementById(headerComponent.DELETE_MODAL_ID);
const findDeleteModalSubmit = () =>
[...findDeleteModal().querySelectorAll('.btn')].find(x => x.textContent === 'Delete pipeline');
2017-09-10 17:25:29 +05:30
it('should render provided pipeline info', () => {
expect(
2018-12-13 13:39:08 +05:30
vm.$el
.querySelector('.header-main-content')
.textContent.replace(/\s+/g, ' ')
.trim(),
).toContain('failed Pipeline #123 triggered 3 weeks ago by Foo');
2017-09-10 17:25:29 +05:30
});
describe('action buttons', () => {
2020-03-09 13:42:32 +05:30
it('should not trigger eventHub when nothing happens', () => {
expect(eventHub.$emit).not.toHaveBeenCalled();
});
it('should call postAction when retry button action is clicked', () => {
vm.$el.querySelector('.js-retry-button').click();
expect(eventHub.$emit).toHaveBeenCalledWith('headerPostAction', 'retry');
});
it('should call postAction when cancel button action is clicked', () => {
vm.$el.querySelector('.js-btn-cancel-pipeline').click();
expect(eventHub.$emit).toHaveBeenCalledWith('headerPostAction', 'cancel');
});
it('does not show delete modal', () => {
expect(findDeleteModal()).not.toBeVisible();
});
describe('when delete button action is clicked', () => {
beforeEach(done => {
vm.$el.querySelector('.js-btn-delete-pipeline').click();
// Modal needs two ticks to show
vm.$nextTick()
.then(() => vm.$nextTick())
.then(done)
.catch(done.fail);
2017-09-10 17:25:29 +05:30
});
2020-03-09 13:42:32 +05:30
it('should show delete modal', () => {
expect(findDeleteModal()).toBeVisible();
});
it('should call delete when modal is submitted', () => {
findDeleteModalSubmit().click();
expect(eventHub.$emit).toHaveBeenCalledWith('headerDeleteAction', 'delete');
});
2017-09-10 17:25:29 +05:30
});
});
});