diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-14 03:06:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-14 03:06:25 +0300 |
commit | a93dfc1b7e55b118b1cf4a67afeb46556292914c (patch) | |
tree | 65b874b7940d0d05c4ebedaef43b8a1009362651 /spec/frontend/releases | |
parent | 188a57f93bba5953800de490fcc6246966a073fd (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/releases')
-rw-r--r-- | spec/frontend/releases/components/milestone_list_spec.js | 56 | ||||
-rw-r--r-- | spec/frontend/releases/components/release_block_spec.js | 120 | ||||
-rw-r--r-- | spec/frontend/releases/mock_data.js | 97 |
3 files changed, 273 insertions, 0 deletions
diff --git a/spec/frontend/releases/components/milestone_list_spec.js b/spec/frontend/releases/components/milestone_list_spec.js new file mode 100644 index 00000000000..f267177ddab --- /dev/null +++ b/spec/frontend/releases/components/milestone_list_spec.js @@ -0,0 +1,56 @@ +import { shallowMount } from '@vue/test-utils'; +import { GlLink } from '@gitlab/ui'; +import MilestoneList from '~/releases/components/milestone_list.vue'; +import Icon from '~/vue_shared/components/icon.vue'; +import _ from 'underscore'; +import { milestones } from '../mock_data'; + +describe('Milestone list', () => { + let wrapper; + + const factory = milestonesProp => { + wrapper = shallowMount(MilestoneList, { + propsData: { + milestones: milestonesProp, + }, + sync: false, + }); + }; + + afterEach(() => { + wrapper.destroy(); + }); + + it('renders the milestone icon', () => { + factory(milestones); + + expect(wrapper.find(Icon).exists()).toBe(true); + }); + + it('renders the label as "Milestone" if only a single milestone is passed in', () => { + factory(milestones.slice(0, 1)); + + expect(wrapper.find('.js-label-text').text()).toEqual('Milestone'); + }); + + it('renders the label as "Milestones" if more than one milestone is passed in', () => { + factory(milestones); + + expect(wrapper.find('.js-label-text').text()).toEqual('Milestones'); + }); + + it('renders a link to the milestone with a tooltip', () => { + const milestone = _.first(milestones); + factory([milestone]); + + const milestoneLink = wrapper.find(GlLink); + + expect(milestoneLink.exists()).toBe(true); + + expect(milestoneLink.text()).toBe(milestone.title); + + expect(milestoneLink.attributes('href')).toBe(milestone.web_url); + + expect(milestoneLink.attributes('data-original-title')).toBe(milestone.description); + }); +}); diff --git a/spec/frontend/releases/components/release_block_spec.js b/spec/frontend/releases/components/release_block_spec.js new file mode 100644 index 00000000000..4be5d500fd9 --- /dev/null +++ b/spec/frontend/releases/components/release_block_spec.js @@ -0,0 +1,120 @@ +import { mount } from '@vue/test-utils'; +import ReleaseBlock from '~/releases/components/release_block.vue'; +import timeagoMixin from '~/vue_shared/mixins/timeago'; +import { first } from 'underscore'; +import { release } from '../mock_data'; + +describe('Release block', () => { + let wrapper; + + const factory = releaseProp => { + wrapper = mount(ReleaseBlock, { + propsData: { + release: releaseProp, + }, + sync: false, + }); + }; + + const milestoneListExists = () => wrapper.find('.js-milestone-list').exists(); + + afterEach(() => { + wrapper.destroy(); + }); + + describe('with default props', () => { + beforeEach(() => { + factory(release); + }); + + 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); + }); + + it('renders tag name', () => { + expect(wrapper.text()).toContain(release.tag_name); + }); + + it('renders release date', () => { + expect(wrapper.text()).toContain(timeagoMixin.methods.timeFormated(release.released_at)); + }); + + it('renders number of assets provided', () => { + expect(wrapper.find('.js-assets-count').text()).toContain(release.assets.count); + }); + + it('renders dropdown with the sources', () => { + expect(wrapper.findAll('.js-sources-dropdown li').length).toEqual( + release.assets.sources.length, + ); + + expect(wrapper.find('.js-sources-dropdown li a').attributes().href).toEqual( + first(release.assets.sources).url, + ); + + expect(wrapper.find('.js-sources-dropdown li a').text()).toContain( + first(release.assets.sources).format, + ); + }); + + it('renders list with the links provided', () => { + 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).url, + ); + + expect(wrapper.find('.js-assets-list li a').text()).toContain( + first(release.assets.links).name, + ); + }); + + it('renders author avatar', () => { + expect(wrapper.find('.user-avatar-link').exists()).toBe(true); + }); + + describe('external label', () => { + it('renders external label when link is external', () => { + expect(wrapper.find('.js-assets-list li a').text()).toContain('external source'); + }); + + it('does not render external label when link is not external', () => { + expect(wrapper.find('.js-assets-list li:nth-child(2) a').text()).not.toContain( + 'external source', + ); + }); + }); + + it('renders the milestone list if at least one milestone is associated to the release', () => { + factory(release); + + expect(milestoneListExists()).toBe(true); + }); + }); + + it('does not render the milestone list if no milestones are associated to the release', () => { + const releaseClone = JSON.parse(JSON.stringify(release)); + delete releaseClone.milestone; + + factory(releaseClone); + + expect(milestoneListExists()).toBe(false); + }); + + it('renders upcoming release badge', () => { + const releaseClone = JSON.parse(JSON.stringify(release)); + releaseClone.upcoming_release = true; + + factory(releaseClone); + + expect(wrapper.text()).toContain('Upcoming Release'); + }); +}); diff --git a/spec/frontend/releases/mock_data.js b/spec/frontend/releases/mock_data.js new file mode 100644 index 00000000000..a0885813c7e --- /dev/null +++ b/spec/frontend/releases/mock_data.js @@ -0,0 +1,97 @@ +export const milestones = [ + { + id: 50, + iid: 2, + project_id: 18, + title: '13.6', + description: 'The 13.6 milestone!', + state: 'active', + created_at: '2019-08-27T17:22:38.280Z', + updated_at: '2019-08-27T17:22:38.280Z', + due_date: '2019-09-19', + start_date: '2019-08-31', + web_url: 'http://0.0.0.0:3001/root/release-test/-/milestones/2', + }, + { + id: 49, + iid: 1, + project_id: 18, + title: '13.5', + description: 'The 13.5 milestone!', + state: 'active', + created_at: '2019-08-26T17:55:48.643Z', + updated_at: '2019-08-26T17:55:48.643Z', + due_date: '2019-10-11', + start_date: '2019-08-19', + web_url: 'http://0.0.0.0:3001/root/release-test/-/milestones/1', + }, +]; + +export const release = { + name: 'New release', + tag_name: 'v0.3', + description: 'A super nice release!', + description_html: '<p data-sourcepos="1:1-1:21" dir="auto">A super nice release!</p>', + created_at: '2019-08-26T17:54:04.952Z', + released_at: '2019-08-26T17:54:04.807Z', + author: { + id: 1, + name: 'Administrator', + username: 'root', + state: 'active', + avatar_url: 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + web_url: 'http://0.0.0.0:3001/root', + }, + commit: { + id: 'c22b0728d1b465f82898c884d32b01aa642f96c1', + short_id: 'c22b0728', + created_at: '2019-08-26T17:47:07.000Z', + parent_ids: [], + title: 'Initial commit', + message: 'Initial commit', + author_name: 'Administrator', + author_email: 'admin@example.com', + authored_date: '2019-08-26T17:47:07.000Z', + committer_name: 'Administrator', + committer_email: 'admin@example.com', + committed_date: '2019-08-26T17:47:07.000Z', + }, + upcoming_release: false, + milestone: milestones[0], + assets: { + count: 5, + sources: [ + { + format: 'zip', + url: 'http://0.0.0.0:3001/root/release-test/-/archive/v0.3/release-test-v0.3.zip', + }, + { + format: 'tar.gz', + url: 'http://0.0.0.0:3001/root/release-test/-/archive/v0.3/release-test-v0.3.tar.gz', + }, + { + format: 'tar.bz2', + url: 'http://0.0.0.0:3001/root/release-test/-/archive/v0.3/release-test-v0.3.tar.bz2', + }, + { + format: 'tar', + url: 'http://0.0.0.0:3001/root/release-test/-/archive/v0.3/release-test-v0.3.tar', + }, + ], + links: [ + { + id: 1, + name: 'my link', + url: 'https://google.com', + external: true, + }, + { + id: 2, + name: 'my second link', + url: + 'https://gitlab.com/gitlab-org/gitlab-ce/-/jobs/artifacts/v11.6.0-rc4/download?job=rspec-mysql+41%2F50', + external: false, + }, + ], + }, +}; |