2017-03-13 20:58:26 -04:00
|
|
|
import Vue from 'vue';
|
2019-03-05 13:33:10 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import { GlButton } from '@gitlab/ui';
|
|
|
|
import eventHub from '~/environments/event_hub';
|
2017-04-20 07:48:54 -04:00
|
|
|
import rollbackComp from '~/environments/components/environment_rollback.vue';
|
2016-12-29 16:42:48 -05:00
|
|
|
|
2016-11-10 13:58:35 -05:00
|
|
|
describe('Rollback Component', () => {
|
2019-03-05 13:33:10 -05:00
|
|
|
const retryUrl = 'https://gitlab.com/retry';
|
2017-03-13 20:58:26 -04:00
|
|
|
let RollbackComponent;
|
2016-11-10 13:58:35 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-03-13 20:58:26 -04:00
|
|
|
RollbackComponent = Vue.extend(rollbackComp);
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
|
2017-03-13 20:58:26 -04:00
|
|
|
it('Should render Re-deploy label when isLastDeployment is true', () => {
|
2017-02-09 06:52:22 -05:00
|
|
|
const component = new RollbackComponent({
|
2016-11-10 13:58:35 -05:00
|
|
|
el: document.querySelector('.test-dom-element'),
|
|
|
|
propsData: {
|
2019-03-05 13:33:10 -05:00
|
|
|
retryUrl,
|
2016-12-08 06:54:08 -05:00
|
|
|
isLastDeployment: true,
|
2019-03-05 13:33:10 -05:00
|
|
|
environment: {},
|
2016-11-10 13:58:35 -05:00
|
|
|
},
|
2017-03-13 20:58:26 -04:00
|
|
|
}).$mount();
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2018-07-10 04:11:04 -04:00
|
|
|
expect(component.$el).toHaveSpriteIcon('repeat');
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
|
2017-03-13 20:58:26 -04:00
|
|
|
it('Should render Rollback label when isLastDeployment is false', () => {
|
2017-02-09 06:52:22 -05:00
|
|
|
const component = new RollbackComponent({
|
2016-11-10 13:58:35 -05:00
|
|
|
el: document.querySelector('.test-dom-element'),
|
|
|
|
propsData: {
|
2019-03-05 13:33:10 -05:00
|
|
|
retryUrl,
|
2017-03-13 20:58:26 -04:00
|
|
|
isLastDeployment: false,
|
2019-03-05 13:33:10 -05:00
|
|
|
environment: {},
|
2016-11-10 13:58:35 -05:00
|
|
|
},
|
2017-03-13 20:58:26 -04:00
|
|
|
}).$mount();
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2018-07-10 04:11:04 -04:00
|
|
|
expect(component.$el).toHaveSpriteIcon('redo');
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
2019-03-05 13:33:10 -05:00
|
|
|
|
|
|
|
it('should emit a "rollback" event on button click', () => {
|
|
|
|
const eventHubSpy = spyOn(eventHub, '$emit');
|
|
|
|
const component = shallowMount(RollbackComponent, {
|
|
|
|
propsData: {
|
|
|
|
retryUrl,
|
|
|
|
environment: {
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const button = component.find(GlButton);
|
|
|
|
|
|
|
|
button.vm.$emit('click');
|
|
|
|
|
|
|
|
expect(eventHubSpy).toHaveBeenCalledWith('requestRollbackEnvironment', {
|
|
|
|
retryUrl,
|
|
|
|
isLastDeployment: true,
|
|
|
|
name: 'test',
|
|
|
|
});
|
|
|
|
});
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|