From c920712fab6abdc37de9444e6bbcd170c295b21a Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 16 Oct 2019 00:06:16 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../__snapshots__/release_block_spec.js.snap | 332 +++++++++++++++++++++ .../releases/list/components/release_block_spec.js | 135 +++++---- spec/frontend/releases/mock_data.js | 3 + 3 files changed, 420 insertions(+), 50 deletions(-) create mode 100644 spec/frontend/releases/list/components/__snapshots__/release_block_spec.js.snap (limited to 'spec/frontend/releases') diff --git a/spec/frontend/releases/list/components/__snapshots__/release_block_spec.js.snap b/spec/frontend/releases/list/components/__snapshots__/release_block_spec.js.snap new file mode 100644 index 00000000000..8f2c0427c83 --- /dev/null +++ b/spec/frontend/releases/list/components/__snapshots__/release_block_spec.js.snap @@ -0,0 +1,332 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Release block with default props matches the snapshot 1`] = ` +
+
+
+

+ + New release + + +

+ + + + +
+ +
+
+ + + + c22b0728 + +
+ +
+ + + + v0.3 + +
+ +
+ + + + Milestones + +
+ + + + 13.6 + + + + • + + + + 13.5 + + + + + +
+ + • + + + + released 1 month ago + + +
+ + +
+ +
+ + + Assets + + + 5 + + + + + + +
+ +
+
+

+ A super nice release! +

