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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.3 KiB
JavaScript
Raw Normal View History

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,
},
});
});
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', () => {
2021-01-03 14:25:43 +05:30
expect(wrapper.find(GlLink).text()).toBe(`v1.1-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', () => {
2021-01-03 14:25:43 +05:30
expect(wrapper.find(GlLink).attributes().download).toBe(`v1.1-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
});
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', () => {
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
);
});
});
});