2021-04-22 11:09:56 -04:00
|
|
|
import { GlButton } 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;
|
|
|
|
|
2021-04-22 11:09:56 -04:00
|
|
|
const findButton = () => wrapper.findComponent(GlButton);
|
2020-04-27 14:09:41 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallowMount(actionBtn, {
|
|
|
|
propsData: {
|
|
|
|
deployKey,
|
|
|
|
type: 'enable',
|
2021-04-22 11:09:56 -04:00
|
|
|
category: 'primary',
|
|
|
|
variant: 'confirm',
|
|
|
|
icon: 'edit',
|
2020-04-27 14:09:41 -04:00
|
|
|
},
|
|
|
|
slots: {
|
|
|
|
default: 'Enable',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the default slot', () => {
|
|
|
|
expect(wrapper.text()).toBe('Enable');
|
|
|
|
});
|
|
|
|
|
2021-04-22 11:09:56 -04:00
|
|
|
it('passes the button props on', () => {
|
|
|
|
expect(findButton().props()).toMatchObject({
|
|
|
|
category: 'primary',
|
|
|
|
variant: 'confirm',
|
|
|
|
icon: 'edit',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-27 14:09:41 -04:00
|
|
|
it('sends eventHub event with btn type', () => {
|
|
|
|
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
|
|
|
|
|
2021-04-22 11:09:56 -04:00
|
|
|
findButton().vm.$emit('click');
|
2020-04-27 14:09:41 -04:00
|
|
|
|
|
|
|
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', () => {
|
2021-04-22 11:09:56 -04:00
|
|
|
findButton().vm.$emit('click');
|
2020-04-27 14:09:41 -04:00
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
2021-04-22 11:09:56 -04:00
|
|
|
expect(findButton().props('loading')).toBe(true);
|
2020-04-27 14:09:41 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|