2021-10-04 14:12:46 -04:00
|
|
|
import { GlDropdownItem } from '@gitlab/ui';
|
2020-03-25 05:08:11 -04:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-12-15 13:13:38 -05:00
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import setEnvironmentToDelete from '~/environments/graphql/mutations/set_environment_to_delete.mutation.graphql';
|
2020-03-25 05:08:11 -04:00
|
|
|
import DeleteComponent from '~/environments/components/environment_delete.vue';
|
|
|
|
import eventHub from '~/environments/event_hub';
|
2021-12-15 13:13:38 -05:00
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import { resolvedEnvironment } from './graphql/mock_data';
|
2020-03-25 05:08:11 -04:00
|
|
|
|
|
|
|
describe('External URL Component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2021-12-15 13:13:38 -05:00
|
|
|
const createWrapper = (props = {}, options = {}) => {
|
2020-03-25 05:08:11 -04:00
|
|
|
wrapper = shallowMount(DeleteComponent, {
|
2021-12-15 13:13:38 -05:00
|
|
|
...options,
|
2020-03-25 05:08:11 -04:00
|
|
|
propsData: {
|
2021-12-15 13:13:38 -05:00
|
|
|
environment: resolvedEnvironment,
|
|
|
|
...props,
|
2020-03-25 05:08:11 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-10-04 14:12:46 -04:00
|
|
|
const findDropdownItem = () => wrapper.find(GlDropdownItem);
|
2020-03-25 05:08:11 -04:00
|
|
|
|
2021-12-15 13:13:38 -05:00
|
|
|
describe('event hub', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createWrapper();
|
|
|
|
});
|
2020-03-25 05:08:11 -04:00
|
|
|
|
2021-12-15 13:13:38 -05:00
|
|
|
it('should render a dropdown item to delete the environment', () => {
|
|
|
|
expect(findDropdownItem().exists()).toBe(true);
|
|
|
|
expect(wrapper.text()).toEqual('Delete environment');
|
|
|
|
expect(findDropdownItem().attributes('variant')).toBe('danger');
|
|
|
|
});
|
2020-03-25 05:08:11 -04:00
|
|
|
|
2021-12-15 13:13:38 -05:00
|
|
|
it('emits requestDeleteEnvironment in the event hub when button is clicked', () => {
|
|
|
|
jest.spyOn(eventHub, '$emit');
|
|
|
|
findDropdownItem().vm.$emit('click');
|
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('requestDeleteEnvironment', resolvedEnvironment);
|
|
|
|
});
|
2020-03-25 05:08:11 -04:00
|
|
|
});
|
|
|
|
|
2021-12-15 13:13:38 -05:00
|
|
|
describe('graphql', () => {
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
let mockApollo;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockApollo = createMockApollo();
|
|
|
|
createWrapper(
|
|
|
|
{ graphql: true, environment: resolvedEnvironment },
|
|
|
|
{ apolloProvider: mockApollo },
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a dropdown item to delete the environment', () => {
|
|
|
|
expect(findDropdownItem().exists()).toBe(true);
|
|
|
|
expect(wrapper.text()).toEqual('Delete environment');
|
|
|
|
expect(findDropdownItem().attributes('variant')).toBe('danger');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('emits requestDeleteEnvironment in the event hub when button is clicked', () => {
|
|
|
|
jest.spyOn(mockApollo.defaultClient, 'mutate');
|
|
|
|
findDropdownItem().vm.$emit('click');
|
|
|
|
expect(mockApollo.defaultClient.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: setEnvironmentToDelete,
|
|
|
|
variables: { environment: resolvedEnvironment },
|
|
|
|
});
|
|
|
|
});
|
2020-03-25 05:08:11 -04:00
|
|
|
});
|
|
|
|
});
|