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

211 lines
6.5 KiB
JavaScript
Raw Normal View History

2019-12-26 22:10:19 +05:30
import { mount } from '@vue/test-utils';
2020-11-24 15:15:51 +05:30
import { GlLink, GlIcon } from '@gitlab/ui';
2019-12-26 22:10:19 +05:30
import { trimText } from 'helpers/text_helper';
2020-10-24 23:57:45 +05:30
import { cloneDeep } from 'lodash';
2020-03-13 15:44:24 +05:30
import ReleaseBlockFooter from '~/releases/components/release_block_footer.vue';
2020-05-24 23:13:21 +05:30
import { release as originalRelease } from '../mock_data';
2019-12-26 22:10:19 +05:30
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
2020-05-24 23:13:21 +05:30
const mockFutureDate = new Date(9999, 0, 0).toISOString();
let mockIsFutureRelease = false;
2019-12-26 22:10:19 +05:30
jest.mock('~/vue_shared/mixins/timeago', () => ({
methods: {
2020-01-01 13:55:28 +05:30
timeFormatted() {
2020-05-24 23:13:21 +05:30
return mockIsFutureRelease ? 'in 1 month' : '7 fortnights ago';
2019-12-26 22:10:19 +05:30
},
tooltipTitle() {
return 'February 30, 2401';
},
},
}));
describe('Release block footer', () => {
let wrapper;
2020-05-24 23:13:21 +05:30
let release;
2019-12-26 22:10:19 +05:30
const factory = (props = {}) => {
wrapper = mount(ReleaseBlockFooter, {
propsData: {
2020-05-24 23:13:21 +05:30
...convertObjectPropsToCamelCase(release, { deep: true }),
2019-12-26 22:10:19 +05:30
...props,
},
});
return wrapper.vm.$nextTick();
};
beforeEach(() => {
2020-05-24 23:13:21 +05:30
release = cloneDeep(originalRelease);
2019-12-26 22:10:19 +05:30
});
afterEach(() => {
wrapper.destroy();
2020-05-24 23:13:21 +05:30
wrapper = null;
mockIsFutureRelease = false;
2019-12-26 22:10:19 +05:30
});
const commitInfoSection = () => wrapper.find('.js-commit-info');
const commitInfoSectionLink = () => commitInfoSection().find(GlLink);
const tagInfoSection = () => wrapper.find('.js-tag-info');
const tagInfoSectionLink = () => tagInfoSection().find(GlLink);
const authorDateInfoSection = () => wrapper.find('.js-author-date-info');
describe('with all props provided', () => {
beforeEach(() => factory());
it('renders the commit icon', () => {
2020-11-24 15:15:51 +05:30
const commitIcon = commitInfoSection().find(GlIcon);
2019-12-26 22:10:19 +05:30
expect(commitIcon.exists()).toBe(true);
expect(commitIcon.props('name')).toBe('commit');
});
it('renders the commit SHA with a link', () => {
const commitLink = commitInfoSectionLink();
expect(commitLink.exists()).toBe(true);
2020-05-24 23:13:21 +05:30
expect(commitLink.text()).toBe(release.commit.short_id);
expect(commitLink.attributes('href')).toBe(release.commit_path);
2019-12-26 22:10:19 +05:30
});
it('renders the tag icon', () => {
2020-11-24 15:15:51 +05:30
const commitIcon = tagInfoSection().find(GlIcon);
2019-12-26 22:10:19 +05:30
expect(commitIcon.exists()).toBe(true);
expect(commitIcon.props('name')).toBe('tag');
});
it('renders the tag name with a link', () => {
const commitLink = tagInfoSection().find(GlLink);
expect(commitLink.exists()).toBe(true);
2020-05-24 23:13:21 +05:30
expect(commitLink.text()).toBe(release.tag_name);
expect(commitLink.attributes('href')).toBe(release.tag_path);
2019-12-26 22:10:19 +05:30
});
it('renders the author and creation time info', () => {
expect(trimText(authorDateInfoSection().text())).toBe(
2020-05-24 23:13:21 +05:30
`Created 7 fortnights ago by ${release.author.username}`,
2019-12-26 22:10:19 +05:30
);
});
2020-05-24 23:13:21 +05:30
describe('when the release date is in the past', () => {
it('prefixes the creation info with "Created"', () => {
expect(trimText(authorDateInfoSection().text())).toEqual(expect.stringMatching(/^Created/));
});
});
describe('renders the author and creation time info with future release date', () => {
beforeEach(() => {
mockIsFutureRelease = true;
factory({ releasedAt: mockFutureDate });
});
it('renders the release date without the author name', () => {
expect(trimText(authorDateInfoSection().text())).toBe(
`Will be created in 1 month by ${release.author.username}`,
);
});
});
describe('when the release date is in the future', () => {
beforeEach(() => {
mockIsFutureRelease = true;
factory({ releasedAt: mockFutureDate });
});
it('prefixes the creation info with "Will be created"', () => {
expect(trimText(authorDateInfoSection().text())).toEqual(
expect.stringMatching(/^Will be created/),
);
});
});
2019-12-26 22:10:19 +05:30
it("renders the author's avatar image", () => {
const avatarImg = authorDateInfoSection().find('img');
expect(avatarImg.exists()).toBe(true);
2020-05-24 23:13:21 +05:30
expect(avatarImg.attributes('src')).toBe(release.author.avatar_url);
2019-12-26 22:10:19 +05:30
});
it("renders a link to the author's profile", () => {
const authorLink = authorDateInfoSection().find(GlLink);
expect(authorLink.exists()).toBe(true);
2020-05-24 23:13:21 +05:30
expect(authorLink.attributes('href')).toBe(release.author.web_url);
2019-12-26 22:10:19 +05:30
});
});
describe('without any commit info', () => {
beforeEach(() => factory({ commit: undefined }));
it('does not render any commit info', () => {
expect(commitInfoSection().exists()).toBe(false);
});
});
describe('without a commit URL', () => {
beforeEach(() => factory({ commitPath: undefined }));
it('renders the commit SHA as plain text (instead of a link)', () => {
expect(commitInfoSectionLink().exists()).toBe(false);
2020-05-24 23:13:21 +05:30
expect(commitInfoSection().text()).toBe(release.commit.short_id);
2019-12-26 22:10:19 +05:30
});
});
describe('without a tag name', () => {
beforeEach(() => factory({ tagName: undefined }));
it('does not render any tag info', () => {
expect(tagInfoSection().exists()).toBe(false);
});
});
describe('without a tag URL', () => {
beforeEach(() => factory({ tagPath: undefined }));
it('renders the tag name as plain text (instead of a link)', () => {
expect(tagInfoSectionLink().exists()).toBe(false);
2020-05-24 23:13:21 +05:30
expect(tagInfoSection().text()).toBe(release.tag_name);
2019-12-26 22:10:19 +05:30
});
});
describe('without any author info', () => {
beforeEach(() => factory({ author: undefined }));
it('renders the release date without the author name', () => {
2020-05-24 23:13:21 +05:30
expect(trimText(authorDateInfoSection().text())).toBe(`Created 7 fortnights ago`);
});
});
describe('future release without any author info', () => {
beforeEach(() => {
mockIsFutureRelease = true;
factory({ author: undefined, releasedAt: mockFutureDate });
});
it('renders the release date without the author name', () => {
expect(trimText(authorDateInfoSection().text())).toBe(`Will be created in 1 month`);
2019-12-26 22:10:19 +05:30
});
});
describe('without a released at date', () => {
beforeEach(() => factory({ releasedAt: undefined }));
it('renders the author name without the release date', () => {
expect(trimText(authorDateInfoSection().text())).toBe(
2020-05-24 23:13:21 +05:30
`Created by ${release.author.username}`,
2019-12-26 22:10:19 +05:30
);
});
});
describe('without a release date or author info', () => {
beforeEach(() => factory({ author: undefined, releasedAt: undefined }));
it('does not render any author or release date info', () => {
expect(authorDateInfoSection().exists()).toBe(false);
});
});
});