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');
|
|
|
|
const createComponent = (deployKey) => {
|
|
|
|
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];
|
|
|
|
|
|
|
|
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(),
|
2017-12-07 06:09:17 -05:00
|
|
|
).toBe(`created ${getTimeago().format(deployKey.created_at)}`);
|
2017-05-02 07:03:58 -04:00
|
|
|
});
|
|
|
|
|
2017-03-31 08:54:38 -04:00
|
|
|
it('shows edit button', () => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelectorAll('.btn')[0].textContent.trim(),
|
|
|
|
).toBe('Edit');
|
|
|
|
});
|
|
|
|
|
2017-05-02 07:03:58 -04:00
|
|
|
it('shows remove button', () => {
|
|
|
|
expect(
|
2017-03-31 08:54:38 -04:00
|
|
|
vm.$el.querySelectorAll('.btn')[1].textContent.trim(),
|
2017-05-02 07:03:58 -04:00
|
|
|
).toBe('Remove');
|
|
|
|
});
|
|
|
|
|
2018-01-05 10:23:44 -05:00
|
|
|
it('shows write access title when key has write access', (done) => {
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show write access title when key has write access', (done) => {
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('public keys', () => {
|
|
|
|
const deployKey = data.public_keys[0];
|
|
|
|
|
|
|
|
beforeEach((done) => {
|
|
|
|
createComponent(deployKey);
|
|
|
|
|
|
|
|
setTimeout(done);
|
|
|
|
});
|
|
|
|
|
2017-03-31 08:54:38 -04:00
|
|
|
it('shows edit button', () => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelectorAll('.btn')[0].textContent.trim(),
|
|
|
|
).toBe('Edit');
|
|
|
|
});
|
|
|
|
|
2017-05-02 07:03:58 -04:00
|
|
|
it('shows enable button', () => {
|
|
|
|
expect(
|
2017-03-31 08:54:38 -04:00
|
|
|
vm.$el.querySelectorAll('.btn')[1].textContent.trim(),
|
2017-05-02 07:03:58 -04:00
|
|
|
).toBe('Enable');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows disable button when key is enabled', (done) => {
|
|
|
|
vm.store.keys.enabled_keys.push(deployKey);
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(
|
2017-03-31 08:54:38 -04:00
|
|
|
vm.$el.querySelectorAll('.btn')[1].textContent.trim(),
|
2017-05-02 07:03:58 -04:00
|
|
|
).toBe('Disable');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|