2020-04-22 19:07:51 +05:30
|
|
|
import { GlLink, GlIcon } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2021-11-18 22:05:49 +05:30
|
|
|
import originalRelease from 'test_fixtures/api/releases/release.json';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { truncateSha } from '~/lib/utils/text_utility';
|
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';
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the evidence icon', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.findComponent(GlIcon).props('name')).toBe('review-list');
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the title for the dowload link', () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(wrapper.findComponent(GlLink).text()).toMatch(/v1\.1-evidences-[0-9]+\.json/);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the correct hover text for the download', () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
expect(wrapper.findComponent(GlLink).attributes('title')).toBe('Open evidence JSON in new tab');
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
it('renders a link that opens in a new tab', () => {
|
|
|
|
expect(wrapper.findComponent(GlLink).attributes().target).toBe('_blank');
|
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
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('renders the long sha after expansion', async () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
wrapper.find('.js-text-expander-prepend').trigger('click');
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.find('.js-expanded').text()).toBe(release.evidences[0].sha);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('copy to clipboard button', () => {
|
|
|
|
it('renders button', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.findComponent(ClipboardButton).exists()).toBe(true);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the correct hover text', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.findComponent(ClipboardButton).attributes('title')).toBe('Copy evidence SHA');
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('copies the sha', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.findComponent(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
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|