2020-06-23 00:09:42 +05:30
|
|
|
import { GlCollapse } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2021-11-18 22:05:49 +05:30
|
|
|
import { assets } from 'test_fixtures/api/releases/release.json';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { trimText } from 'helpers/text_helper';
|
2021-01-03 14:25:43 +05:30
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
2020-06-23 00:09:42 +05:30
|
|
|
import ReleaseBlockAssets from '~/releases/components/release_block_assets.vue';
|
|
|
|
import { ASSET_LINK_TYPE } from '~/releases/constants';
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
describe('Release block assets', () => {
|
|
|
|
let wrapper;
|
|
|
|
let defaultProps;
|
|
|
|
|
|
|
|
// A map of types to the expected section heading text
|
|
|
|
const sections = {
|
|
|
|
[ASSET_LINK_TYPE.IMAGE]: 'Images',
|
|
|
|
[ASSET_LINK_TYPE.PACKAGE]: 'Packages',
|
|
|
|
[ASSET_LINK_TYPE.RUNBOOK]: 'Runbooks',
|
|
|
|
[ASSET_LINK_TYPE.OTHER]: 'Other',
|
|
|
|
};
|
|
|
|
|
|
|
|
const createComponent = (propsData = defaultProps) => {
|
|
|
|
wrapper = mount(ReleaseBlockAssets, {
|
|
|
|
propsData,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const findSectionHeading = (type) =>
|
|
|
|
wrapper.findAll('h5').filter((h5) => h5.text() === sections[type]);
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-01-03 14:25:43 +05:30
|
|
|
defaultProps = { assets: convertObjectPropsToCamelCase(assets, { deep: true }) };
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('with default props', () => {
|
|
|
|
beforeEach(() => createComponent());
|
|
|
|
|
|
|
|
const findAccordionButton = () => wrapper.find('[data-testid="accordion-button"]');
|
|
|
|
|
|
|
|
it('renders an "Assets" accordion with the asset count', () => {
|
|
|
|
const accordionButton = findAccordionButton();
|
|
|
|
|
|
|
|
expect(accordionButton.exists()).toBe(true);
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(trimText(accordionButton.text())).toBe('Assets 8');
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the accordion as expanded by default', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
const accordion = wrapper.findComponent(GlCollapse);
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
expect(accordion.exists()).toBe(true);
|
|
|
|
expect(accordion.isVisible()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders sources with the expected text and URL', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
defaultProps.assets.sources.forEach((s) => {
|
2020-06-23 00:09:42 +05:30
|
|
|
const sourceLink = wrapper.find(`li>a[href="${s.url}"]`);
|
|
|
|
|
|
|
|
expect(sourceLink.exists()).toBe(true);
|
|
|
|
expect(sourceLink.text()).toBe(`Source code (${s.format})`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a heading for each assets type (except sources)', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
Object.keys(sections).forEach((type) => {
|
2020-06-23 00:09:42 +05:30
|
|
|
const sectionHeadings = findSectionHeading(type);
|
|
|
|
|
|
|
|
expect(sectionHeadings).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders asset links with the expected text and URL', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
defaultProps.assets.links.forEach((l) => {
|
2020-06-23 00:09:42 +05:30
|
|
|
const sourceLink = wrapper.find(`li>a[href="${l.directAssetUrl}"]`);
|
|
|
|
|
|
|
|
expect(sourceLink.exists()).toBe(true);
|
|
|
|
expect(sourceLink.text()).toBe(l.name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when a release doesn't have a link with a certain asset type", () => {
|
|
|
|
const typeToExclude = ASSET_LINK_TYPE.IMAGE;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
defaultProps.assets.links = defaultProps.assets.links.filter(
|
2021-03-08 18:12:59 +05:30
|
|
|
(l) => l.linkType !== typeToExclude,
|
2020-06-23 00:09:42 +05:30
|
|
|
);
|
|
|
|
createComponent(defaultProps);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render a section heading if there are no links of that type', () => {
|
|
|
|
const sectionHeadings = findSectionHeading(typeToExclude);
|
|
|
|
|
|
|
|
expect(sectionHeadings).toHaveLength(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
describe('sources', () => {
|
|
|
|
const testSources = ({ shouldSourcesBeRendered }) => {
|
2021-03-08 18:12:59 +05:30
|
|
|
assets.sources.forEach((s) => {
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(wrapper.find(`a[href="${s.url}"]`).exists()).toBe(shouldSourcesBeRendered);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('when the release has sources', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent(defaultProps);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders sources', () => {
|
|
|
|
testSources({ shouldSourcesBeRendered: true });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the release does not have sources', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
delete defaultProps.assets.sources;
|
|
|
|
createComponent(defaultProps);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render any sources', () => {
|
|
|
|
testSources({ shouldSourcesBeRendered: false });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
describe('links', () => {
|
2023-07-09 08:55:56 +05:30
|
|
|
const findAllExternalIcons = () => wrapper.findAll('[data-testid="external-link-indicator"]');
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
beforeEach(() => createComponent(defaultProps));
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
it('renders with an external source indicator', () => {
|
|
|
|
expect(findAllExternalIcons()).toHaveLength(defaultProps.assets.count);
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|