2017-04-18 18:30:05 +00:00
|
|
|
import Vue from 'vue';
|
2018-04-10 14:31:53 +00:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-05-04 13:11:48 +00:00
|
|
|
import stage from '~/pipelines/components/stage.vue';
|
2018-04-11 13:12:10 +00:00
|
|
|
import eventHub from '~/pipelines/event_hub';
|
2018-04-10 14:31:53 +00:00
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2018-04-24 16:35:44 +00:00
|
|
|
import { stageReply } from './mock_data';
|
2017-05-04 13:11:48 +00:00
|
|
|
|
|
|
|
describe('Pipelines stage component', () => {
|
|
|
|
let StageComponent;
|
|
|
|
let component;
|
2018-04-10 14:31:53 +00:00
|
|
|
let mock;
|
2017-05-04 13:11:48 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-04-10 14:31:53 +00:00
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
|
2017-05-04 13:11:48 +00:00
|
|
|
StageComponent = Vue.extend(stage);
|
|
|
|
|
2018-04-10 14:31:53 +00:00
|
|
|
component = mountComponent(StageComponent, {
|
|
|
|
stage: {
|
|
|
|
status: {
|
|
|
|
group: 'success',
|
2018-07-18 16:56:19 +00:00
|
|
|
icon: 'status_success',
|
2018-04-10 14:31:53 +00:00
|
|
|
title: 'success',
|
2017-05-04 13:11:48 +00:00
|
|
|
},
|
2018-04-10 14:31:53 +00:00
|
|
|
dropdown_path: 'path.json',
|
2017-05-04 13:11:48 +00:00
|
|
|
},
|
2018-04-10 14:31:53 +00:00
|
|
|
updateDropdown: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
component.$destroy();
|
|
|
|
mock.restore();
|
2017-05-04 13:11:48 +00:00
|
|
|
});
|
2017-04-18 18:30:05 +00:00
|
|
|
|
2017-05-04 13:11:48 +00:00
|
|
|
it('should render a dropdown with the status icon', () => {
|
|
|
|
expect(component.$el.getAttribute('class')).toEqual('dropdown');
|
|
|
|
expect(component.$el.querySelector('svg')).toBeDefined();
|
|
|
|
expect(component.$el.querySelector('button').getAttribute('data-toggle')).toEqual('dropdown');
|
|
|
|
});
|
2017-04-18 18:30:05 +00:00
|
|
|
|
2017-05-04 13:11:48 +00:00
|
|
|
describe('with successfull request', () => {
|
2017-04-18 18:30:05 +00:00
|
|
|
beforeEach(() => {
|
2018-04-24 16:35:44 +00:00
|
|
|
mock.onGet('path.json').reply(200, stageReply);
|
2017-04-18 18:30:05 +00:00
|
|
|
});
|
|
|
|
|
2018-04-11 13:12:10 +00:00
|
|
|
it('should render the received data and emit `clickedDropdown` event', done => {
|
|
|
|
spyOn(eventHub, '$emit');
|
2017-05-04 13:11:48 +00:00
|
|
|
component.$el.querySelector('button').click();
|
2017-04-18 18:30:05 +00:00
|
|
|
|
2017-05-04 13:11:48 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
component.$el.querySelector('.js-builds-dropdown-container ul').textContent.trim(),
|
2018-04-24 16:35:44 +00:00
|
|
|
).toContain(stageReply.latest_statuses[0].name);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2018-04-11 13:12:10 +00:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('clickedDropdown');
|
2017-05-04 13:11:48 +00:00
|
|
|
done();
|
|
|
|
}, 0);
|
2017-04-18 18:30:05 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-04 13:11:48 +00:00
|
|
|
describe('when request fails', () => {
|
2017-04-18 18:30:05 +00:00
|
|
|
beforeEach(() => {
|
2018-04-10 14:31:53 +00:00
|
|
|
mock.onGet('path.json').reply(500);
|
2017-04-18 18:30:05 +00:00
|
|
|
});
|
2017-04-26 16:37:54 +00:00
|
|
|
|
2017-05-04 13:11:48 +00:00
|
|
|
it('should close the dropdown', () => {
|
|
|
|
component.$el.click();
|
2017-04-26 16:37:54 +00:00
|
|
|
|
2017-05-04 13:11:48 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(component.$el.classList.contains('open')).toEqual(false);
|
|
|
|
}, 0);
|
2017-04-26 16:37:54 +00:00
|
|
|
});
|
|
|
|
});
|
2017-06-26 16:50:58 +00:00
|
|
|
|
|
|
|
describe('update endpoint correctly', () => {
|
|
|
|
beforeEach(() => {
|
2018-04-24 16:35:44 +00:00
|
|
|
const copyStage = Object.assign({}, stageReply);
|
|
|
|
copyStage.latest_statuses[0].name = 'this is the updated content';
|
|
|
|
mock.onGet('bar.json').reply(200, copyStage);
|
2017-06-26 16:50:58 +00:00
|
|
|
});
|
|
|
|
|
2018-04-10 14:31:53 +00:00
|
|
|
it('should update the stage to request the new endpoint provided', done => {
|
2017-06-26 16:50:58 +00:00
|
|
|
component.stage = {
|
|
|
|
status: {
|
|
|
|
group: 'running',
|
2018-07-18 16:56:19 +00:00
|
|
|
icon: 'status_running',
|
2017-06-26 16:50:58 +00:00
|
|
|
title: 'running',
|
|
|
|
},
|
2018-04-10 14:31:53 +00:00
|
|
|
dropdown_path: 'bar.json',
|
2017-06-26 16:50:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
component.$el.querySelector('button').click();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
component.$el.querySelector('.js-builds-dropdown-container ul').textContent.trim(),
|
2018-04-24 16:35:44 +00:00
|
|
|
).toContain('this is the updated content');
|
2017-06-26 16:50:58 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-15 15:55:07 +00:00
|
|
|
|
|
|
|
describe('pipelineActionRequestComplete', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mock.onGet('path.json').reply(200, stageReply);
|
|
|
|
|
|
|
|
mock.onPost(`${stageReply.latest_statuses[0].status.action.path}.json`).reply(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('within pipeline table', () => {
|
2018-05-16 11:24:59 +00:00
|
|
|
it('emits `refreshPipelinesTable` event when `pipelineActionRequestComplete` is triggered', done => {
|
2018-05-15 15:55:07 +00:00
|
|
|
spyOn(eventHub, '$emit');
|
|
|
|
|
|
|
|
component.type = 'PIPELINES_TABLE';
|
|
|
|
component.$el.querySelector('button').click();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
component.$el.querySelector('.js-ci-action').click();
|
2018-10-17 07:13:26 +00:00
|
|
|
component
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('refreshPipelinesTable');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2018-05-15 15:55:07 +00:00
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-04-18 18:30:05 +00:00
|
|
|
});
|