2020-05-24 23:13:21 +05:30
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-05-24 23:13:21 +05:30
|
|
|
import actionBtn from '~/deploy_keys/components/action_btn.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import eventHub from '~/deploy_keys/eventhub';
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
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(() => {
|
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('enable.key', deployKey, expect.anything());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|