2022-02-01 07:17:55 -05:00
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2021-10-04 14:12:46 -04:00
|
|
|
import { GlDropdownItem } from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-02-01 07:17:55 -05:00
|
|
|
import cancelAutoStopMutation from '~/environments/graphql/mutations/cancel_auto_stop.mutation.graphql';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
2020-01-03 04:07:33 -05:00
|
|
|
import PinComponent from '~/environments/components/environment_pin.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import eventHub from '~/environments/event_hub';
|
2020-01-03 04:07:33 -05:00
|
|
|
|
|
|
|
describe('Pin Component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const factory = (options = {}) => {
|
|
|
|
// This destroys any wrappers created before a nested call to factory reassigns it
|
|
|
|
if (wrapper && wrapper.destroy) {
|
|
|
|
wrapper.destroy();
|
|
|
|
}
|
|
|
|
wrapper = shallowMount(PinComponent, {
|
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const autoStopUrl = '/root/auto-stop-env-test/-/environments/38/cancel_auto_stop';
|
|
|
|
|
2022-02-01 07:17:55 -05:00
|
|
|
describe('without graphql', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
autoStopUrl,
|
|
|
|
},
|
|
|
|
});
|
2020-01-03 04:07:33 -05:00
|
|
|
});
|
|
|
|
|
2022-02-01 07:17:55 -05:00
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
2020-01-03 04:07:33 -05:00
|
|
|
|
2022-02-01 07:17:55 -05:00
|
|
|
it('should render the component with descriptive text', () => {
|
|
|
|
expect(wrapper.text()).toBe('Prevent auto-stopping');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should emit onPinClick when clicked', () => {
|
|
|
|
const eventHubSpy = jest.spyOn(eventHub, '$emit');
|
2022-08-15 23:11:31 -04:00
|
|
|
const item = wrapper.findComponent(GlDropdownItem);
|
2022-02-01 07:17:55 -05:00
|
|
|
|
|
|
|
item.vm.$emit('click');
|
|
|
|
|
|
|
|
expect(eventHubSpy).toHaveBeenCalledWith('cancelAutoStop', autoStopUrl);
|
|
|
|
});
|
2020-01-03 04:07:33 -05:00
|
|
|
});
|
|
|
|
|
2022-02-01 07:17:55 -05:00
|
|
|
describe('with graphql', () => {
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
let mockApollo;
|
2020-01-03 04:07:33 -05:00
|
|
|
|
2022-02-01 07:17:55 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
mockApollo = createMockApollo();
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
autoStopUrl,
|
|
|
|
graphql: true,
|
|
|
|
},
|
|
|
|
apolloProvider: mockApollo,
|
|
|
|
});
|
|
|
|
});
|
2020-01-03 04:07:33 -05:00
|
|
|
|
2022-02-01 07:17:55 -05:00
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the component with descriptive text', () => {
|
|
|
|
expect(wrapper.text()).toBe('Prevent auto-stopping');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should emit onPinClick when clicked', () => {
|
|
|
|
jest.spyOn(mockApollo.defaultClient, 'mutate');
|
2022-08-15 23:11:31 -04:00
|
|
|
const item = wrapper.findComponent(GlDropdownItem);
|
2022-02-01 07:17:55 -05:00
|
|
|
|
|
|
|
item.vm.$emit('click');
|
|
|
|
|
|
|
|
expect(mockApollo.defaultClient.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: cancelAutoStopMutation,
|
|
|
|
variables: { autoStopUrl },
|
|
|
|
});
|
|
|
|
});
|
2020-01-03 04:07:33 -05:00
|
|
|
});
|
|
|
|
});
|