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

113 lines
2.8 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import Vue from 'vue';
import DeployKeysStore from '~/deploy_keys/store';
import key from '~/deploy_keys/components/key.vue';
2018-03-17 18:26:18 +05:30
import { getTimeago } from '~/lib/utils/datetime_utility';
2017-08-17 22:00:37 +05:30
describe('Deploy keys key', () => {
let vm;
const KeyComponent = Vue.extend(key);
const data = getJSONFixture('deploy_keys/keys.json');
const createComponent = (deployKey) => {
const store = new DeployKeysStore();
store.keys = data;
vm = new KeyComponent({
propsData: {
deployKey,
store,
2017-09-10 17:25:29 +05:30
endpoint: 'https://test.host/dummy/endpoint',
2017-08-17 22:00:37 +05:30
},
}).$mount();
};
describe('enabled key', () => {
const deployKey = data.enabled_keys[0];
beforeEach((done) => {
createComponent(deployKey);
setTimeout(done);
});
it('renders the keys title', () => {
expect(
vm.$el.querySelector('.title').textContent.trim(),
).toContain('My title');
});
it('renders human friendly formatted created date', () => {
expect(
vm.$el.querySelector('.key-created-at').textContent.trim(),
2018-03-17 18:26:18 +05:30
).toBe(`created ${getTimeago().format(deployKey.created_at)}`);
2017-08-17 22:00:37 +05:30
});
2017-09-10 17:25:29 +05:30
it('shows edit button', () => {
expect(
vm.$el.querySelectorAll('.btn')[0].textContent.trim(),
).toBe('Edit');
});
2017-08-17 22:00:37 +05:30
it('shows remove button', () => {
expect(
2017-09-10 17:25:29 +05:30
vm.$el.querySelectorAll('.btn')[1].textContent.trim(),
2017-08-17 22:00:37 +05:30
).toBe('Remove');
});
2018-03-17 18:26:18 +05:30
it('shows write access title when key has write access', (done) => {
vm.deployKey.deploy_keys_projects[0].can_push = true;
2017-08-17 22:00:37 +05:30
Vue.nextTick(() => {
expect(
2018-03-17 18:26:18 +05:30
vm.$el.querySelector('.deploy-project-label').getAttribute('data-original-title'),
2017-08-17 22:00:37 +05:30
).toBe('Write access allowed');
2018-03-17 18:26:18 +05:30
done();
});
});
it('does not show write access title when key has write access', (done) => {
vm.deployKey.deploy_keys_projects[0].can_push = false;
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
Vue.nextTick(() => {
expect(
vm.$el.querySelector('.deploy-project-label').getAttribute('data-original-title'),
).toBe('Read access only');
2017-08-17 22:00:37 +05:30
done();
});
});
});
describe('public keys', () => {
const deployKey = data.public_keys[0];
beforeEach((done) => {
createComponent(deployKey);
setTimeout(done);
});
2017-09-10 17:25:29 +05:30
it('shows edit button', () => {
expect(
vm.$el.querySelectorAll('.btn')[0].textContent.trim(),
).toBe('Edit');
});
2017-08-17 22:00:37 +05:30
it('shows enable button', () => {
expect(
2017-09-10 17:25:29 +05:30
vm.$el.querySelectorAll('.btn')[1].textContent.trim(),
2017-08-17 22:00:37 +05:30
).toBe('Enable');
});
it('shows disable button when key is enabled', (done) => {
vm.store.keys.enabled_keys.push(deployKey);
Vue.nextTick(() => {
expect(
2017-09-10 17:25:29 +05:30
vm.$el.querySelectorAll('.btn')[1].textContent.trim(),
2017-08-17 22:00:37 +05:30
).toBe('Disable');
done();
});
});
});
});