2017-03-17 13:30:32 -04:00
|
|
|
import Vue from 'vue';
|
2019-08-05 09:51:08 -04:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2018-10-04 08:53:15 -04:00
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
|
|
|
import { TEST_HOST } from 'spec/test_constants';
|
2019-12-11 04:08:12 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import PipelinesActions from '~/pipelines/components/pipelines_actions.vue';
|
2017-03-17 13:30:32 -04:00
|
|
|
|
|
|
|
describe('Pipelines Actions dropdown', () => {
|
2018-10-04 08:53:15 -04:00
|
|
|
const Component = Vue.extend(PipelinesActions);
|
|
|
|
let vm;
|
2019-08-05 09:51:08 -04:00
|
|
|
let mock;
|
2017-03-17 13:30:32 -04:00
|
|
|
|
2018-10-04 08:53:15 -04:00
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
2019-08-05 09:51:08 -04:00
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
2018-10-04 08:53:15 -04:00
|
|
|
});
|
2017-03-17 13:30:32 -04:00
|
|
|
|
2018-10-04 08:53:15 -04:00
|
|
|
describe('manual actions', () => {
|
|
|
|
const actions = [
|
2017-03-17 13:30:32 -04:00
|
|
|
{
|
|
|
|
name: 'stop_review',
|
2018-10-04 08:53:15 -04:00
|
|
|
path: `${TEST_HOST}/root/review-app/builds/1893/play`,
|
2017-03-17 13:30:32 -04:00
|
|
|
},
|
2017-04-04 09:14:15 -04:00
|
|
|
{
|
|
|
|
name: 'foo',
|
2018-10-04 08:53:15 -04:00
|
|
|
path: `${TEST_HOST}/disabled/pipeline/action`,
|
2017-04-04 09:14:15 -04:00
|
|
|
playable: false,
|
|
|
|
},
|
2017-03-17 13:30:32 -04:00
|
|
|
];
|
|
|
|
|
2018-10-04 08:53:15 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
vm = mountComponent(Component, { actions });
|
|
|
|
});
|
2017-03-17 13:30:32 -04:00
|
|
|
|
2018-10-04 08:53:15 -04:00
|
|
|
it('renders a dropdown with the provided actions', () => {
|
|
|
|
const dropdownItems = vm.$el.querySelectorAll('.dropdown-menu li');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-04 08:53:15 -04:00
|
|
|
expect(dropdownItems.length).toEqual(actions.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders a disabled action when it's not playable", () => {
|
|
|
|
const dropdownItem = vm.$el.querySelector('.dropdown-menu li:last-child button');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-04 08:53:15 -04:00
|
|
|
expect(dropdownItem).toBeDisabled();
|
|
|
|
});
|
2019-08-05 09:51:08 -04:00
|
|
|
|
|
|
|
describe('on click', () => {
|
|
|
|
it('makes a request and toggles the loading state', done => {
|
|
|
|
mock.onPost(actions.path).reply(200);
|
|
|
|
|
|
|
|
vm.$el.querySelector('.dropdown-menu li button').click();
|
|
|
|
|
|
|
|
expect(vm.isLoading).toEqual(true);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(vm.isLoading).toEqual(false);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-17 13:30:32 -04:00
|
|
|
});
|
|
|
|
|
2018-10-04 08:53:15 -04:00
|
|
|
describe('scheduled jobs', () => {
|
|
|
|
const scheduledJobAction = {
|
|
|
|
name: 'scheduled action',
|
|
|
|
path: `${TEST_HOST}/scheduled/job/action`,
|
|
|
|
playable: true,
|
|
|
|
scheduled_at: '2063-04-05T00:42:00Z',
|
|
|
|
};
|
2018-10-05 03:34:08 -04:00
|
|
|
const expiredJobAction = {
|
|
|
|
name: 'expired action',
|
|
|
|
path: `${TEST_HOST}/expired/job/action`,
|
|
|
|
playable: true,
|
|
|
|
scheduled_at: '2018-10-05T08:23:00Z',
|
|
|
|
};
|
|
|
|
const findDropdownItem = action => {
|
|
|
|
const buttons = vm.$el.querySelectorAll('.dropdown-menu li button');
|
|
|
|
return Array.prototype.find.call(buttons, element =>
|
|
|
|
element.innerText.trim().startsWith(action.name),
|
|
|
|
);
|
|
|
|
};
|
2018-10-04 08:53:15 -04:00
|
|
|
|
2018-10-26 05:04:45 -04:00
|
|
|
beforeEach(done => {
|
2018-10-04 08:53:15 -04:00
|
|
|
spyOn(Date, 'now').and.callFake(() => new Date('2063-04-04T00:42:00Z').getTime());
|
2018-10-05 03:34:08 -04:00
|
|
|
vm = mountComponent(Component, { actions: [scheduledJobAction, expiredJobAction] });
|
2018-10-26 05:04:45 -04:00
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2018-10-04 08:53:15 -04:00
|
|
|
});
|
|
|
|
|
2019-08-05 09:51:08 -04:00
|
|
|
it('makes post request after confirming', done => {
|
|
|
|
mock.onPost(scheduledJobAction.path).reply(200);
|
2018-10-04 08:53:15 -04:00
|
|
|
spyOn(window, 'confirm').and.callFake(() => true);
|
|
|
|
|
2018-10-05 03:34:08 -04:00
|
|
|
findDropdownItem(scheduledJobAction).click();
|
2018-10-04 08:53:15 -04:00
|
|
|
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
2019-08-05 09:51:08 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(mock.history.post.length).toBe(1);
|
|
|
|
done();
|
|
|
|
});
|
2018-10-04 08:53:15 -04:00
|
|
|
});
|
|
|
|
|
2019-08-05 09:51:08 -04:00
|
|
|
it('does not make post request if confirmation is cancelled', () => {
|
|
|
|
mock.onPost(scheduledJobAction.path).reply(200);
|
2018-10-04 08:53:15 -04:00
|
|
|
spyOn(window, 'confirm').and.callFake(() => false);
|
|
|
|
|
2018-10-05 03:34:08 -04:00
|
|
|
findDropdownItem(scheduledJobAction).click();
|
2018-10-04 08:53:15 -04:00
|
|
|
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
2019-08-05 09:51:08 -04:00
|
|
|
expect(mock.history.post.length).toBe(0);
|
2018-10-04 08:53:15 -04:00
|
|
|
});
|
2017-04-04 09:14:15 -04:00
|
|
|
|
2018-10-04 08:53:15 -04:00
|
|
|
it('displays the remaining time in the dropdown', () => {
|
2018-10-05 03:34:08 -04:00
|
|
|
expect(findDropdownItem(scheduledJobAction)).toContainText('24:00:00');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays 00:00:00 for expired jobs in the dropdown', () => {
|
|
|
|
expect(findDropdownItem(expiredJobAction)).toContainText('00:00:00');
|
2018-10-04 08:53:15 -04:00
|
|
|
});
|
2017-04-04 09:14:15 -04:00
|
|
|
});
|
2017-03-17 13:30:32 -04:00
|
|
|
});
|