diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 15:09:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 15:09:42 +0300 |
commit | 729e3765d5feb762df1ccfbc228a8dd4662aa3f9 (patch) | |
tree | f326420fc64999c6bcc28816ed54f0972fb46459 /spec/frontend | |
parent | 6f7881ee9dcec34141a8f34fc814b56b366d2b48 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/locale/index_spec.js | 31 | ||||
-rw-r--r-- | spec/frontend/notes/components/discussion_counter_spec.js | 59 | ||||
-rw-r--r-- | spec/frontend/notes/stores/mutation_spec.js | 46 | ||||
-rw-r--r-- | spec/frontend/releases/components/evidence_block_spec.js | 15 | ||||
-rw-r--r-- | spec/frontend/releases/mock_data.js | 23 |
5 files changed, 158 insertions, 16 deletions
diff --git a/spec/frontend/locale/index_spec.js b/spec/frontend/locale/index_spec.js new file mode 100644 index 00000000000..346ed5182f4 --- /dev/null +++ b/spec/frontend/locale/index_spec.js @@ -0,0 +1,31 @@ +import { createDateTimeFormat, languageCode } from '~/locale'; + +import { setLanguage } from 'helpers/locale_helper'; + +describe('locale', () => { + afterEach(() => setLanguage(null)); + + describe('languageCode', () => { + it('parses the lang attribute', () => { + setLanguage('ja'); + + expect(languageCode()).toBe('ja'); + }); + + it('falls back to English', () => { + setLanguage(null); + + expect(languageCode()).toBe('en'); + }); + }); + + describe('createDateTimeFormat', () => { + beforeEach(() => setLanguage('en')); + + it('creates an instance of Intl.DateTimeFormat', () => { + const dateFormat = createDateTimeFormat({ year: 'numeric', month: 'long', day: 'numeric' }); + + expect(dateFormat.format(new Date(2015, 6, 3))).toBe('July 3, 2015'); + }); + }); +}); diff --git a/spec/frontend/notes/components/discussion_counter_spec.js b/spec/frontend/notes/components/discussion_counter_spec.js index c9375df07e8..77603c16f82 100644 --- a/spec/frontend/notes/components/discussion_counter_spec.js +++ b/spec/frontend/notes/components/discussion_counter_spec.js @@ -75,17 +75,66 @@ describe('DiscussionCounter component', () => { }); it.each` - title | resolved | hasNextBtn | isActive | icon | groupLength - ${'hasNextButton'} | ${false} | ${true} | ${false} | ${'check-circle'} | ${2} - ${'allResolved'} | ${true} | ${false} | ${true} | ${'check-circle-filled'} | ${0} - `('renders correctly if $title', ({ resolved, hasNextBtn, isActive, icon, groupLength }) => { + title | resolved | isActive | icon | groupLength + ${'not allResolved'} | ${false} | ${false} | ${'check-circle'} | ${3} + ${'allResolved'} | ${true} | ${true} | ${'check-circle-filled'} | ${1} + `('renders correctly if $title', ({ resolved, isActive, icon, groupLength }) => { updateStore({ resolvable: true, resolved }); wrapper = shallowMount(DiscussionCounter, { store, localVue }); - expect(wrapper.find(`.has-next-btn`).exists()).toBe(hasNextBtn); expect(wrapper.find(`.is-active`).exists()).toBe(isActive); expect(wrapper.find({ name: icon }).exists()).toBe(true); expect(wrapper.findAll('[role="group"').length).toBe(groupLength); }); }); + + describe('toggle all threads button', () => { + let toggleAllButton; + const updateStoreWithExpanded = expanded => { + const discussion = { ...discussionMock, expanded }; + store.commit(types.SET_INITIAL_DISCUSSIONS, [discussion]); + store.dispatch('updateResolvableDiscussionsCounts'); + wrapper = shallowMount(DiscussionCounter, { store, localVue }); + toggleAllButton = wrapper.find('.toggle-all-discussions-btn'); + }; + + afterEach(() => wrapper.destroy()); + + it('calls button handler when clicked', () => { + updateStoreWithExpanded(true); + + wrapper.setMethods({ handleExpandDiscussions: jest.fn() }); + toggleAllButton.trigger('click'); + + expect(wrapper.vm.handleExpandDiscussions).toHaveBeenCalledTimes(1); + }); + + it('collapses all discussions if expanded', () => { + updateStoreWithExpanded(true); + + expect(wrapper.vm.allExpanded).toBe(true); + expect(toggleAllButton.find({ name: 'angle-up' }).exists()).toBe(true); + + toggleAllButton.trigger('click'); + + return wrapper.vm.$nextTick().then(() => { + expect(wrapper.vm.allExpanded).toBe(false); + expect(toggleAllButton.find({ name: 'angle-down' }).exists()).toBe(true); + }); + }); + + it('expands all discussions if collapsed', () => { + updateStoreWithExpanded(false); + + expect(wrapper.vm.allExpanded).toBe(false); + expect(toggleAllButton.find({ name: 'angle-down' }).exists()).toBe(true); + + toggleAllButton.trigger('click'); + + return wrapper.vm.$nextTick().then(() => { + expect(wrapper.vm.allExpanded).toBe(true); + expect(toggleAllButton.find({ name: 'angle-up' }).exists()).toBe(true); + }); + }); + }); }); diff --git a/spec/frontend/notes/stores/mutation_spec.js b/spec/frontend/notes/stores/mutation_spec.js index ee772afbc03..ea5658821b1 100644 --- a/spec/frontend/notes/stores/mutation_spec.js +++ b/spec/frontend/notes/stores/mutation_spec.js @@ -329,6 +329,52 @@ describe('Notes Store mutations', () => { }); }); + describe('SET_EXPAND_DISCUSSIONS', () => { + it('should succeed when discussions are null', () => { + const state = {}; + + mutations.SET_EXPAND_DISCUSSIONS(state, { discussionIds: null, expanded: true }); + + expect(state).toEqual({}); + }); + + it('should succeed when discussions are empty', () => { + const state = {}; + + mutations.SET_EXPAND_DISCUSSIONS(state, { discussionIds: [], expanded: true }); + + expect(state).toEqual({}); + }); + + it('should open all closed discussions', () => { + const discussion1 = Object.assign({}, discussionMock, { id: 0, expanded: false }); + const discussion2 = Object.assign({}, discussionMock, { id: 1, expanded: true }); + const discussionIds = [discussion1.id, discussion2.id]; + + const state = { discussions: [discussion1, discussion2] }; + + mutations.SET_EXPAND_DISCUSSIONS(state, { discussionIds, expanded: true }); + + state.discussions.forEach(discussion => { + expect(discussion.expanded).toEqual(true); + }); + }); + + it('should close all opened discussions', () => { + const discussion1 = Object.assign({}, discussionMock, { id: 0, expanded: false }); + const discussion2 = Object.assign({}, discussionMock, { id: 1, expanded: true }); + const discussionIds = [discussion1.id, discussion2.id]; + + const state = { discussions: [discussion1, discussion2] }; + + mutations.SET_EXPAND_DISCUSSIONS(state, { discussionIds, expanded: false }); + + state.discussions.forEach(discussion => { + expect(discussion.expanded).toEqual(false); + }); + }); + }); + describe('UPDATE_NOTE', () => { it('should update a note', () => { const state = { diff --git a/spec/frontend/releases/components/evidence_block_spec.js b/spec/frontend/releases/components/evidence_block_spec.js index c76a0e04dce..ba60a79e464 100644 --- a/spec/frontend/releases/components/evidence_block_spec.js +++ b/spec/frontend/releases/components/evidence_block_spec.js @@ -1,7 +1,6 @@ import { mount } from '@vue/test-utils'; -import { GlLink } from '@gitlab/ui'; +import { GlLink, GlIcon } from '@gitlab/ui'; import { truncateSha } from '~/lib/utils/text_utility'; -import Icon from '~/vue_shared/components/icon.vue'; import { release as originalRelease } from '../mock_data'; import EvidenceBlock from '~/releases/components/evidence_block.vue'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; @@ -32,11 +31,11 @@ describe('Evidence Block', () => { }); it('renders the evidence icon', () => { - expect(wrapper.find(Icon).props('name')).toBe('review-list'); + expect(wrapper.find(GlIcon).props('name')).toBe('review-list'); }); it('renders the title for the dowload link', () => { - expect(wrapper.find(GlLink).text()).toBe(`${release.tagName}-evidence.json`); + expect(wrapper.find(GlLink).text()).toBe('v1.1.2-evidences-1.json'); }); it('renders the correct hover text for the download', () => { @@ -44,19 +43,19 @@ describe('Evidence Block', () => { }); it('renders the correct file link for download', () => { - expect(wrapper.find(GlLink).attributes().download).toBe(`${release.tagName}-evidence.json`); + expect(wrapper.find(GlLink).attributes().download).toBe('v1.1.2-evidences-1.json'); }); describe('sha text', () => { it('renders the short sha initially', () => { - expect(wrapper.find('.js-short').text()).toBe(truncateSha(release.evidenceSha)); + expect(wrapper.find('.js-short').text()).toBe(truncateSha(release.evidences[0].sha)); }); 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.evidenceSha); + expect(wrapper.find('.js-expanded').text()).toBe(release.evidences[0].sha); }); }); }); @@ -72,7 +71,7 @@ describe('Evidence Block', () => { it('copies the sha', () => { expect(wrapper.find(ClipboardButton).attributes('data-clipboard-text')).toBe( - release.evidenceSha, + release.evidences[0].sha, ); }); }); diff --git a/spec/frontend/releases/mock_data.js b/spec/frontend/releases/mock_data.js index 85e6bab71ba..bd5fc86275e 100644 --- a/spec/frontend/releases/mock_data.js +++ b/spec/frontend/releases/mock_data.js @@ -43,7 +43,6 @@ export const 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', - evidence_sha: 'fb3a125fd69a0e5048ebfb0ba43eb32ce4911520dd8d', author: { id: 1, name: 'Administrator', @@ -69,10 +68,28 @@ export const release = { commit_path: '/root/release-test/commit/c22b0728d1b465f82898c884d32b01aa642f96c1', upcoming_release: false, milestones, + evidences: [ + { + filepath: + 'https://20592.qa-tunnel.gitlab.info/root/test-deployments/-/releases/v1.1.2/evidences/1.json', + sha: 'fb3a125fd69a0e5048ebfb0ba43eb32ce4911520dd8d', + collected_at: '2018-10-19 15:43:20 +0200', + }, + { + filepath: + 'https://20592.qa-tunnel.gitlab.info/root/test-deployments/-/releases/v1.1.2/evidences/2.json', + sha: '6ebd17a66e6a861175735416e49cf677678029805712dd71bb805c609e2d9108', + collected_at: '2018-10-19 15:43:20 +0200', + }, + { + filepath: + 'https://20592.qa-tunnel.gitlab.info/root/test-deployments/-/releases/v1.1.2/evidences/3.json', + sha: '2f65beaf275c3cb4b4e24fb01d481cc475d69c957830833f15338384816b5cba', + collected_at: '2018-10-19 15:43:20 +0200', + }, + ], assets: { count: 5, - evidence_file_path: - 'https://20592.qa-tunnel.gitlab.info/root/test-deployments/-/releases/v1.1.2/evidence.json', sources: [ { format: 'zip', |