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

156 lines
4.1 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import _ from 'underscore';
2017-08-17 22:00:37 +05:30
import Vue from 'vue';
import eventHub from '~/deploy_keys/eventhub';
import deployKeysApp from '~/deploy_keys/components/app.vue';
describe('Deploy keys app component', () => {
const data = getJSONFixture('deploy_keys/keys.json');
let vm;
const deployKeysResponse = (request, next) => {
2018-10-15 14:42:47 +05:30
next(
request.respondWith(JSON.stringify(data), {
status: 200,
}),
);
2017-08-17 22:00:37 +05:30
};
2018-10-15 14:42:47 +05:30
beforeEach(done => {
2017-08-17 22:00:37 +05:30
const Component = Vue.extend(deployKeysApp);
Vue.http.interceptors.push(deployKeysResponse);
vm = new Component({
propsData: {
endpoint: '/test',
2018-10-15 14:42:47 +05:30
projectId: '8',
2017-08-17 22:00:37 +05:30
},
}).$mount();
setTimeout(done);
});
afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, deployKeysResponse);
});
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',
);
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}`,
);
expect(textContent('.js-deployKeys-tab-available_project_keys .badge')).toBe(
`${vm.store.keys.available_project_keys.length}`,
);
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
});