2020-04-27 14:09:41 -04:00
|
|
|
import { mount } from '@vue/test-utils';
|
2022-01-25 10:12:32 -05:00
|
|
|
import { nextTick } from 'vue';
|
2021-10-11 08:11:56 -04:00
|
|
|
import data from 'test_fixtures/deploy_keys/keys.json';
|
2020-04-27 14:09:41 -04:00
|
|
|
import key from '~/deploy_keys/components/key.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import DeployKeysStore from '~/deploy_keys/store';
|
2020-04-27 14:09:41 -04:00
|
|
|
import { getTimeago } from '~/lib/utils/datetime_utility';
|
|
|
|
|
|
|
|
describe('Deploy keys key', () => {
|
|
|
|
let wrapper;
|
|
|
|
let store;
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
const findTextAndTrim = (selector) => wrapper.find(selector).text().trim();
|
2020-04-27 14:09:41 -04:00
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
const createComponent = (propsData) => {
|
2020-04-27 14:09:41 -04:00
|
|
|
wrapper = mount(key, {
|
|
|
|
propsData: {
|
|
|
|
store,
|
|
|
|
endpoint: 'https://test.host/dummy/endpoint',
|
|
|
|
...propsData,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
store = new DeployKeysStore();
|
|
|
|
store.keys = data;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('enabled key', () => {
|
|
|
|
const deployKey = data.enabled_keys[0];
|
|
|
|
|
|
|
|
it('renders the keys title', () => {
|
|
|
|
createComponent({ deployKey });
|
|
|
|
|
|
|
|
expect(findTextAndTrim('.title')).toContain('My title');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders human friendly formatted created date', () => {
|
|
|
|
createComponent({ deployKey });
|
|
|
|
|
|
|
|
expect(findTextAndTrim('.key-created-at')).toBe(
|
|
|
|
`${getTimeago().format(deployKey.created_at)}`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows pencil button for editing', () => {
|
|
|
|
createComponent({ deployKey });
|
|
|
|
|
2021-11-10 01:10:31 -05:00
|
|
|
expect(wrapper.find('.btn [data-testid="pencil-icon"]').exists()).toBe(true);
|
2020-04-27 14:09:41 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows disable button when the project is not deletable', () => {
|
|
|
|
createComponent({ deployKey });
|
|
|
|
|
2021-11-10 01:10:31 -05:00
|
|
|
expect(wrapper.find('.btn [data-testid="cancel-icon"]').exists()).toBe(true);
|
2020-04-27 14:09:41 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows remove button when the project is deletable', () => {
|
|
|
|
createComponent({
|
|
|
|
deployKey: { ...deployKey, destroyed_when_orphaned: true, almost_orphaned: true },
|
|
|
|
});
|
2021-11-10 01:10:31 -05:00
|
|
|
expect(wrapper.find('.btn [data-testid="remove-icon"]').exists()).toBe(true);
|
2020-04-27 14:09:41 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deploy key labels', () => {
|
|
|
|
const deployKey = data.enabled_keys[0];
|
|
|
|
const deployKeysProjects = [...deployKey.deploy_keys_projects];
|
|
|
|
it('shows write access title when key has write access', () => {
|
|
|
|
deployKeysProjects[0] = { ...deployKeysProjects[0], can_push: true };
|
|
|
|
createComponent({ deployKey: { ...deployKey, deploy_keys_projects: deployKeysProjects } });
|
|
|
|
|
2020-10-26 05:08:48 -04:00
|
|
|
expect(wrapper.find('.deploy-project-label').attributes('title')).toBe(
|
2021-02-02 13:09:42 -05:00
|
|
|
'Grant write permissions to this key',
|
2020-04-27 14:09:41 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show write access title when key has write access', () => {
|
|
|
|
deployKeysProjects[0] = { ...deployKeysProjects[0], can_push: false };
|
|
|
|
createComponent({ deployKey: { ...deployKey, deploy_keys_projects: deployKeysProjects } });
|
|
|
|
|
2020-10-26 05:08:48 -04:00
|
|
|
expect(wrapper.find('.deploy-project-label').attributes('title')).toBe('Read access only');
|
2020-04-27 14:09:41 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows expandable button if more than two projects', () => {
|
|
|
|
createComponent({ deployKey });
|
|
|
|
const labels = wrapper.findAll('.deploy-project-label');
|
|
|
|
|
|
|
|
expect(labels.length).toBe(2);
|
|
|
|
expect(labels.at(1).text()).toContain('others');
|
2020-10-26 05:08:48 -04:00
|
|
|
expect(labels.at(1).attributes('title')).toContain('Expand');
|
2020-04-27 14:09:41 -04:00
|
|
|
});
|
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
it('expands all project labels after click', async () => {
|
2020-04-27 14:09:41 -04:00
|
|
|
createComponent({ deployKey });
|
|
|
|
const { length } = deployKey.deploy_keys_projects;
|
2020-12-23 07:10:26 -05:00
|
|
|
wrapper.findAll('.deploy-project-label').at(1).trigger('click');
|
2020-04-27 14:09:41 -04:00
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
|
|
|
const labels = wrapper.findAll('.deploy-project-label');
|
2020-04-27 14:09:41 -04:00
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
expect(labels.length).toBe(length);
|
|
|
|
expect(labels.at(1).text()).not.toContain(`+${length} others`);
|
|
|
|
expect(labels.at(1).attributes('title')).not.toContain('Expand');
|
2020-04-27 14:09:41 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows two projects', () => {
|
|
|
|
createComponent({
|
|
|
|
deployKey: { ...deployKey, deploy_keys_projects: [...deployKeysProjects].slice(0, 2) },
|
|
|
|
});
|
|
|
|
|
|
|
|
const labels = wrapper.findAll('.deploy-project-label');
|
|
|
|
|
|
|
|
expect(labels.length).toBe(2);
|
|
|
|
expect(labels.at(1).text()).toContain(deployKey.deploy_keys_projects[1].project.full_name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('public keys', () => {
|
|
|
|
const deployKey = data.public_keys[0];
|
|
|
|
|
|
|
|
it('renders deploy keys without any enabled projects', () => {
|
|
|
|
createComponent({ deployKey: { ...deployKey, deploy_keys_projects: [] } });
|
|
|
|
|
|
|
|
expect(findTextAndTrim('.deploy-project-list')).toBe('None');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows enable button', () => {
|
|
|
|
createComponent({ deployKey });
|
|
|
|
expect(findTextAndTrim('.btn')).toBe('Enable');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows pencil button for editing', () => {
|
|
|
|
createComponent({ deployKey });
|
2021-11-10 01:10:31 -05:00
|
|
|
expect(wrapper.find('.btn [data-testid="pencil-icon"]').exists()).toBe(true);
|
2020-04-27 14:09:41 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows disable button when key is enabled', () => {
|
|
|
|
store.keys.enabled_keys.push(deployKey);
|
|
|
|
|
|
|
|
createComponent({ deployKey });
|
|
|
|
|
2021-11-10 01:10:31 -05:00
|
|
|
expect(wrapper.find('.btn [data-testid="cancel-icon"]').exists()).toBe(true);
|
2020-04-27 14:09:41 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|