2019-09-13 20:06:25 -04:00
|
|
|
import { mount } from '@vue/test-utils';
|
2021-02-14 13:09:20 -05:00
|
|
|
import $ from 'jquery';
|
2022-01-25 07:14:14 -05:00
|
|
|
import { nextTick } from 'vue';
|
2022-06-30 14:09:30 -04:00
|
|
|
import originalOneReleaseQueryResponse from 'test_fixtures/graphql/releases/graphql/queries/one_release.query.graphql.json';
|
|
|
|
import { convertOneReleaseGraphQLResponse } from '~/releases/util';
|
2021-02-14 13:09:20 -05:00
|
|
|
import * as commonUtils from '~/lib/utils/common_utils';
|
|
|
|
import * as urlUtility from '~/lib/utils/url_utility';
|
2020-02-14 16:09:08 -05:00
|
|
|
import EvidenceBlock from '~/releases/components/evidence_block.vue';
|
|
|
|
import ReleaseBlock from '~/releases/components/release_block.vue';
|
|
|
|
import ReleaseBlockFooter from '~/releases/components/release_block_footer.vue';
|
2020-03-04 04:08:20 -05:00
|
|
|
import { BACK_URL_PARAM } from '~/releases/constants';
|
2021-02-14 13:09:20 -05:00
|
|
|
import timeagoMixin from '~/vue_shared/mixins/timeago';
|
2019-09-13 20:06:25 -04:00
|
|
|
|
|
|
|
describe('Release block', () => {
|
|
|
|
let wrapper;
|
2020-02-24 13:09:05 -05:00
|
|
|
let release;
|
2019-09-13 20:06:25 -04:00
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
const factory = async (releaseProp, featureFlags = {}) => {
|
2019-09-13 20:06:25 -04:00
|
|
|
wrapper = mount(ReleaseBlock, {
|
|
|
|
propsData: {
|
|
|
|
release: releaseProp,
|
|
|
|
},
|
2019-10-15 20:06:16 -04:00
|
|
|
provide: {
|
|
|
|
glFeatures: {
|
2019-11-08 07:06:32 -05:00
|
|
|
...featureFlags,
|
2019-10-15 20:06:16 -04:00
|
|
|
},
|
|
|
|
},
|
2019-09-13 20:06:25 -04:00
|
|
|
});
|
2019-10-15 20:06:16 -04:00
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
await nextTick();
|
2019-09-13 20:06:25 -04:00
|
|
|
};
|
|
|
|
|
2019-10-01 05:10:39 -04:00
|
|
|
const milestoneListLabel = () => wrapper.find('.js-milestone-list-label');
|
2019-10-15 20:06:16 -04:00
|
|
|
const editButton = () => wrapper.find('.js-edit-button');
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-01-22 07:08:40 -05:00
|
|
|
jest.spyOn($.fn, 'renderGFM');
|
2022-06-30 14:09:30 -04:00
|
|
|
release = convertOneReleaseGraphQLResponse(originalOneReleaseQueryResponse).data;
|
2019-10-15 20:06:16 -04:00
|
|
|
});
|
2019-09-13 20:06:25 -04:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with default props', () => {
|
2019-10-15 20:06:16 -04:00
|
|
|
beforeEach(() => factory(release));
|
|
|
|
|
2019-09-13 20:06:25 -04:00
|
|
|
it("renders the block with an id equal to the release's tag name", () => {
|
2020-09-30 14:09:52 -04:00
|
|
|
expect(wrapper.attributes().id).toBe(release.tagName);
|
2019-09-13 20:06:25 -04:00
|
|
|
});
|
|
|
|
|
2020-03-04 04:08:20 -05:00
|
|
|
it(`renders an edit button that links to the "Edit release" page with a "${BACK_URL_PARAM}" parameter`, () => {
|
2019-10-15 20:06:16 -04:00
|
|
|
expect(editButton().exists()).toBe(true);
|
2020-03-04 04:08:20 -05:00
|
|
|
expect(editButton().attributes('href')).toBe(
|
|
|
|
`${release._links.editUrl}?${BACK_URL_PARAM}=${encodeURIComponent(window.location.href)}`,
|
|
|
|
);
|
2019-09-13 20:06:25 -04:00
|
|
|
});
|
|
|
|
|
2019-10-15 20:06:16 -04:00
|
|
|
it('renders release name', () => {
|
|
|
|
expect(wrapper.text()).toContain(release.name);
|
2019-09-13 20:06:25 -04:00
|
|
|
});
|
|
|
|
|
2020-01-22 07:08:40 -05:00
|
|
|
it('renders release description', () => {
|
|
|
|
expect(wrapper.vm.$refs['gfm-content']).toBeDefined();
|
|
|
|
expect($.fn.renderGFM).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
2019-09-13 20:06:25 -04:00
|
|
|
it('renders release date', () => {
|
2020-02-24 13:09:05 -05:00
|
|
|
expect(wrapper.text()).toContain(timeagoMixin.methods.timeFormatted(release.releasedAt));
|
2019-09-13 20:06:25 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders author avatar', () => {
|
|
|
|
expect(wrapper.find('.user-avatar-link').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2019-11-08 07:06:32 -05:00
|
|
|
it('renders the footer', () => {
|
2022-09-12 11:14:03 -04:00
|
|
|
expect(wrapper.findComponent(ReleaseBlockFooter).exists()).toBe(true);
|
2019-11-08 07:06:32 -05:00
|
|
|
});
|
2019-09-13 20:06:25 -04:00
|
|
|
});
|
|
|
|
|
2019-10-15 20:06:16 -04:00
|
|
|
it('renders commit sha', () => {
|
2020-02-24 13:09:05 -05:00
|
|
|
release.commitPath = '/commit/example';
|
2019-10-15 20:06:16 -04:00
|
|
|
|
2020-02-24 13:09:05 -05:00
|
|
|
return factory(release).then(() => {
|
|
|
|
expect(wrapper.text()).toContain(release.commit.shortId);
|
2019-10-15 20:06:16 -04:00
|
|
|
|
|
|
|
expect(wrapper.find('a[href="/commit/example"]').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tag name', () => {
|
2020-02-24 13:09:05 -05:00
|
|
|
release.tagPath = '/tag/example';
|
2019-10-15 20:06:16 -04:00
|
|
|
|
2020-02-24 13:09:05 -05:00
|
|
|
return factory(release).then(() => {
|
|
|
|
expect(wrapper.text()).toContain(release.tagName);
|
2019-10-15 20:06:16 -04:00
|
|
|
|
|
|
|
expect(wrapper.find('a[href="/tag/example"]').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-13 20:06:25 -04:00
|
|
|
it('does not render the milestone list if no milestones are associated to the release', () => {
|
2020-02-24 13:09:05 -05:00
|
|
|
delete release.milestones;
|
2019-10-01 05:10:39 -04:00
|
|
|
|
2020-02-24 13:09:05 -05:00
|
|
|
return factory(release).then(() => {
|
2019-10-15 20:06:16 -04:00
|
|
|
expect(milestoneListLabel().exists()).toBe(false);
|
|
|
|
});
|
2019-10-01 05:10:39 -04:00
|
|
|
});
|
|
|
|
|
2019-09-13 20:06:25 -04:00
|
|
|
it('renders upcoming release badge', () => {
|
2020-02-24 13:09:05 -05:00
|
|
|
release.upcomingRelease = true;
|
2019-09-13 20:06:25 -04:00
|
|
|
|
2020-02-24 13:09:05 -05:00
|
|
|
return factory(release).then(() => {
|
2019-10-15 20:06:16 -04:00
|
|
|
expect(wrapper.text()).toContain('Upcoming Release');
|
|
|
|
});
|
2019-09-13 20:06:25 -04:00
|
|
|
});
|
2019-10-04 08:06:14 -04:00
|
|
|
|
2020-02-24 13:09:05 -05:00
|
|
|
it('slugifies the tagName before setting it as the elements ID', () => {
|
|
|
|
release.tagName = 'a dangerous tag name <script>alert("hello")</script>';
|
2019-10-04 08:06:14 -04:00
|
|
|
|
2020-02-24 13:09:05 -05:00
|
|
|
return factory(release).then(() => {
|
2020-01-17 16:08:29 -05:00
|
|
|
expect(wrapper.attributes().id).toBe('a-dangerous-tag-name-script-alert-hello-script');
|
2019-10-15 20:06:16 -04:00
|
|
|
});
|
2019-10-04 08:06:14 -04:00
|
|
|
});
|
|
|
|
|
2020-04-01 17:07:56 -04:00
|
|
|
it('does not set the ID if tagName is missing', () => {
|
|
|
|
release.tagName = undefined;
|
|
|
|
|
|
|
|
return factory(release).then(() => {
|
|
|
|
expect(wrapper.attributes().id).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-22 04:06:20 -05:00
|
|
|
describe('evidence block', () => {
|
2020-10-07 02:09:03 -04:00
|
|
|
it('renders the evidence block when the evidence is available', () => {
|
|
|
|
return factory(release).then(() => {
|
2022-09-12 11:14:03 -04:00
|
|
|
expect(wrapper.findComponent(EvidenceBlock).exists()).toBe(true);
|
2020-10-07 02:09:03 -04:00
|
|
|
});
|
|
|
|
});
|
2019-11-22 04:06:20 -05:00
|
|
|
|
|
|
|
it('does not render the evidence block when there is no evidence', () => {
|
2020-10-07 02:09:03 -04:00
|
|
|
release.evidences = [];
|
2019-11-22 04:06:20 -05:00
|
|
|
|
2020-02-24 13:09:05 -05:00
|
|
|
return factory(release).then(() => {
|
2022-09-12 11:14:03 -04:00
|
|
|
expect(wrapper.findComponent(EvidenceBlock).exists()).toBe(false);
|
2019-11-22 04:06:20 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-04 08:06:14 -04:00
|
|
|
describe('anchor scrolling', () => {
|
2020-03-04 04:08:20 -05:00
|
|
|
let locationHash;
|
|
|
|
|
2019-10-04 08:06:14 -04:00
|
|
|
beforeEach(() => {
|
2020-03-04 04:08:20 -05:00
|
|
|
commonUtils.scrollToElement = jest.fn();
|
|
|
|
urlUtility.getLocationHash = jest.fn().mockImplementation(() => locationHash);
|
2019-10-04 08:06:14 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const hasTargetBlueBackground = () => wrapper.classes('bg-line-target-blue');
|
|
|
|
|
|
|
|
it('does not attempt to scroll the page if no anchor tag is included in the URL', () => {
|
2020-03-04 04:08:20 -05:00
|
|
|
locationHash = '';
|
2019-10-15 20:06:16 -04:00
|
|
|
return factory(release).then(() => {
|
2020-03-04 04:08:20 -05:00
|
|
|
expect(commonUtils.scrollToElement).not.toHaveBeenCalled();
|
2019-10-15 20:06:16 -04:00
|
|
|
});
|
2019-10-04 08:06:14 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it("does not attempt to scroll the page if the anchor tag doesn't match the release's tag name", () => {
|
2020-03-04 04:08:20 -05:00
|
|
|
locationHash = 'v0.4';
|
2019-10-15 20:06:16 -04:00
|
|
|
return factory(release).then(() => {
|
2020-03-04 04:08:20 -05:00
|
|
|
expect(commonUtils.scrollToElement).not.toHaveBeenCalled();
|
2019-10-15 20:06:16 -04:00
|
|
|
});
|
2019-10-04 08:06:14 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it("attempts to scroll itself into view if the anchor tag matches the release's tag name", () => {
|
2020-03-04 04:08:20 -05:00
|
|
|
locationHash = release.tagName;
|
2019-10-15 20:06:16 -04:00
|
|
|
return factory(release).then(() => {
|
2020-03-04 04:08:20 -05:00
|
|
|
expect(commonUtils.scrollToElement).toHaveBeenCalledTimes(1);
|
2019-10-04 08:06:14 -04:00
|
|
|
|
2020-03-04 04:08:20 -05:00
|
|
|
expect(commonUtils.scrollToElement).toHaveBeenCalledWith(wrapper.element);
|
2019-10-15 20:06:16 -04:00
|
|
|
});
|
2019-10-04 08:06:14 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders with a light blue background if it is the target of the anchor', () => {
|
2020-03-04 04:08:20 -05:00
|
|
|
locationHash = release.tagName;
|
2019-10-04 08:06:14 -04:00
|
|
|
|
2019-10-15 20:06:16 -04:00
|
|
|
return factory(release).then(() => {
|
2019-10-04 08:06:14 -04:00
|
|
|
expect(hasTargetBlueBackground()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render with a light blue background if it is not the target of the anchor', () => {
|
2020-03-04 04:08:20 -05:00
|
|
|
locationHash = '';
|
2019-10-04 08:06:14 -04:00
|
|
|
|
2019-10-15 20:06:16 -04:00
|
|
|
return factory(release).then(() => {
|
2019-10-04 08:06:14 -04:00
|
|
|
expect(hasTargetBlueBackground()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-09-13 20:06:25 -04:00
|
|
|
});
|