2017-08-17 22:00:37 +05:30
|
|
|
import Vue from 'vue';
|
2018-11-08 19:23:39 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-08-17 22:00:37 +05:30
|
|
|
import eventHub from '~/deploy_keys/eventhub';
|
|
|
|
import deployKeysApp from '~/deploy_keys/components/app.vue';
|
2018-11-08 19:23:39 +05:30
|
|
|
import { TEST_HOST } from 'spec/test_constants';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe('Deploy keys app component', () => {
|
|
|
|
const data = getJSONFixture('deploy_keys/keys.json');
|
|
|
|
let vm;
|
2018-11-08 19:23:39 +05:30
|
|
|
let mock;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2018-12-05 23:21:45 +05:30
|
|
|
// set up axios mock before component
|
2018-11-08 19:23:39 +05:30
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onGet(`${TEST_HOST}/dummy/`).replyOnce(200, data);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
const Component = Vue.extend(deployKeysApp);
|
|
|
|
|
|
|
|
vm = new Component({
|
|
|
|
propsData: {
|
2018-11-08 19:23:39 +05:30
|
|
|
endpoint: `${TEST_HOST}/dummy`,
|
2018-10-15 14:42:47 +05:30
|
|
|
projectId: '8',
|
2017-08-17 22:00:37 +05:30
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
|
|
|
setTimeout(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-11-08 19:23:39 +05:30
|
|
|
mock.restore();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it('renders loading icon', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
vm.store.keys = {};
|
|
|
|
vm.isLoading = false;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(vm.$el.querySelectorAll('.deploy-keys .nav-links li').length).toBe(0);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(vm.$el.querySelector('.fa-spinner')).toBeDefined();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders keys panels', () => {
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(vm.$el.querySelectorAll('.deploy-keys .nav-links li').length).toBe(3);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it('renders the titles with keys count', () => {
|
|
|
|
const textContent = selector => {
|
|
|
|
const element = vm.$el.querySelector(`${selector}`);
|
|
|
|
|
|
|
|
expect(element).not.toBeNull();
|
|
|
|
return element.textContent.trim();
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(textContent('.js-deployKeys-tab-enabled_keys')).toContain('Enabled deploy keys');
|
|
|
|
expect(textContent('.js-deployKeys-tab-available_project_keys')).toContain(
|
|
|
|
'Privately accessible deploy keys',
|
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(textContent('.js-deployKeys-tab-public_keys')).toContain(
|
|
|
|
'Publicly accessible deploy keys',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(textContent('.js-deployKeys-tab-enabled_keys .badge')).toBe(
|
|
|
|
`${vm.store.keys.enabled_keys.length}`,
|
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(textContent('.js-deployKeys-tab-available_project_keys .badge')).toBe(
|
|
|
|
`${vm.store.keys.available_project_keys.length}`,
|
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(textContent('.js-deployKeys-tab-public_keys .badge')).toBe(
|
|
|
|
`${vm.store.keys.public_keys.length}`,
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it('does not render key panels when keys object is empty', done => {
|
|
|
|
vm.store.keys = {};
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(vm.$el.querySelectorAll('.deploy-keys .nav-links li').length).toBe(0);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it('re-fetches deploy keys when enabling a key', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
const key = data.public_keys[0];
|
|
|
|
|
|
|
|
spyOn(vm.service, 'getKeys');
|
2018-10-15 14:42:47 +05:30
|
|
|
spyOn(vm.service, 'enableKey').and.callFake(() => Promise.resolve());
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
eventHub.$emit('enable.key', key);
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.service.enableKey).toHaveBeenCalledWith(key.id);
|
|
|
|
expect(vm.service.getKeys).toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it('re-fetches deploy keys when disabling a key', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
const key = data.public_keys[0];
|
|
|
|
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
spyOn(vm.service, 'getKeys');
|
2018-10-15 14:42:47 +05:30
|
|
|
spyOn(vm.service, 'disableKey').and.callFake(() => Promise.resolve());
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
eventHub.$emit('disable.key', key);
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.service.disableKey).toHaveBeenCalledWith(key.id);
|
|
|
|
expect(vm.service.getKeys).toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it('calls disableKey when removing a key', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
const key = data.public_keys[0];
|
|
|
|
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
spyOn(vm.service, 'getKeys');
|
2018-10-15 14:42:47 +05:30
|
|
|
spyOn(vm.service, 'disableKey').and.callFake(() => Promise.resolve());
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
eventHub.$emit('remove.key', key);
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.service.disableKey).toHaveBeenCalledWith(key.id);
|
|
|
|
expect(vm.service.getKeys).toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('hasKeys returns true when there are keys', () => {
|
|
|
|
expect(vm.hasKeys).toEqual(3);
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it('resets disable button loading state', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
spyOn(window, 'confirm').and.returnValue(false);
|
|
|
|
|
|
|
|
const btn = vm.$el.querySelector('.btn-warning');
|
|
|
|
|
|
|
|
btn.click();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(btn.querySelector('.btn-warning')).not.toExist();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|