2017-05-02 07:03:58 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import DeployKeysStore from '~/deploy_keys/store';
|
|
|
|
import key from '~/deploy_keys/components/key.vue';
|
2017-12-07 06:09:17 -05:00
|
|
|
import { getTimeago } from '~/lib/utils/datetime_utility';
|
2017-05-02 07:03:58 -04:00
|
|
|
|
|
|
|
describe('Deploy keys key', () => {
|
|
|
|
let vm;
|
|
|
|
const KeyComponent = Vue.extend(key);
|
|
|
|
const data = getJSONFixture('deploy_keys/keys.json');
|
2018-05-07 14:21:34 -04:00
|
|
|
const createComponent = deployKey => {
|
2017-05-02 07:03:58 -04:00
|
|
|
const store = new DeployKeysStore();
|
|
|
|
store.keys = data;
|
|
|
|
|
|
|
|
vm = new KeyComponent({
|
|
|
|
propsData: {
|
|
|
|
deployKey,
|
|
|
|
store,
|
2017-06-20 04:05:55 -04:00
|
|
|
endpoint: 'https://test.host/dummy/endpoint',
|
2017-05-02 07:03:58 -04:00
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('enabled key', () => {
|
|
|
|
const deployKey = data.enabled_keys[0];
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
beforeEach(done => {
|
2017-05-02 07:03:58 -04:00
|
|
|
createComponent(deployKey);
|
|
|
|
|
|
|
|
setTimeout(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the keys title', () => {
|
2018-05-07 14:21:34 -04:00
|
|
|
expect(vm.$el.querySelector('.title').textContent.trim()).toContain('My title');
|
2017-05-02 07:03:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders human friendly formatted created date', () => {
|
2018-05-07 14:21:34 -04:00
|
|
|
expect(vm.$el.querySelector('.key-created-at').textContent.trim()).toBe(
|
|
|
|
`${getTimeago().format(deployKey.created_at)}`,
|
|
|
|
);
|
2017-05-02 07:03:58 -04:00
|
|
|
});
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
it('shows pencil button for editing', () => {
|
|
|
|
expect(vm.$el.querySelector('.btn .ic-pencil')).toExist();
|
2017-03-31 08:54:38 -04:00
|
|
|
});
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
it('shows disable button when the project is not deletable', () => {
|
|
|
|
expect(vm.$el.querySelector('.btn .ic-cancel')).toExist();
|
2017-05-02 07:03:58 -04:00
|
|
|
});
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
it('shows remove button when the project is deletable', done => {
|
|
|
|
vm.deployKey.destroyed_when_orphaned = true;
|
|
|
|
vm.deployKey.almost_orphaned = true;
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('.btn .ic-remove')).toExist();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deploy key labels', () => {
|
|
|
|
it('shows write access title when key has write access', done => {
|
2018-01-05 10:23:44 -05:00
|
|
|
vm.deployKey.deploy_keys_projects[0].can_push = true;
|
2017-05-02 07:03:58 -04:00
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(
|
2018-01-05 10:23:44 -05:00
|
|
|
vm.$el.querySelector('.deploy-project-label').getAttribute('data-original-title'),
|
2017-05-02 07:03:58 -04:00
|
|
|
).toBe('Write access allowed');
|
2018-01-05 10:23:44 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
it('does not show write access title when key has write access', done => {
|
2018-01-05 10:23:44 -05:00
|
|
|
vm.deployKey.deploy_keys_projects[0].can_push = false;
|
2017-05-02 07:03:58 -04:00
|
|
|
|
2018-01-05 10:23:44 -05:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelector('.deploy-project-label').getAttribute('data-original-title'),
|
|
|
|
).toBe('Read access only');
|
2017-05-02 07:03:58 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-05-07 14:21:34 -04:00
|
|
|
|
|
|
|
it('shows expandable button if more than two projects', () => {
|
|
|
|
const labels = vm.$el.querySelectorAll('.deploy-project-label');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
expect(labels.length).toBe(2);
|
|
|
|
expect(labels[1].textContent).toContain('others');
|
|
|
|
expect(labels[1].getAttribute('data-original-title')).toContain('Expand');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('expands all project labels after click', done => {
|
2018-06-16 17:50:13 -04:00
|
|
|
const { length } = vm.deployKey.deploy_keys_projects;
|
2018-05-07 14:21:34 -04:00
|
|
|
vm.$el.querySelectorAll('.deploy-project-label')[1].click();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
const labels = vm.$el.querySelectorAll('.deploy-project-label');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
expect(labels.length).toBe(length);
|
|
|
|
expect(labels[1].textContent).not.toContain(`+${length} others`);
|
|
|
|
expect(labels[1].getAttribute('data-original-title')).not.toContain('Expand');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows two projects', done => {
|
|
|
|
vm.deployKey.deploy_keys_projects = [...vm.deployKey.deploy_keys_projects].slice(0, 2);
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
const labels = vm.$el.querySelectorAll('.deploy-project-label');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
expect(labels.length).toBe(2);
|
|
|
|
expect(labels[1].textContent).toContain(
|
|
|
|
vm.deployKey.deploy_keys_projects[1].project.full_name,
|
|
|
|
);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-05-02 07:03:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('public keys', () => {
|
|
|
|
const deployKey = data.public_keys[0];
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
beforeEach(done => {
|
2017-05-02 07:03:58 -04:00
|
|
|
createComponent(deployKey);
|
|
|
|
|
|
|
|
setTimeout(done);
|
|
|
|
});
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
it('renders deploy keys without any enabled projects', done => {
|
|
|
|
vm.deployKey.deploy_keys_projects = [];
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('.deploy-project-list').textContent.trim()).toBe('None');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2017-03-31 08:54:38 -04:00
|
|
|
});
|
|
|
|
|
2017-05-02 07:03:58 -04:00
|
|
|
it('shows enable button', () => {
|
2018-05-07 14:21:34 -04:00
|
|
|
expect(vm.$el.querySelectorAll('.btn')[0].textContent.trim()).toBe('Enable');
|
2017-05-02 07:03:58 -04:00
|
|
|
});
|
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
it('shows pencil button for editing', () => {
|
|
|
|
expect(vm.$el.querySelector('.btn .ic-pencil')).toExist();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows disable button when key is enabled', done => {
|
2017-05-02 07:03:58 -04:00
|
|
|
vm.store.keys.enabled_keys.push(deployKey);
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-05-07 14:21:34 -04:00
|
|
|
expect(vm.$el.querySelector('.btn .ic-cancel')).toExist();
|
2017-05-02 07:03:58 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|