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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 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';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2021-11-18 22:05:49 +05:30
import data from 'test_fixtures/deploy_keys/keys.json';
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 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',
});
});
2022-04-04 11:22:00 +05:30
it('sends eventHub event with btn type', async () => {
2020-05-24 23:13:21 +05:30
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
2022-04-04 11:22:00 +05:30
await nextTick();
expect(eventHub.$emit).toHaveBeenCalledWith('enable.key', deployKey, expect.anything());
2020-05-24 23:13:21 +05:30
});
2022-04-04 11:22:00 +05:30
it('shows loading spinner after click', async () => {
2021-06-08 01:23:25 +05:30
findButton().vm.$emit('click');
2020-05-24 23:13:21 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
expect(findButton().props('loading')).toBe(true);
2020-05-24 23:13:21 +05:30
});
});