debian-mirror-gitlab/spec/frontend/deploy_keys/components/action_btn_spec.js

58 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-06-08 01:23:25 +05:30
import { GlButton } 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;
2021-06-08 01:23:25 +05:30
const findButton = () => wrapper.findComponent(GlButton);
2020-05-24 23:13:21 +05:30
beforeEach(() => {
wrapper = shallowMount(actionBtn, {
propsData: {
deployKey,
type: 'enable',
2021-06-08 01:23:25 +05:30
category: 'primary',
variant: 'confirm',
icon: 'edit',
2020-05-24 23:13:21 +05:30
},
slots: {
default: 'Enable',
},
});
});
it('renders the default slot', () => {
expect(wrapper.text()).toBe('Enable');
});
2021-06-08 01:23:25 +05:30
it('passes the button props on', () => {
expect(findButton().props()).toMatchObject({
category: 'primary',
variant: 'confirm',
icon: 'edit',
});
});
2020-05-24 23:13:21 +05:30
it('sends eventHub event with btn type', () => {
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
2021-06-08 01:23:25 +05:30
findButton().vm.$emit('click');
2020-05-24 23:13:21 +05:30
return wrapper.vm.$nextTick().then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith('enable.key', deployKey, expect.anything());
});
});
it('shows loading spinner after click', () => {
2021-06-08 01:23:25 +05:30
findButton().vm.$emit('click');
2020-05-24 23:13:21 +05:30
return wrapper.vm.$nextTick().then(() => {
2021-06-08 01:23:25 +05:30
expect(findButton().props('loading')).toBe(true);
2020-05-24 23:13:21 +05:30
});
});
});