2020-10-24 23:57:45 +05:30
|
|
|
import { GlButton } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-03-02 08:16:31 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import setEnvironmentToStopMutation from '~/environments/graphql/mutations/set_environment_to_stop.mutation.graphql';
|
|
|
|
import isEnvironmentStoppingQuery from '~/environments/graphql/queries/is_environment_stopping.query.graphql';
|
2020-01-01 13:55:28 +05:30
|
|
|
import StopComponent from '~/environments/components/environment_stop.vue';
|
|
|
|
import eventHub from '~/environments/event_hub';
|
2022-03-02 08:16:31 +05:30
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import { resolvedEnvironment } from './graphql/mock_data';
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
describe('Stop Component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
const createWrapper = (props = {}, options = {}) => {
|
2020-01-01 13:55:28 +05:30
|
|
|
wrapper = shallowMount(StopComponent, {
|
|
|
|
propsData: {
|
|
|
|
environment: {},
|
2022-03-02 08:16:31 +05:30
|
|
|
...props,
|
2020-01-01 13:55:28 +05:30
|
|
|
},
|
2022-03-02 08:16:31 +05:30
|
|
|
...options,
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
const findButton = () => wrapper.findComponent(GlButton);
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
describe('eventHub', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createWrapper();
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it('should render a button to stop the environment', () => {
|
|
|
|
expect(findButton().exists()).toBe(true);
|
|
|
|
expect(wrapper.attributes('title')).toEqual('Stop environment');
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it('emits requestStopEnvironment in the event hub when button is clicked', () => {
|
|
|
|
jest.spyOn(eventHub, '$emit');
|
|
|
|
findButton().vm.$emit('click');
|
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('requestStopEnvironment', wrapper.vm.environment);
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
describe('graphql', () => {
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
let mockApollo;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockApollo = createMockApollo();
|
|
|
|
mockApollo.clients.defaultClient.writeQuery({
|
|
|
|
query: isEnvironmentStoppingQuery,
|
|
|
|
variables: { environment: resolvedEnvironment },
|
|
|
|
data: { isEnvironmentStopping: true },
|
|
|
|
});
|
|
|
|
|
|
|
|
createWrapper(
|
|
|
|
{ graphql: true, environment: resolvedEnvironment },
|
|
|
|
{ apolloProvider: mockApollo },
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a button to stop the environment', () => {
|
|
|
|
expect(findButton().exists()).toBe(true);
|
|
|
|
expect(wrapper.attributes('title')).toEqual('Stop environment');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the environment to stop on click', () => {
|
|
|
|
jest.spyOn(mockApollo.defaultClient, 'mutate');
|
|
|
|
findButton().vm.$emit('click');
|
|
|
|
expect(mockApollo.defaultClient.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: setEnvironmentToStopMutation,
|
|
|
|
variables: { environment: resolvedEnvironment },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it('should show a loading icon if the environment is currently stopping', () => {
|
2022-03-02 08:16:31 +05:30
|
|
|
expect(findButton().props('loading')).toBe(true);
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
});
|