2022-04-04 11:22:00 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2021-11-18 22:05:49 +05:30
|
|
|
import { GlDropdownItem } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-04-04 11:22:00 +05:30
|
|
|
import cancelAutoStopMutation from '~/environments/graphql/mutations/cancel_auto_stop.mutation.graphql';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
2020-03-13 15:44:24 +05:30
|
|
|
import PinComponent from '~/environments/components/environment_pin.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import eventHub from '~/environments/event_hub';
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
describe('Pin Component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const factory = (options = {}) => {
|
|
|
|
wrapper = shallowMount(PinComponent, {
|
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const autoStopUrl = '/root/auto-stop-env-test/-/environments/38/cancel_auto_stop';
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
describe('without graphql', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
autoStopUrl,
|
|
|
|
},
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
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-27 11:52:29 +05:30
|
|
|
const item = wrapper.findComponent(GlDropdownItem);
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
item.vm.$emit('click');
|
|
|
|
|
|
|
|
expect(eventHubSpy).toHaveBeenCalledWith('cancelAutoStop', autoStopUrl);
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
describe('with graphql', () => {
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
let mockApollo;
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
mockApollo = createMockApollo();
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
autoStopUrl,
|
|
|
|
graphql: true,
|
|
|
|
},
|
|
|
|
apolloProvider: mockApollo,
|
|
|
|
});
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
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-27 11:52:29 +05:30
|
|
|
const item = wrapper.findComponent(GlDropdownItem);
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
item.vm.$emit('click');
|
|
|
|
|
|
|
|
expect(mockApollo.defaultClient.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: cancelAutoStopMutation,
|
|
|
|
variables: { autoStopUrl },
|
|
|
|
});
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
});
|