2022-08-27 11:52:29 +05:30
|
|
|
import { GlLink, GlBadge } from '@gitlab/ui';
|
2020-04-08 14:13:33 +05:30
|
|
|
import { merge } from 'lodash';
|
2021-11-18 22:05:49 +05:30
|
|
|
import originalRelease from 'test_fixtures/api/releases/release.json';
|
2021-10-27 15:23:28 +05:30
|
|
|
import setWindowLocation from 'helpers/set_window_location_helper';
|
2022-08-27 11:52:29 +05:30
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
|
|
|
import { __ } from '~/locale';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
2021-03-11 19:13:27 +05:30
|
|
|
import ReleaseBlockHeader from '~/releases/components/release_block_header.vue';
|
2020-04-08 14:13:33 +05:30
|
|
|
import { BACK_URL_PARAM } from '~/releases/constants';
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
describe('Release block header', () => {
|
|
|
|
let wrapper;
|
|
|
|
let release;
|
|
|
|
|
|
|
|
const factory = (releaseUpdates = {}) => {
|
2022-08-27 11:52:29 +05:30
|
|
|
wrapper = shallowMountExtended(ReleaseBlockHeader, {
|
2020-03-13 15:44:24 +05:30
|
|
|
propsData: {
|
|
|
|
release: merge({}, release, releaseUpdates),
|
|
|
|
},
|
2022-08-27 11:52:29 +05:30
|
|
|
stubs: { GlBadge },
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-04-08 14:13:33 +05:30
|
|
|
release = convertObjectPropsToCamelCase(originalRelease, { deep: true });
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
const findHeader = () => wrapper.find('h2');
|
2022-10-11 01:57:18 +05:30
|
|
|
const findHeaderLink = () => findHeader().findComponent(GlLink);
|
2020-04-08 14:13:33 +05:30
|
|
|
const findEditButton = () => wrapper.find('.js-edit-button');
|
2022-08-27 11:52:29 +05:30
|
|
|
const findBadge = () => wrapper.findComponent(GlBadge);
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
describe('when _links.self is provided', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the title as a link', () => {
|
|
|
|
const link = findHeaderLink();
|
|
|
|
|
|
|
|
expect(link.text()).toBe(release.name);
|
|
|
|
expect(link.attributes('href')).toBe(release._links.self);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when _links.self is missing', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({ _links: { self: null } });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the title as text', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(findHeader().text()).toContain(release.name);
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(findHeaderLink().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
describe('when _links.edit_url is provided', () => {
|
|
|
|
const currentUrl = 'https://example.gitlab.com/path';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-10-27 15:23:28 +05:30
|
|
|
setWindowLocation(currentUrl);
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
factory();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders an edit button', () => {
|
|
|
|
expect(findEditButton().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the edit button with the correct href', () => {
|
|
|
|
const expectedQueryParam = `${BACK_URL_PARAM}=${encodeURIComponent(currentUrl)}`;
|
|
|
|
const expectedUrl = `${release._links.editUrl}?${expectedQueryParam}`;
|
|
|
|
expect(findEditButton().attributes().href).toBe(expectedUrl);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when _links.edit is missing', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({ _links: { editUrl: null } });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render an edit button', () => {
|
|
|
|
expect(findEditButton().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
describe('upcoming release', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({ upcomingRelease: true, historicalRelease: false });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows a badge that the release is upcoming', () => {
|
|
|
|
const badge = findBadge();
|
|
|
|
|
|
|
|
expect(badge.text()).toBe(__('Upcoming Release'));
|
|
|
|
expect(badge.props('variant')).toBe('warning');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('historical release', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({ upcomingRelease: false, historicalRelease: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows a badge that the release is historical', () => {
|
|
|
|
const badge = findBadge();
|
|
|
|
|
|
|
|
expect(badge.text()).toBe(__('Historical release'));
|
|
|
|
expect(badge.attributes('title')).toBe(
|
|
|
|
__(
|
|
|
|
'This release was created with a date in the past. Evidence collection at the moment of the release is unavailable.',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|