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';
|
2022-01-25 10:12:32 -05:00
|
|
|
import { nextTick } from 'vue';
|
2021-10-11 08:11:56 -04:00
|
|
|
import data from 'test_fixtures/deploy_keys/keys.json';
|
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 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',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
it('sends eventHub event with btn type', async () => {
|
2020-04-27 14:09:41 -04:00
|
|
|
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
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('enable.key', deployKey, expect.anything());
|
2020-04-27 14:09:41 -04:00
|
|
|
});
|
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
it('shows loading spinner after click', async () => {
|
2021-04-22 11:09:56 -04:00
|
|
|
findButton().vm.$emit('click');
|
2020-04-27 14:09:41 -04:00
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(findButton().props('loading')).toBe(true);
|
2020-04-27 14:09:41 -04:00
|
|
|
});
|
|
|
|
});
|