2020-01-03 04:07:33 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-04-03 05:09:31 -04:00
|
|
|
import { GlDeprecatedButton } from '@gitlab/ui';
|
2020-01-03 04:07:33 -05:00
|
|
|
import Icon from '~/vue_shared/components/icon.vue';
|
|
|
|
import eventHub from '~/environments/event_hub';
|
|
|
|
import PinComponent from '~/environments/components/environment_pin.vue';
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the component with thumbtack icon', () => {
|
|
|
|
expect(wrapper.find(Icon).props('name')).toBe('thumbtack');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should emit onPinClick when clicked', () => {
|
|
|
|
const eventHubSpy = jest.spyOn(eventHub, '$emit');
|
2020-04-03 05:09:31 -04:00
|
|
|
const button = wrapper.find(GlDeprecatedButton);
|
2020-01-03 04:07:33 -05:00
|
|
|
|
|
|
|
button.vm.$emit('click');
|
|
|
|
|
|
|
|
expect(eventHubSpy).toHaveBeenCalledWith('cancelAutoStop', autoStopUrl);
|
|
|
|
});
|
|
|
|
});
|