2022-01-26 12:08:38 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2021-11-18 22:05:49 +05:30
|
|
|
import { GlDropdownItem } from '@gitlab/ui';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2019-10-12 21:52:04 +05:30
|
|
|
import RollbackComponent from '~/environments/components/environment_rollback.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import eventHub from '~/environments/event_hub';
|
2022-01-26 12:08:38 +05:30
|
|
|
import setEnvironmentToRollback from '~/environments/graphql/mutations/set_environment_to_rollback.mutation.graphql';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe('Rollback Component', () => {
|
2019-07-07 11:18:12 +05:30
|
|
|
const retryUrl = 'https://gitlab.com/retry';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
it('Should render Re-deploy label when isLastDeployment is true', () => {
|
2021-11-18 22:05:49 +05:30
|
|
|
const wrapper = shallowMount(RollbackComponent, {
|
2017-08-17 22:00:37 +05:30
|
|
|
propsData: {
|
2019-07-07 11:18:12 +05:30
|
|
|
retryUrl,
|
2017-08-17 22:00:37 +05:30
|
|
|
isLastDeployment: true,
|
2019-07-07 11:18:12 +05:30
|
|
|
environment: {},
|
2017-08-17 22:00:37 +05:30
|
|
|
},
|
2019-10-12 21:52:04 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(wrapper.text()).toBe('Re-deploy to environment');
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('Should render Rollback label when isLastDeployment is false', () => {
|
2021-11-18 22:05:49 +05:30
|
|
|
const wrapper = shallowMount(RollbackComponent, {
|
2017-08-17 22:00:37 +05:30
|
|
|
propsData: {
|
2019-07-07 11:18:12 +05:30
|
|
|
retryUrl,
|
2017-08-17 22:00:37 +05:30
|
|
|
isLastDeployment: false,
|
2019-07-07 11:18:12 +05:30
|
|
|
environment: {},
|
2017-08-17 22:00:37 +05:30
|
|
|
},
|
2019-10-12 21:52:04 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(wrapper.text()).toBe('Rollback environment');
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
it('should emit a "rollback" event on button click', () => {
|
2019-10-12 21:52:04 +05:30
|
|
|
const eventHubSpy = jest.spyOn(eventHub, '$emit');
|
|
|
|
const wrapper = shallowMount(RollbackComponent, {
|
2019-07-07 11:18:12 +05:30
|
|
|
propsData: {
|
|
|
|
retryUrl,
|
|
|
|
environment: {
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2022-08-27 11:52:29 +05:30
|
|
|
const button = wrapper.findComponent(GlDropdownItem);
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
button.vm.$emit('click');
|
|
|
|
|
|
|
|
expect(eventHubSpy).toHaveBeenCalledWith('requestRollbackEnvironment', {
|
|
|
|
retryUrl,
|
|
|
|
isLastDeployment: true,
|
|
|
|
name: 'test',
|
|
|
|
});
|
|
|
|
});
|
2022-01-26 12:08:38 +05:30
|
|
|
|
|
|
|
it('should trigger a graphql mutation when graphql is enabled', () => {
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
|
|
|
const apolloProvider = createMockApollo();
|
|
|
|
jest.spyOn(apolloProvider.defaultClient, 'mutate');
|
|
|
|
const environment = {
|
|
|
|
name: 'test',
|
|
|
|
};
|
|
|
|
const wrapper = shallowMount(RollbackComponent, {
|
|
|
|
propsData: {
|
|
|
|
retryUrl,
|
|
|
|
graphql: true,
|
|
|
|
environment,
|
|
|
|
},
|
|
|
|
apolloProvider,
|
|
|
|
});
|
2022-08-27 11:52:29 +05:30
|
|
|
const button = wrapper.findComponent(GlDropdownItem);
|
2022-01-26 12:08:38 +05:30
|
|
|
button.vm.$emit('click');
|
|
|
|
|
|
|
|
expect(apolloProvider.defaultClient.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: setEnvironmentToRollback,
|
2023-01-13 00:05:48 +05:30
|
|
|
variables: { environment: { ...environment, isLastDeployment: true, retryUrl } },
|
2022-01-26 12:08:38 +05:30
|
|
|
});
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|