debian-mirror-gitlab/spec/frontend/releases/components/evidence_block_spec.js

79 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
import { mount } from '@vue/test-utils';
2020-04-22 19:07:51 +05:30
import { GlLink, GlIcon } from '@gitlab/ui';
2020-01-01 13:55:28 +05:30
import { truncateSha } from '~/lib/utils/text_utility';
2020-04-08 14:13:33 +05:30
import { release as originalRelease } from '../mock_data';
2020-03-13 15:44:24 +05:30
import EvidenceBlock from '~/releases/components/evidence_block.vue';
2020-01-01 13:55:28 +05:30
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
2020-04-08 14:13:33 +05:30
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
2020-01-01 13:55:28 +05:30
describe('Evidence Block', () => {
let wrapper;
2020-04-08 14:13:33 +05:30
let release;
2020-01-01 13:55:28 +05:30
const factory = (options = {}) => {
2020-03-13 15:44:24 +05:30
wrapper = mount(EvidenceBlock, {
2020-01-01 13:55:28 +05:30
...options,
});
};
beforeEach(() => {
2020-04-08 14:13:33 +05:30
release = convertObjectPropsToCamelCase(originalRelease, { deep: true });
2020-01-01 13:55:28 +05:30
factory({
propsData: {
release,
},
});
});
afterEach(() => {
wrapper.destroy();
});
it('renders the evidence icon', () => {
2020-04-22 19:07:51 +05:30
expect(wrapper.find(GlIcon).props('name')).toBe('review-list');
2020-01-01 13:55:28 +05:30
});
it('renders the title for the dowload link', () => {
2020-04-22 19:07:51 +05:30
expect(wrapper.find(GlLink).text()).toBe('v1.1.2-evidences-1.json');
2020-01-01 13:55:28 +05:30
});
it('renders the correct hover text for the download', () => {
2020-03-13 15:44:24 +05:30
expect(wrapper.find(GlLink).attributes('title')).toBe('Download evidence JSON');
2020-01-01 13:55:28 +05:30
});
it('renders the correct file link for download', () => {
2020-04-22 19:07:51 +05:30
expect(wrapper.find(GlLink).attributes().download).toBe('v1.1.2-evidences-1.json');
2020-01-01 13:55:28 +05:30
});
describe('sha text', () => {
it('renders the short sha initially', () => {
2020-04-22 19:07:51 +05:30
expect(wrapper.find('.js-short').text()).toBe(truncateSha(release.evidences[0].sha));
2020-01-01 13:55:28 +05:30
});
it('renders the long sha after expansion', () => {
wrapper.find('.js-text-expander-prepend').trigger('click');
2020-03-13 15:44:24 +05:30
return wrapper.vm.$nextTick().then(() => {
2020-04-22 19:07:51 +05:30
expect(wrapper.find('.js-expanded').text()).toBe(release.evidences[0].sha);
2020-03-13 15:44:24 +05:30
});
2020-01-01 13:55:28 +05:30
});
});
describe('copy to clipboard button', () => {
it('renders button', () => {
expect(wrapper.find(ClipboardButton).exists()).toBe(true);
});
it('renders the correct hover text', () => {
2020-04-08 14:13:33 +05:30
expect(wrapper.find(ClipboardButton).attributes('title')).toBe('Copy evidence SHA');
2020-01-01 13:55:28 +05:30
});
it('copies the sha', () => {
expect(wrapper.find(ClipboardButton).attributes('data-clipboard-text')).toBe(
2020-04-22 19:07:51 +05:30
release.evidences[0].sha,
2020-01-01 13:55:28 +05:30
);
});
});
});