diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-24 21:09:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-24 21:09:05 +0300 |
commit | c2367afbf57ebc65d5b78a743b5d6a91f0aece9f (patch) | |
tree | 165c2c54bf72ab3a3a9417d97f63ece5c9eba9f5 /spec/frontend/releases | |
parent | 51a9512965d86e3094968fa514e4ae8a96d38cf3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/releases')
6 files changed, 63 insertions, 58 deletions
diff --git a/spec/frontend/releases/components/app_edit_spec.js b/spec/frontend/releases/components/app_edit_spec.js index cb940facbd6..b2dbb8cc435 100644 --- a/spec/frontend/releases/components/app_edit_spec.js +++ b/spec/frontend/releases/components/app_edit_spec.js @@ -13,7 +13,7 @@ describe('Release edit component', () => { beforeEach(() => { gon.api_version = 'v4'; - releaseClone = JSON.parse(JSON.stringify(convertObjectPropsToCamelCase(release))); + releaseClone = convertObjectPropsToCamelCase(release, { deep: true }); state = { release: releaseClone, diff --git a/spec/frontend/releases/components/evidence_block_spec.js b/spec/frontend/releases/components/evidence_block_spec.js index 7b896575965..fb62f4a3bfe 100644 --- a/spec/frontend/releases/components/evidence_block_spec.js +++ b/spec/frontend/releases/components/evidence_block_spec.js @@ -2,12 +2,14 @@ import { mount } from '@vue/test-utils'; import { GlLink } from '@gitlab/ui'; import { truncateSha } from '~/lib/utils/text_utility'; import Icon from '~/vue_shared/components/icon.vue'; -import { release } from '../mock_data'; +import { release as originalRelease } from '../mock_data'; import EvidenceBlock from '~/releases/components/evidence_block.vue'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; +import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; describe('Evidence Block', () => { let wrapper; + let release; const factory = (options = {}) => { wrapper = mount(EvidenceBlock, { @@ -16,6 +18,8 @@ describe('Evidence Block', () => { }; beforeEach(() => { + release = convertObjectPropsToCamelCase(originalRelease, { deep: true }); + factory({ propsData: { release, @@ -32,7 +36,7 @@ describe('Evidence Block', () => { }); it('renders the title for the dowload link', () => { - expect(wrapper.find(GlLink).text()).toBe(`${release.tag_name}-evidence.json`); + expect(wrapper.find(GlLink).text()).toBe(`${release.tagName}-evidence.json`); }); it('renders the correct hover text for the download', () => { @@ -40,19 +44,19 @@ describe('Evidence Block', () => { }); it('renders the correct file link for download', () => { - expect(wrapper.find(GlLink).attributes().download).toBe(`${release.tag_name}-evidence.json`); + expect(wrapper.find(GlLink).attributes().download).toBe(`${release.tagName}-evidence.json`); }); describe('sha text', () => { it('renders the short sha initially', () => { - expect(wrapper.find('.js-short').text()).toBe(truncateSha(release.evidence_sha)); + expect(wrapper.find('.js-short').text()).toBe(truncateSha(release.evidenceSha)); }); it('renders the long sha after expansion', () => { wrapper.find('.js-text-expander-prepend').trigger('click'); return wrapper.vm.$nextTick().then(() => { - expect(wrapper.find('.js-expanded').text()).toBe(release.evidence_sha); + expect(wrapper.find('.js-expanded').text()).toBe(release.evidenceSha); }); }); }); @@ -68,7 +72,7 @@ describe('Evidence Block', () => { it('copies the sha', () => { expect(wrapper.find(ClipboardButton).attributes('data-clipboard-text')).toBe( - release.evidence_sha, + release.evidenceSha, ); }); }); diff --git a/spec/frontend/releases/components/release_block_footer_spec.js b/spec/frontend/releases/components/release_block_footer_spec.js index 4125d5c7e74..c63637c4cae 100644 --- a/spec/frontend/releases/components/release_block_footer_spec.js +++ b/spec/frontend/releases/components/release_block_footer_spec.js @@ -24,7 +24,7 @@ describe('Release block footer', () => { const factory = (props = {}) => { wrapper = mount(ReleaseBlockFooter, { propsData: { - ...convertObjectPropsToCamelCase(releaseClone), + ...convertObjectPropsToCamelCase(releaseClone, { deep: true }), ...props, }, }); diff --git a/spec/frontend/releases/components/release_block_header_spec.js b/spec/frontend/releases/components/release_block_header_spec.js index 157df15ff3c..78adad13f69 100644 --- a/spec/frontend/releases/components/release_block_header_spec.js +++ b/spec/frontend/releases/components/release_block_header_spec.js @@ -1,5 +1,5 @@ import { shallowMount } from '@vue/test-utils'; -import { cloneDeep, merge } from 'lodash'; +import { merge } from 'lodash'; import { GlLink } from '@gitlab/ui'; import ReleaseBlockHeader from '~/releases/components/release_block_header.vue'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; @@ -18,9 +18,7 @@ describe('Release block header', () => { }; beforeEach(() => { - release = convertObjectPropsToCamelCase(cloneDeep(originalRelease), { - ignoreKeyNames: ['_links'], - }); + release = convertObjectPropsToCamelCase(originalRelease, { deep: true }); }); afterEach(() => { @@ -39,13 +37,13 @@ describe('Release block header', () => { const link = findHeaderLink(); expect(link.text()).toBe(release.name); - expect(link.attributes('href')).toBe(release._links.self); + expect(link.attributes('href')).toBe(release.Links.self); }); }); describe('when _links.self is missing', () => { beforeEach(() => { - factory({ _links: { self: null } }); + factory({ Links: { self: null } }); }); it('renders the title as text', () => { 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 5a3204a4ce2..10f5db96b31 100644 --- a/spec/frontend/releases/components/release_block_milestone_info_spec.js +++ b/spec/frontend/releases/components/release_block_milestone_info_spec.js @@ -2,12 +2,13 @@ import { mount } from '@vue/test-utils'; 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 } from '../mock_data'; +import { milestones as originalMilestones } from '../mock_data'; import { MAX_MILESTONES_TO_DISPLAY } from '~/releases/constants'; +import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; describe('Release block milestone info', () => { let wrapper; - let milestonesClone; + let milestones; const factory = milestonesProp => { wrapper = mount(ReleaseBlockMilestoneInfo, { @@ -20,7 +21,7 @@ describe('Release block milestone info', () => { }; beforeEach(() => { - milestonesClone = JSON.parse(JSON.stringify(milestones)); + milestones = convertObjectPropsToCamelCase(originalMilestones, { deep: true }); }); afterEach(() => { @@ -32,7 +33,7 @@ describe('Release block milestone info', () => { const issuesContainer = () => wrapper.find('.js-issues-container'); describe('with default props', () => { - beforeEach(() => factory(milestonesClone)); + beforeEach(() => factory(milestones)); it('renders the correct percentage', () => { expect(milestoneProgressBarContainer().text()).toContain('41% complete'); @@ -53,13 +54,13 @@ describe('Release block milestone info', () => { it('renders a list of links to all associated milestones', () => { expect(trimText(milestoneListContainer().text())).toContain('Milestones 13.6 • 13.5'); - milestonesClone.forEach((m, i) => { + milestones.forEach((m, i) => { const milestoneLink = milestoneListContainer() .findAll(GlLink) .at(i); expect(milestoneLink.text()).toBe(m.title); - expect(milestoneLink.attributes('href')).toBe(m.web_url); + expect(milestoneLink.attributes('href')).toBe(m.webUrl); expect(milestoneLink.attributes('title')).toBe(m.description); }); }); @@ -84,7 +85,7 @@ describe('Release block milestone info', () => { beforeEach(() => { lotsOfMilestones = []; - const template = milestonesClone[0]; + const template = milestones[0]; for (let i = 0; i < MAX_MILESTONES_TO_DISPLAY + 10; i += 1) { lotsOfMilestones.push({ @@ -148,16 +149,16 @@ describe('Release block milestone info', () => { /** Ensures we don't have any issues with dividing by zero when computing percentages */ describe('when all issue counts are zero', () => { beforeEach(() => { - milestonesClone = milestonesClone.map(m => ({ + milestones = milestones.map(m => ({ ...m, - issue_stats: { - ...m.issue_stats, + issueStats: { + ...m.issueStats, opened: 0, closed: 0, }, })); - return factory(milestonesClone); + return factory(milestones); }); expectAllZeros(); @@ -165,12 +166,12 @@ describe('Release block milestone info', () => { describe('if the API response is missing the "issue_stats" property', () => { beforeEach(() => { - milestonesClone = milestonesClone.map(m => ({ + milestones = milestones.map(m => ({ ...m, - issue_stats: undefined, + issueStats: undefined, })); - return factory(milestonesClone); + return factory(milestones); }); expectAllZeros(); diff --git a/spec/frontend/releases/components/release_block_spec.js b/spec/frontend/releases/components/release_block_spec.js index aba1b8aff41..5d365b77560 100644 --- a/spec/frontend/releases/components/release_block_spec.js +++ b/spec/frontend/releases/components/release_block_spec.js @@ -5,10 +5,12 @@ 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'; import timeagoMixin from '~/vue_shared/mixins/timeago'; -import { release } from '../mock_data'; +import { release as originalRelease } from '../mock_data'; import Icon from '~/vue_shared/components/icon.vue'; import { scrollToElement } from '~/lib/utils/common_utils'; +const { convertObjectPropsToCamelCase } = jest.requireActual('~/lib/utils/common_utils'); + let mockLocationHash; jest.mock('~/lib/utils/url_utility', () => ({ __esModule: true, @@ -22,7 +24,7 @@ jest.mock('~/lib/utils/common_utils', () => ({ describe('Release block', () => { let wrapper; - let releaseClone; + let release; const factory = (releaseProp, featureFlags = {}) => { wrapper = mount(ReleaseBlock, { @@ -45,7 +47,7 @@ describe('Release block', () => { beforeEach(() => { jest.spyOn($.fn, 'renderGFM'); - releaseClone = JSON.parse(JSON.stringify(release)); + release = convertObjectPropsToCamelCase(originalRelease, { deep: true }); }); afterEach(() => { @@ -61,7 +63,7 @@ describe('Release block', () => { it('renders an edit button that links to the "Edit release" page', () => { expect(editButton().exists()).toBe(true); - expect(editButton().attributes('href')).toBe(release._links.edit_url); + expect(editButton().attributes('href')).toBe(release.Links.editUrl); }); it('renders release name', () => { @@ -74,7 +76,7 @@ describe('Release block', () => { }); it('renders release date', () => { - expect(wrapper.text()).toContain(timeagoMixin.methods.timeFormatted(release.released_at)); + expect(wrapper.text()).toContain(timeagoMixin.methods.timeFormatted(release.releasedAt)); }); it('renders number of assets provided', () => { @@ -129,72 +131,72 @@ describe('Release block', () => { }); it('renders commit sha', () => { - releaseClone.commit_path = '/commit/example'; + release.commitPath = '/commit/example'; - return factory(releaseClone).then(() => { - expect(wrapper.text()).toContain(release.commit.short_id); + return factory(release).then(() => { + expect(wrapper.text()).toContain(release.commit.shortId); expect(wrapper.find('a[href="/commit/example"]').exists()).toBe(true); }); }); it('renders tag name', () => { - releaseClone.tag_path = '/tag/example'; + release.tagPath = '/tag/example'; - return factory(releaseClone).then(() => { - expect(wrapper.text()).toContain(release.tag_name); + return factory(release).then(() => { + expect(wrapper.text()).toContain(release.tagName); expect(wrapper.find('a[href="/tag/example"]').exists()).toBe(true); }); }); - it("does not render an edit button if release._links.edit_url isn't a string", () => { - delete releaseClone._links; + it("does not render an edit button if release.Links.editUrl isn't a string", () => { + delete release.Links; - return factory(releaseClone).then(() => { + return factory(release).then(() => { expect(editButton().exists()).toBe(false); }); }); it('does not render the milestone list if no milestones are associated to the release', () => { - delete releaseClone.milestones; + delete release.milestones; - return factory(releaseClone).then(() => { + return factory(release).then(() => { expect(milestoneListLabel().exists()).toBe(false); }); }); it('renders upcoming release badge', () => { - releaseClone.upcoming_release = true; + release.upcomingRelease = true; - return factory(releaseClone).then(() => { + return factory(release).then(() => { expect(wrapper.text()).toContain('Upcoming Release'); }); }); - it('slugifies the tag_name before setting it as the elements ID', () => { - releaseClone.tag_name = 'a dangerous tag name <script>alert("hello")</script>'; + it('slugifies the tagName before setting it as the elements ID', () => { + release.tagName = 'a dangerous tag name <script>alert("hello")</script>'; - return factory(releaseClone).then(() => { + return factory(release).then(() => { expect(wrapper.attributes().id).toBe('a-dangerous-tag-name-script-alert-hello-script'); }); }); describe('evidence block', () => { it('renders the evidence block when the evidence is available and the feature flag is true', () => - factory(releaseClone, { releaseEvidenceCollection: true }).then(() => + factory(release, { releaseEvidenceCollection: true }).then(() => expect(wrapper.find(EvidenceBlock).exists()).toBe(true), )); it('does not render the evidence block when the evidence is available but the feature flag is false', () => - factory(releaseClone, { releaseEvidenceCollection: true }).then(() => + factory(release, { releaseEvidenceCollection: true }).then(() => expect(wrapper.find(EvidenceBlock).exists()).toBe(true), )); it('does not render the evidence block when there is no evidence', () => { - releaseClone.evidence_sha = null; + release.evidenceSha = null; - return factory(releaseClone).then(() => { + return factory(release).then(() => { expect(wrapper.find(EvidenceBlock).exists()).toBe(false); }); }); @@ -222,7 +224,7 @@ describe('Release block', () => { }); it("attempts to scroll itself into view if the anchor tag matches the release's tag name", () => { - mockLocationHash = release.tag_name; + mockLocationHash = release.tagName; return factory(release).then(() => { expect(scrollToElement).toHaveBeenCalledTimes(1); @@ -231,7 +233,7 @@ describe('Release block', () => { }); it('renders with a light blue background if it is the target of the anchor', () => { - mockLocationHash = release.tag_name; + mockLocationHash = release.tagName; return factory(release).then(() => { expect(hasTargetBlueBackground()).toBe(true); @@ -275,16 +277,16 @@ describe('Release block', () => { expect(milestoneLink.text()).toBe(milestone.title); - expect(milestoneLink.attributes('href')).toBe(milestone.web_url); + expect(milestoneLink.attributes('href')).toBe(milestone.webUrl); expect(milestoneLink.attributes('title')).toBe(milestone.description); }); }); it('renders the label as "Milestone" if only a single milestone is passed in', () => { - releaseClone.milestones = releaseClone.milestones.slice(0, 1); + release.milestones = release.milestones.slice(0, 1); - return factory(releaseClone, { releaseIssueSummary: false }).then(() => { + return factory(release, { releaseIssueSummary: false }).then(() => { expect( milestoneListLabel() .find('.js-label-text') |