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

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

129 lines
3.9 KiB
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import { mount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter';
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 waitForPromises from 'helpers/wait_for_promises';
2021-03-11 19:13:27 +05:30
import { TEST_HOST } from 'spec/test_constants';
2020-05-24 23:13:21 +05:30
import deployKeysApp from '~/deploy_keys/components/app.vue';
2021-06-08 01:23:25 +05:30
import ConfirmModal from '~/deploy_keys/components/confirm_modal.vue';
2021-03-11 19:13:27 +05:30
import eventHub from '~/deploy_keys/eventhub';
import axios from '~/lib/utils/axios_utils';
2020-05-24 23:13:21 +05:30
const TEST_ENDPOINT = `${TEST_HOST}/dummy/`;
describe('Deploy keys app component', () => {
let wrapper;
let mock;
const mountComponent = () => {
wrapper = mount(deployKeysApp, {
propsData: {
endpoint: TEST_ENDPOINT,
projectId: '8',
},
});
return waitForPromises();
};
beforeEach(() => {
mock = new MockAdapter(axios);
mock.onGet(TEST_ENDPOINT).reply(200, data);
});
afterEach(() => {
wrapper.destroy();
mock.restore();
});
const findLoadingIcon = () => wrapper.find('.gl-spinner');
2021-03-08 18:12:59 +05:30
const findKeyPanels = () => wrapper.findAll('.deploy-keys .gl-tabs-nav li');
2021-06-08 01:23:25 +05:30
const findModal = () => wrapper.findComponent(ConfirmModal);
2020-05-24 23:13:21 +05:30
2022-04-04 11:22:00 +05:30
it('renders loading icon while waiting for request', async () => {
2020-05-24 23:13:21 +05:30
mock.onGet(TEST_ENDPOINT).reply(() => new Promise());
mountComponent();
2022-04-04 11:22:00 +05:30
await nextTick();
expect(findLoadingIcon().exists()).toBe(true);
2020-05-24 23:13:21 +05:30
});
2022-04-04 11:22:00 +05:30
it('renders keys panels', async () => {
await mountComponent();
expect(findKeyPanels().length).toBe(3);
2020-05-24 23:13:21 +05:30
});
it.each`
2021-03-08 18:12:59 +05:30
selector
${'.js-deployKeys-tab-enabled_keys'}
${'.js-deployKeys-tab-available_project_keys'}
${'.js-deployKeys-tab-public_keys'}
`('$selector title exists', ({ selector }) => {
2020-05-24 23:13:21 +05:30
return mountComponent().then(() => {
const element = wrapper.find(selector);
expect(element.exists()).toBe(true);
});
});
it('does not render key panels when keys object is empty', () => {
mock.onGet(TEST_ENDPOINT).reply(200, []);
return mountComponent().then(() => {
expect(findKeyPanels().length).toBe(0);
});
});
2022-04-04 11:22:00 +05:30
it('re-fetches deploy keys when enabling a key', async () => {
2020-05-24 23:13:21 +05:30
const key = data.public_keys[0];
2022-04-04 11:22:00 +05:30
await mountComponent();
jest.spyOn(wrapper.vm.service, 'getKeys').mockImplementation(() => {});
jest.spyOn(wrapper.vm.service, 'enableKey').mockImplementation(() => Promise.resolve());
eventHub.$emit('enable.key', key);
await nextTick();
expect(wrapper.vm.service.enableKey).toHaveBeenCalledWith(key.id);
expect(wrapper.vm.service.getKeys).toHaveBeenCalled();
2020-05-24 23:13:21 +05:30
});
2022-04-04 11:22:00 +05:30
it('re-fetches deploy keys when disabling a key', async () => {
2020-05-24 23:13:21 +05:30
const key = data.public_keys[0];
2022-04-04 11:22:00 +05:30
await mountComponent();
jest.spyOn(wrapper.vm.service, 'getKeys').mockImplementation(() => {});
jest.spyOn(wrapper.vm.service, 'disableKey').mockImplementation(() => Promise.resolve());
eventHub.$emit('disable.key', key, () => {});
await nextTick();
expect(findModal().props('visible')).toBe(true);
findModal().vm.$emit('remove');
await nextTick();
expect(wrapper.vm.service.disableKey).toHaveBeenCalledWith(key.id);
expect(wrapper.vm.service.getKeys).toHaveBeenCalled();
2020-05-24 23:13:21 +05:30
});
2022-04-04 11:22:00 +05:30
it('calls disableKey when removing a key', async () => {
2020-05-24 23:13:21 +05:30
const key = data.public_keys[0];
2022-04-04 11:22:00 +05:30
await mountComponent();
jest.spyOn(wrapper.vm.service, 'getKeys').mockImplementation(() => {});
jest.spyOn(wrapper.vm.service, 'disableKey').mockImplementation(() => Promise.resolve());
eventHub.$emit('remove.key', key, () => {});
await nextTick();
expect(findModal().props('visible')).toBe(true);
findModal().vm.$emit('remove');
await nextTick();
expect(wrapper.vm.service.disableKey).toHaveBeenCalledWith(key.id);
expect(wrapper.vm.service.getKeys).toHaveBeenCalled();
2020-05-24 23:13:21 +05:30
});
2022-04-04 11:22:00 +05:30
it('hasKeys returns true when there are keys', async () => {
await mountComponent();
expect(wrapper.vm.hasKeys).toEqual(3);
2020-05-24 23:13:21 +05:30
});
});