2017-03-13 20:58:26 -04:00
|
|
|
import Vue from 'vue';
|
2018-10-09 13:54:16 -04:00
|
|
|
import eventHub from '~/environments/event_hub';
|
|
|
|
import EnvironmentActions from '~/environments/components/environment_actions.vue';
|
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
|
|
|
import { TEST_HOST } from 'spec/test_constants';
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2018-10-09 13:54:16 -04:00
|
|
|
describe('EnvironmentActions Component', () => {
|
|
|
|
const Component = Vue.extend(EnvironmentActions);
|
|
|
|
let vm;
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2018-10-09 13:54:16 -04:00
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2018-10-09 13:54:16 -04:00
|
|
|
describe('manual actions', () => {
|
|
|
|
const actions = [
|
2016-11-10 13:58:35 -05:00
|
|
|
{
|
|
|
|
name: 'bar',
|
2016-11-18 14:40:47 -05:00
|
|
|
play_path: 'https://gitlab.com/play',
|
2016-11-10 13:58:35 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'foo',
|
2016-11-18 14:40:47 -05:00
|
|
|
play_path: '#',
|
2016-11-10 13:58:35 -05:00
|
|
|
},
|
2017-04-04 09:14:15 -04:00
|
|
|
{
|
|
|
|
name: 'foo bar',
|
|
|
|
play_path: 'url',
|
|
|
|
playable: false,
|
|
|
|
},
|
2016-11-10 13:58:35 -05:00
|
|
|
];
|
|
|
|
|
2018-10-09 13:54:16 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
vm = mountComponent(Component, { actions });
|
|
|
|
});
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2018-10-09 13:54:16 -04:00
|
|
|
it('should render a dropdown button with icon and title attribute', () => {
|
|
|
|
expect(vm.$el.querySelector('.fa-caret-down')).toBeDefined();
|
|
|
|
expect(vm.$el.querySelector('.dropdown-new').getAttribute('data-original-title')).toEqual(
|
|
|
|
'Deploy to...',
|
|
|
|
);
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2018-10-09 13:54:16 -04:00
|
|
|
expect(vm.$el.querySelector('.dropdown-new').getAttribute('aria-label')).toEqual(
|
|
|
|
'Deploy to...',
|
|
|
|
);
|
2017-06-06 16:46:31 -04:00
|
|
|
});
|
|
|
|
|
2018-10-09 13:54:16 -04:00
|
|
|
it('should render a dropdown with the provided list of actions', () => {
|
|
|
|
expect(vm.$el.querySelectorAll('.dropdown-menu li').length).toEqual(actions.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should render a disabled action when it's not playable", () => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelector('.dropdown-menu li:last-child button').getAttribute('disabled'),
|
|
|
|
).toEqual('disabled');
|
2017-03-31 05:20:11 -04:00
|
|
|
|
2018-10-09 13:54:16 -04:00
|
|
|
expect(
|
|
|
|
vm.$el.querySelector('.dropdown-menu li:last-child button').classList.contains('disabled'),
|
|
|
|
).toEqual(true);
|
|
|
|
});
|
2017-03-13 20:58:26 -04:00
|
|
|
});
|
|
|
|
|
2018-10-09 13:54:16 -04:00
|
|
|
describe('scheduled jobs', () => {
|
|
|
|
const scheduledJobAction = {
|
|
|
|
name: 'scheduled action',
|
|
|
|
playPath: `${TEST_HOST}/scheduled/job/action`,
|
|
|
|
playable: true,
|
|
|
|
scheduledAt: '2063-04-05T00:42:00Z',
|
|
|
|
};
|
|
|
|
const expiredJobAction = {
|
|
|
|
name: 'expired action',
|
|
|
|
playPath: `${TEST_HOST}/expired/job/action`,
|
|
|
|
playable: true,
|
|
|
|
scheduledAt: '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),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(Date, 'now').and.callFake(() => new Date('2063-04-04T00:42:00Z').getTime());
|
|
|
|
vm = mountComponent(Component, { actions: [scheduledJobAction, expiredJobAction] });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('emits postAction event after confirming', () => {
|
|
|
|
const emitSpy = jasmine.createSpy('emit');
|
|
|
|
eventHub.$on('postAction', emitSpy);
|
|
|
|
spyOn(window, 'confirm').and.callFake(() => true);
|
|
|
|
|
|
|
|
findDropdownItem(scheduledJobAction).click();
|
|
|
|
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
expect(emitSpy).toHaveBeenCalledWith({ endpoint: scheduledJobAction.playPath });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not emit postAction event if confirmation is cancelled', () => {
|
|
|
|
const emitSpy = jasmine.createSpy('emit');
|
|
|
|
eventHub.$on('postAction', emitSpy);
|
|
|
|
spyOn(window, 'confirm').and.callFake(() => false);
|
|
|
|
|
|
|
|
findDropdownItem(scheduledJobAction).click();
|
2017-04-04 09:14:15 -04:00
|
|
|
|
2018-10-09 13:54:16 -04:00
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
expect(emitSpy).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the remaining time in the dropdown', () => {
|
|
|
|
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');
|
|
|
|
});
|
2017-04-04 09:14:15 -04:00
|
|
|
});
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|