+
+
+
+
+`; diff --git a/spec/frontend/releases/list/components/release_block_spec.js b/spec/frontend/releases/list/components/release_block_spec.js index eae0025feac..0b908d7d6bc 100644 --- a/spec/frontend/releases/list/components/release_block_spec.js +++ b/spec/frontend/releases/list/components/release_block_spec.js @@ -19,46 +19,53 @@ jest.mock('~/lib/utils/common_utils', () => ({ describe('Release block', () => { let wrapper; + let releaseClone; - const factory = releaseProp => { + const factory = (releaseProp, releaseEditPageFeatureFlag = true) => { wrapper = mount(ReleaseBlock, { propsData: { release: releaseProp, }, + provide: { + glFeatures: { + releaseEditPage: releaseEditPageFeatureFlag, + }, + }, + sync: false, }); + + return wrapper.vm.$nextTick(); }; const milestoneListLabel = () => wrapper.find('.js-milestone-list-label'); + const editButton = () => wrapper.find('.js-edit-button'); + + beforeEach(() => { + releaseClone = JSON.parse(JSON.stringify(release)); + }); afterEach(() => { wrapper.destroy(); }); describe('with default props', () => { - beforeEach(() => { - factory(release); + beforeEach(() => factory(release)); + + it('matches the snapshot', () => { + expect(wrapper.element).toMatchSnapshot(); }); it("renders the block with an id equal to the release's tag name", () => { expect(wrapper.attributes().id).toBe('v0.3'); }); - it('renders release name', () => { - expect(wrapper.text()).toContain(release.name); - }); - - it('renders commit sha', () => { - expect(wrapper.text()).toContain(release.commit.short_id); - - wrapper.setProps({ release: { ...release, commit_path: '/commit/example' } }); - expect(wrapper.find('a[href="/commit/example"]').exists()).toBe(true); + 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); }); - it('renders tag name', () => { - expect(wrapper.text()).toContain(release.tag_name); - - wrapper.setProps({ release: { ...release, tag_path: '/tag/example' } }); - expect(wrapper.find('a[href="/tag/example"]').exists()).toBe(true); + it('renders release name', () => { + expect(wrapper.text()).toContain(release.name); }); it('renders release date', () => { @@ -141,44 +148,73 @@ describe('Release block', () => { }); }); + it('renders commit sha', () => { + releaseClone.commit_path = '/commit/example'; + + return factory(releaseClone).then(() => { + expect(wrapper.text()).toContain(release.commit.short_id); + + expect(wrapper.find('a[href="/commit/example"]').exists()).toBe(true); + }); + }); + + it('renders tag name', () => { + releaseClone.tag_path = '/tag/example'; + + return factory(releaseClone).then(() => { + expect(wrapper.text()).toContain(release.tag_name); + + expect(wrapper.find('a[href="/tag/example"]').exists()).toBe(true); + }); + }); + + it("does not render an edit button if release._links.edit isn't a string", () => { + delete releaseClone._links; + + return factory(releaseClone).then(() => { + expect(editButton().exists()).toBe(false); + }); + }); + + it('does not render an edit button if the releaseEditPage feature flag is disabled', () => + factory(releaseClone, false).then(() => { + expect(editButton().exists()).toBe(false); + })); + it('does not render the milestone list if no milestones are associated to the release', () => { - const releaseClone = JSON.parse(JSON.stringify(release)); delete releaseClone.milestones; - factory(releaseClone); - - expect(milestoneListLabel().exists()).toBe(false); + return factory(releaseClone).then(() => { + expect(milestoneListLabel().exists()).toBe(false); + }); }); it('renders the label as "Milestone" if only a single milestone is passed in', () => { - const releaseClone = JSON.parse(JSON.stringify(release)); releaseClone.milestones = releaseClone.milestones.slice(0, 1); - factory(releaseClone); - - expect( - milestoneListLabel() - .find('.js-label-text') - .text(), - ).toEqual('Milestone'); + return factory(releaseClone).then(() => { + expect( + milestoneListLabel() + .find('.js-label-text') + .text(), + ).toEqual('Milestone'); + }); }); it('renders upcoming release badge', () => { - const releaseClone = JSON.parse(JSON.stringify(release)); releaseClone.upcoming_release = true; - factory(releaseClone); - - expect(wrapper.text()).toContain('Upcoming Release'); + return factory(releaseClone).then(() => { + expect(wrapper.text()).toContain('Upcoming Release'); + }); }); it('slugifies the tag_name before setting it as the elements ID', () => { - const releaseClone = JSON.parse(JSON.stringify(release)); releaseClone.tag_name = 'a dangerous tag name '; - factory(releaseClone); - - expect(wrapper.attributes().id).toBe('a-dangerous-tag-name-script-alert-hello-script-'); + return factory(releaseClone).then(() => { + expect(wrapper.attributes().id).toBe('a-dangerous-tag-name-script-alert-hello-script-'); + }); }); describe('anchor scrolling', () => { @@ -190,40 +226,39 @@ describe('Release block', () => { it('does not attempt to scroll the page if no anchor tag is included in the URL', () => { mockLocationHash = ''; - factory(release); - - expect(scrollToElement).not.toHaveBeenCalled(); + return factory(release).then(() => { + expect(scrollToElement).not.toHaveBeenCalled(); + }); }); it("does not attempt to scroll the page if the anchor tag doesn't match the release's tag name", () => { mockLocationHash = 'v0.4'; - factory(release); - - expect(scrollToElement).not.toHaveBeenCalled(); + return factory(release).then(() => { + expect(scrollToElement).not.toHaveBeenCalled(); + }); }); it("attempts to scroll itself into view if the anchor tag matches the release's tag name", () => { mockLocationHash = release.tag_name; - factory(release); + return factory(release).then(() => { + expect(scrollToElement).toHaveBeenCalledTimes(1); - expect(scrollToElement).toHaveBeenCalledTimes(1); - expect(scrollToElement).toHaveBeenCalledWith(wrapper.element); + expect(scrollToElement).toHaveBeenCalledWith(wrapper.element); + }); }); it('renders with a light blue background if it is the target of the anchor', () => { mockLocationHash = release.tag_name; - factory(release); - return wrapper.vm.$nextTick().then(() => { + return factory(release).then(() => { expect(hasTargetBlueBackground()).toBe(true); }); }); it('does not render with a light blue background if it is not the target of the anchor', () => { mockLocationHash = ''; - factory(release); - return wrapper.vm.$nextTick().then(() => { + return factory(release).then(() => { expect(hasTargetBlueBackground()).toBe(false); }); }); diff --git a/spec/frontend/releases/mock_data.js b/spec/frontend/releases/mock_data.js index 328199343f5..b2ebf1174d4 100644 --- a/spec/frontend/releases/mock_data.js +++ b/spec/frontend/releases/mock_data.js @@ -94,4 +94,7 @@ export const release = { }, ], }, + _links: { + edit: 'http://0.0.0.0:3001/root/release-test/-/releases/v0.3/edit', + }, }; -- cgit v1.2.3