debian-mirror-gitlab/spec/frontend/environments/environment_delete_spec.js

72 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-11-18 22:05:49 +05:30
import { GlDropdownItem } from '@gitlab/ui';
2020-04-22 19:07:51 +05:30
import { shallowMount } from '@vue/test-utils';
2022-01-26 12:08:38 +05:30
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import setEnvironmentToDelete from '~/environments/graphql/mutations/set_environment_to_delete.mutation.graphql';
2020-04-22 19:07:51 +05:30
import DeleteComponent from '~/environments/components/environment_delete.vue';
import eventHub from '~/environments/event_hub';
2022-01-26 12:08:38 +05:30
import createMockApollo from 'helpers/mock_apollo_helper';
import { resolvedEnvironment } from './graphql/mock_data';
2020-04-22 19:07:51 +05:30
describe('External URL Component', () => {
let wrapper;
2022-01-26 12:08:38 +05:30
const createWrapper = (props = {}, options = {}) => {
2020-04-22 19:07:51 +05:30
wrapper = shallowMount(DeleteComponent, {
2022-01-26 12:08:38 +05:30
...options,
2020-04-22 19:07:51 +05:30
propsData: {
2022-01-26 12:08:38 +05:30
environment: resolvedEnvironment,
...props,
2020-04-22 19:07:51 +05:30
},
});
};
2022-08-27 11:52:29 +05:30
const findDropdownItem = () => wrapper.findComponent(GlDropdownItem);
2020-04-22 19:07:51 +05:30
2022-01-26 12:08:38 +05:30
describe('event hub', () => {
beforeEach(() => {
createWrapper();
});
2020-04-22 19:07:51 +05:30
2022-01-26 12:08:38 +05:30
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-04-22 19:07:51 +05:30
2022-01-26 12:08:38 +05:30
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-04-22 19:07:51 +05:30
});
2022-01-26 12:08:38 +05:30
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-04-22 19:07:51 +05:30
});
});