gitlab-org--gitlab-foss/spec/frontend/deploy_keys/components/action_btn_spec.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

import { GlLoadingIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import actionBtn from '~/deploy_keys/components/action_btn.vue';
import eventHub from '~/deploy_keys/eventhub';
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');
});
});
});