2020-04-27 14:09:41 -04:00
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-04-27 14:09:41 -04:00
|
|
|
import actionBtn from '~/deploy_keys/components/action_btn.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import eventHub from '~/deploy_keys/eventhub';
|
2020-04-27 14:09:41 -04:00
|
|
|
|
|
|
|
describe('Deploy keys action btn', () => {
|
|
|
|
const data = getJSONFixture('deploy_keys/keys.json');
|
|
|
|
const deployKey = data.enabled_keys[0];
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallowMount(actionBtn, {
|
|
|
|
propsData: {
|
|
|
|
deployKey,
|
|
|
|
type: 'enable',
|
|
|
|
},
|
|
|
|
slots: {
|
|
|
|
default: 'Enable',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the default slot', () => {
|
|
|
|
expect(wrapper.text()).toBe('Enable');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sends eventHub event with btn type', () => {
|
|
|
|
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
|
|
|
|
|
|
|
|
wrapper.trigger('click');
|
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
2020-06-22 20:08:58 -04:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('enable.key', deployKey, expect.anything());
|
2020-04-27 14:09:41 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows loading spinner after click', () => {
|
|
|
|
wrapper.trigger('click');
|
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('disables button after click', () => {
|
|
|
|
wrapper.trigger('click');
|
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.attributes('disabled')).toBe('disabled');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|