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';
|
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 = {}) => {
|
|
|
|
// 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';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
autoStopUrl,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
it('should render the component with descriptive text', () => {
|
|
|
|
expect(wrapper.text()).toBe('Prevent auto-stopping');
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should emit onPinClick when clicked', () => {
|
|
|
|
const eventHubSpy = jest.spyOn(eventHub, '$emit');
|
2021-11-18 22:05:49 +05:30
|
|
|
const item = wrapper.find(GlDropdownItem);
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
item.vm.$emit('click');
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
expect(eventHubSpy).toHaveBeenCalledWith('cancelAutoStop', autoStopUrl);
|
|
|
|
});
|
|
|
|
});
|