diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/frontend/releases/components | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/frontend/releases/components')
5 files changed, 147 insertions, 27 deletions
diff --git a/spec/frontend/releases/components/app_edit_spec.js b/spec/frontend/releases/components/app_edit_spec.js index 09bafe4aa9b..4450b047acd 100644 --- a/spec/frontend/releases/components/app_edit_spec.js +++ b/spec/frontend/releases/components/app_edit_spec.js @@ -1,11 +1,13 @@ import Vuex from 'vuex'; import { mount } from '@vue/test-utils'; import ReleaseEditApp from '~/releases/components/app_edit.vue'; -import { release as originalRelease } from '../mock_data'; +import { release as originalRelease, milestones as originalMilestones } from '../mock_data'; import * as commonUtils from '~/lib/utils/common_utils'; import { BACK_URL_PARAM } from '~/releases/constants'; import AssetLinksForm from '~/releases/components/asset_links_form.vue'; import { merge } from 'lodash'; +import axios from 'axios'; +import MockAdapter from 'axios-mock-adapter'; describe('Release edit component', () => { let wrapper; @@ -13,6 +15,7 @@ describe('Release edit component', () => { let actions; let getters; let state; + let mock; const factory = ({ featureFlags = {}, store: storeUpdates = {} } = {}) => { state = { @@ -20,6 +23,7 @@ describe('Release edit component', () => { markdownDocsPath: 'path/to/markdown/docs', updateReleaseApiDocsPath: 'path/to/update/release/api/docs', releasesPagePath: 'path/to/releases/page', + projectId: '8', }; actions = { @@ -62,8 +66,11 @@ describe('Release edit component', () => { }; beforeEach(() => { + mock = new MockAdapter(axios); gon.api_version = 'v4'; + mock.onGet('/api/v4/projects/8/milestones').reply(200, originalMilestones); + release = commonUtils.convertObjectPropsToCamelCase(originalRelease, { deep: true }); }); diff --git a/spec/frontend/releases/components/release_block_footer_spec.js b/spec/frontend/releases/components/release_block_footer_spec.js index c63637c4cae..b91cfb82b65 100644 --- a/spec/frontend/releases/components/release_block_footer_spec.js +++ b/spec/frontend/releases/components/release_block_footer_spec.js @@ -3,13 +3,17 @@ import { GlLink } from '@gitlab/ui'; import { trimText } from 'helpers/text_helper'; import ReleaseBlockFooter from '~/releases/components/release_block_footer.vue'; import Icon from '~/vue_shared/components/icon.vue'; -import { release } from '../mock_data'; +import { release as originalRelease } from '../mock_data'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; +import { cloneDeep } from 'lodash'; + +const mockFutureDate = new Date(9999, 0, 0).toISOString(); +let mockIsFutureRelease = false; jest.mock('~/vue_shared/mixins/timeago', () => ({ methods: { timeFormatted() { - return '7 fortnights ago'; + return mockIsFutureRelease ? 'in 1 month' : '7 fortnights ago'; }, tooltipTitle() { return 'February 30, 2401'; @@ -19,12 +23,12 @@ jest.mock('~/vue_shared/mixins/timeago', () => ({ describe('Release block footer', () => { let wrapper; - let releaseClone; + let release; const factory = (props = {}) => { wrapper = mount(ReleaseBlockFooter, { propsData: { - ...convertObjectPropsToCamelCase(releaseClone, { deep: true }), + ...convertObjectPropsToCamelCase(release, { deep: true }), ...props, }, }); @@ -33,11 +37,13 @@ describe('Release block footer', () => { }; beforeEach(() => { - releaseClone = JSON.parse(JSON.stringify(release)); + release = cloneDeep(originalRelease); }); afterEach(() => { wrapper.destroy(); + wrapper = null; + mockIsFutureRelease = false; }); const commitInfoSection = () => wrapper.find('.js-commit-info'); @@ -60,8 +66,8 @@ describe('Release block footer', () => { const commitLink = commitInfoSectionLink(); expect(commitLink.exists()).toBe(true); - expect(commitLink.text()).toBe(releaseClone.commit.short_id); - expect(commitLink.attributes('href')).toBe(releaseClone.commit_path); + expect(commitLink.text()).toBe(release.commit.short_id); + expect(commitLink.attributes('href')).toBe(release.commit_path); }); it('renders the tag icon', () => { @@ -75,28 +81,60 @@ describe('Release block footer', () => { const commitLink = tagInfoSection().find(GlLink); expect(commitLink.exists()).toBe(true); - expect(commitLink.text()).toBe(releaseClone.tag_name); - expect(commitLink.attributes('href')).toBe(releaseClone.tag_path); + expect(commitLink.text()).toBe(release.tag_name); + expect(commitLink.attributes('href')).toBe(release.tag_path); }); it('renders the author and creation time info', () => { expect(trimText(authorDateInfoSection().text())).toBe( - `Created 7 fortnights ago by ${releaseClone.author.username}`, + `Created 7 fortnights ago by ${release.author.username}`, ); }); + 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/), + ); + }); + }); + it("renders the author's avatar image", () => { const avatarImg = authorDateInfoSection().find('img'); expect(avatarImg.exists()).toBe(true); - expect(avatarImg.attributes('src')).toBe(releaseClone.author.avatar_url); + expect(avatarImg.attributes('src')).toBe(release.author.avatar_url); }); it("renders a link to the author's profile", () => { const authorLink = authorDateInfoSection().find(GlLink); expect(authorLink.exists()).toBe(true); - expect(authorLink.attributes('href')).toBe(releaseClone.author.web_url); + expect(authorLink.attributes('href')).toBe(release.author.web_url); }); }); @@ -113,7 +151,7 @@ describe('Release block footer', () => { it('renders the commit SHA as plain text (instead of a link)', () => { expect(commitInfoSectionLink().exists()).toBe(false); - expect(commitInfoSection().text()).toBe(releaseClone.commit.short_id); + expect(commitInfoSection().text()).toBe(release.commit.short_id); }); }); @@ -130,7 +168,7 @@ describe('Release block footer', () => { it('renders the tag name as plain text (instead of a link)', () => { expect(tagInfoSectionLink().exists()).toBe(false); - expect(tagInfoSection().text()).toBe(releaseClone.tag_name); + expect(tagInfoSection().text()).toBe(release.tag_name); }); }); @@ -138,7 +176,18 @@ describe('Release block footer', () => { beforeEach(() => factory({ author: undefined })); it('renders the release date without the author name', () => { - expect(trimText(authorDateInfoSection().text())).toBe('Created 7 fortnights ago'); + 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`); }); }); @@ -147,7 +196,7 @@ describe('Release block footer', () => { it('renders the author name without the release date', () => { expect(trimText(authorDateInfoSection().text())).toBe( - `Created by ${releaseClone.author.username}`, + `Created by ${release.author.username}`, ); }); }); diff --git a/spec/frontend/releases/components/release_block_metadata_spec.js b/spec/frontend/releases/components/release_block_metadata_spec.js new file mode 100644 index 00000000000..cbe478bfa1f --- /dev/null +++ b/spec/frontend/releases/components/release_block_metadata_spec.js @@ -0,0 +1,67 @@ +import { mount } from '@vue/test-utils'; +import { trimText } from 'helpers/text_helper'; +import ReleaseBlockMetadata from '~/releases/components/release_block_metadata.vue'; +import { release as originalRelease } from '../mock_data'; +import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; +import { cloneDeep } from 'lodash'; + +const mockFutureDate = new Date(9999, 0, 0).toISOString(); +let mockIsFutureRelease = false; + +jest.mock('~/vue_shared/mixins/timeago', () => ({ + methods: { + timeFormatted() { + return mockIsFutureRelease ? 'in 1 month' : '7 fortnights ago'; + }, + tooltipTitle() { + return 'February 30, 2401'; + }, + }, +})); + +describe('Release block metadata', () => { + let wrapper; + let release; + + const factory = (releaseUpdates = {}) => { + wrapper = mount(ReleaseBlockMetadata, { + propsData: { + release: { + ...convertObjectPropsToCamelCase(release, { deep: true }), + ...releaseUpdates, + }, + }, + }); + }; + + beforeEach(() => { + release = cloneDeep(originalRelease); + }); + + afterEach(() => { + wrapper.destroy(); + wrapper = null; + mockIsFutureRelease = false; + }); + + const findReleaseDateInfo = () => wrapper.find('.js-release-date-info'); + + describe('with all props provided', () => { + beforeEach(() => factory()); + + it('renders the release time info', () => { + expect(trimText(findReleaseDateInfo().text())).toBe(`released 7 fortnights ago`); + }); + }); + + describe('with a future release date', () => { + beforeEach(() => { + mockIsFutureRelease = true; + factory({ releasedAt: mockFutureDate }); + }); + + it('renders the release date without the author name', () => { + expect(trimText(findReleaseDateInfo().text())).toBe(`will be released in 1 month`); + }); + }); +}); diff --git a/spec/frontend/releases/components/release_block_milestone_info_spec.js b/spec/frontend/releases/components/release_block_milestone_info_spec.js index 0b65b6cab96..0e79c45b337 100644 --- a/spec/frontend/releases/components/release_block_milestone_info_spec.js +++ b/spec/frontend/releases/components/release_block_milestone_info_spec.js @@ -1,5 +1,5 @@ import { mount } from '@vue/test-utils'; -import { GlProgressBar, GlLink, GlBadge, GlDeprecatedButton } from '@gitlab/ui'; +import { GlProgressBar, GlLink, GlBadge, GlButton } from '@gitlab/ui'; import { trimText } from 'helpers/text_helper'; import ReleaseBlockMilestoneInfo from '~/releases/components/release_block_milestone_info.vue'; import { milestones as originalMilestones } from '../mock_data'; @@ -106,7 +106,7 @@ describe('Release block milestone info', () => { const clickShowMoreFewerButton = () => { milestoneListContainer() - .find(GlDeprecatedButton) + .find(GlButton) .trigger('click'); return wrapper.vm.$nextTick(); diff --git a/spec/frontend/releases/components/release_block_spec.js b/spec/frontend/releases/components/release_block_spec.js index 9846fcb65eb..19119d99f3c 100644 --- a/spec/frontend/releases/components/release_block_spec.js +++ b/spec/frontend/releases/components/release_block_spec.js @@ -1,6 +1,5 @@ import $ from 'jquery'; import { mount } from '@vue/test-utils'; -import { first } from 'underscore'; 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'; @@ -80,11 +79,11 @@ describe('Release block', () => { ); expect(wrapper.find('.js-sources-dropdown li a').attributes().href).toEqual( - first(release.assets.sources).url, + release.assets.sources[0].url, ); expect(wrapper.find('.js-sources-dropdown li a').text()).toContain( - first(release.assets.sources).format, + release.assets.sources[0].format, ); }); @@ -92,12 +91,10 @@ describe('Release block', () => { expect(wrapper.findAll('.js-assets-list li').length).toEqual(release.assets.links.length); expect(wrapper.find('.js-assets-list li a').attributes().href).toEqual( - first(release.assets.links).directAssetUrl, + release.assets.links[0].directAssetUrl, ); - expect(wrapper.find('.js-assets-list li a').text()).toContain( - first(release.assets.links).name, - ); + expect(wrapper.find('.js-assets-list li a').text()).toContain(release.assets.links[0].name); }); it('renders author avatar', () => { @@ -264,7 +261,7 @@ describe('Release block', () => { }); it('renders a link to the milestone with a tooltip', () => { - const milestone = first(release.milestones); + const milestone = release.milestones[0]; const milestoneLink = wrapper.find('.js-milestone-link'); expect(milestoneLink.exists()).toBe(true); |