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

137 lines
3.8 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import Vue from 'vue';
2018-10-15 14:42:47 +05:30
import MockAdapter from 'axios-mock-adapter';
2020-01-01 13:55:28 +05:30
import mountComponent from 'spec/helpers/vue_mount_component_helper';
2018-10-15 14:42:47 +05:30
import axios from '~/lib/utils/axios_utils';
2017-08-17 22:00:37 +05:30
import stage from '~/pipelines/components/stage.vue';
2018-10-15 14:42:47 +05:30
import eventHub from '~/pipelines/event_hub';
import { stageReply } from './mock_data';
2017-08-17 22:00:37 +05:30
describe('Pipelines stage component', () => {
let StageComponent;
let component;
2018-10-15 14:42:47 +05:30
let mock;
2017-08-17 22:00:37 +05:30
beforeEach(() => {
2018-10-15 14:42:47 +05:30
mock = new MockAdapter(axios);
2017-08-17 22:00:37 +05:30
StageComponent = Vue.extend(stage);
2018-10-15 14:42:47 +05:30
component = mountComponent(StageComponent, {
stage: {
status: {
group: 'success',
2018-11-18 11:00:15 +05:30
icon: 'status_success',
2018-10-15 14:42:47 +05:30
title: 'success',
2017-08-17 22:00:37 +05:30
},
2018-10-15 14:42:47 +05:30
dropdown_path: 'path.json',
2017-08-17 22:00:37 +05:30
},
2018-10-15 14:42:47 +05:30
updateDropdown: false,
});
});
afterEach(() => {
component.$destroy();
mock.restore();
2017-08-17 22:00:37 +05:30
});
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');
});
2018-12-13 13:39:08 +05:30
describe('with successful request', () => {
2017-08-17 22:00:37 +05:30
beforeEach(() => {
2018-10-15 14:42:47 +05:30
mock.onGet('path.json').reply(200, stageReply);
2017-08-17 22:00:37 +05:30
});
2018-10-15 14:42:47 +05:30
it('should render the received data and emit `clickedDropdown` event', done => {
spyOn(eventHub, '$emit');
2017-08-17 22:00:37 +05:30
component.$el.querySelector('button').click();
setTimeout(() => {
expect(
component.$el.querySelector('.js-builds-dropdown-container ul').textContent.trim(),
2018-10-15 14:42:47 +05:30
).toContain(stageReply.latest_statuses[0].name);
2018-12-13 13:39:08 +05:30
2018-10-15 14:42:47 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith('clickedDropdown');
2017-08-17 22:00:37 +05:30
done();
}, 0);
});
});
describe('when request fails', () => {
beforeEach(() => {
2018-10-15 14:42:47 +05:30
mock.onGet('path.json').reply(500);
2017-08-17 22:00:37 +05:30
});
it('should close the dropdown', () => {
component.$el.click();
setTimeout(() => {
expect(component.$el.classList.contains('open')).toEqual(false);
}, 0);
});
});
2017-09-10 17:25:29 +05:30
describe('update endpoint correctly', () => {
beforeEach(() => {
2018-10-15 14:42:47 +05:30
const copyStage = Object.assign({}, stageReply);
copyStage.latest_statuses[0].name = 'this is the updated content';
mock.onGet('bar.json').reply(200, copyStage);
2017-09-10 17:25:29 +05:30
});
2018-10-15 14:42:47 +05:30
it('should update the stage to request the new endpoint provided', done => {
2017-09-10 17:25:29 +05:30
component.stage = {
status: {
group: 'running',
2018-11-18 11:00:15 +05:30
icon: 'status_running',
2017-09-10 17:25:29 +05:30
title: 'running',
},
2018-10-15 14:42:47 +05:30
dropdown_path: 'bar.json',
2017-09-10 17:25:29 +05:30
};
Vue.nextTick(() => {
component.$el.querySelector('button').click();
setTimeout(() => {
expect(
component.$el.querySelector('.js-builds-dropdown-container ul').textContent.trim(),
2018-10-15 14:42:47 +05:30
).toContain('this is the updated content');
2017-09-10 17:25:29 +05:30
done();
});
});
});
});
2018-10-15 14:42:47 +05:30
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', () => {
it('emits `refreshPipelinesTable` event when `pipelineActionRequestComplete` is triggered', done => {
spyOn(eventHub, '$emit');
component.type = 'PIPELINES_TABLE';
component.$el.querySelector('button').click();
setTimeout(() => {
component.$el.querySelector('.js-ci-action').click();
2019-07-07 11:18:12 +05:30
setTimeout(() => {
component
.$nextTick()
.then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith('refreshPipelinesTable');
})
.then(done)
.catch(done.fail);
}, 0);
2018-10-15 14:42:47 +05:30
}, 0);
});
});
});
2017-08-17 22:00:37 +05:30
});