diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-12 21:06:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-12 21:06:57 +0300 |
commit | 6d31b8f052d30b7e55128d17b66bceed8c6065a9 (patch) | |
tree | ca428cf6145af7cfaada94378e66bd5e7cc5a429 /spec/frontend | |
parent | 69944ffb68788d190e81ff7e33db5dcb6c903184 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/notes/components/diff_discussion_header_spec.js | 141 | ||||
-rw-r--r-- | spec/frontend/releases/detail/components/app_spec.js | 19 | ||||
-rw-r--r-- | spec/frontend/repository/pages/index_spec.js | 42 | ||||
-rw-r--r-- | spec/frontend/repository/pages/tree_spec.js | 60 | ||||
-rw-r--r-- | spec/frontend/repository/utils/dom_spec.js | 20 | ||||
-rw-r--r-- | spec/frontend/repository/utils/title_spec.js | 4 |
6 files changed, 283 insertions, 3 deletions
diff --git a/spec/frontend/notes/components/diff_discussion_header_spec.js b/spec/frontend/notes/components/diff_discussion_header_spec.js new file mode 100644 index 00000000000..f90147f9105 --- /dev/null +++ b/spec/frontend/notes/components/diff_discussion_header_spec.js @@ -0,0 +1,141 @@ +import { mount, createLocalVue } from '@vue/test-utils'; + +import createStore from '~/notes/stores'; +import diffDiscussionHeader from '~/notes/components/diff_discussion_header.vue'; + +import { discussionMock } from '../../../javascripts/notes/mock_data'; +import mockDiffFile from '../../diffs/mock_data/diff_discussions'; + +const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json'; + +describe('diff_discussion_header component', () => { + let store; + let wrapper; + + preloadFixtures(discussionWithTwoUnresolvedNotes); + + beforeEach(() => { + window.mrTabs = {}; + store = createStore(); + + const localVue = createLocalVue(); + wrapper = mount(diffDiscussionHeader, { + store, + propsData: { discussion: discussionMock }, + localVue, + sync: false, + }); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + it('should render user avatar', () => { + const discussion = { ...discussionMock }; + discussion.diff_file = mockDiffFile; + discussion.diff_discussion = true; + + wrapper.setProps({ discussion }); + + expect(wrapper.find('.user-avatar-link').exists()).toBe(true); + }); + + describe('action text', () => { + const commitId = 'razupaltuff'; + const truncatedCommitId = commitId.substr(0, 8); + let commitElement; + + beforeEach(done => { + store.state.diffs = { + projectPath: 'something', + }; + + wrapper.setProps({ + discussion: { + ...discussionMock, + for_commit: true, + commit_id: commitId, + diff_discussion: true, + diff_file: { + ...mockDiffFile, + }, + }, + }); + + wrapper.vm + .$nextTick() + .then(() => { + commitElement = wrapper.find('.commit-sha'); + }) + .then(done) + .catch(done.fail); + }); + + describe('for diff threads without a commit id', () => { + it('should show started a thread on the diff text', done => { + Object.assign(wrapper.vm.discussion, { + for_commit: false, + commit_id: null, + }); + + wrapper.vm.$nextTick(() => { + expect(wrapper.text()).toContain('started a thread on the diff'); + + done(); + }); + }); + + it('should show thread on older version text', done => { + Object.assign(wrapper.vm.discussion, { + for_commit: false, + commit_id: null, + active: false, + }); + + wrapper.vm.$nextTick(() => { + expect(wrapper.text()).toContain('started a thread on an old version of the diff'); + + done(); + }); + }); + }); + + describe('for commit threads', () => { + it('should display a monospace started a thread on commit', () => { + expect(wrapper.text()).toContain(`started a thread on commit ${truncatedCommitId}`); + expect(commitElement.exists()).toBe(true); + expect(commitElement.text()).toContain(truncatedCommitId); + }); + }); + + describe('for diff thread with a commit id', () => { + it('should display started thread on commit header', done => { + wrapper.vm.discussion.for_commit = false; + + wrapper.vm.$nextTick(() => { + expect(wrapper.text()).toContain(`started a thread on commit ${truncatedCommitId}`); + + expect(commitElement).not.toBe(null); + + done(); + }); + }); + + it('should display outdated change on commit header', done => { + wrapper.vm.discussion.for_commit = false; + wrapper.vm.discussion.active = false; + + wrapper.vm.$nextTick(() => { + expect(wrapper.text()).toContain( + `started a thread on an outdated change in commit ${truncatedCommitId}`, + ); + + expect(commitElement).not.toBe(null); + + done(); + }); + }); + }); + }); +}); diff --git a/spec/frontend/releases/detail/components/app_spec.js b/spec/frontend/releases/detail/components/app_spec.js index f8eb33a69a8..4726f18c8fa 100644 --- a/spec/frontend/releases/detail/components/app_spec.js +++ b/spec/frontend/releases/detail/components/app_spec.js @@ -8,15 +8,17 @@ describe('Release detail component', () => { let wrapper; let releaseClone; let actions; + let state; beforeEach(() => { gon.api_version = 'v4'; releaseClone = JSON.parse(JSON.stringify(convertObjectPropsToCamelCase(release))); - const state = { + state = { release: releaseClone, markdownDocsPath: 'path/to/markdown/docs', + updateReleaseApiDocsPath: 'path/to/update/release/api/docs', }; actions = { @@ -46,6 +48,21 @@ describe('Release detail component', () => { expect(wrapper.find('#git-ref').element.value).toBe(releaseClone.tagName); }); + it('renders the correct help text under the "Tag name" field', () => { + const helperText = wrapper.find('#tag-name-help'); + const helperTextLink = helperText.find('a'); + const helperTextLinkAttrs = helperTextLink.attributes(); + + expect(helperText.text()).toBe( + 'Changing a Release tag is only supported via Releases API. More information', + ); + expect(helperTextLink.text()).toBe('More information'); + expect(helperTextLinkAttrs.href).toBe(state.updateReleaseApiDocsPath); + expect(helperTextLinkAttrs.rel).toContain('noopener'); + expect(helperTextLinkAttrs.rel).toContain('noreferrer'); + expect(helperTextLinkAttrs.target).toBe('_blank'); + }); + it('renders the correct release title in the "Release title" field', () => { expect(wrapper.find('#release-title').element.value).toBe(releaseClone.name); }); diff --git a/spec/frontend/repository/pages/index_spec.js b/spec/frontend/repository/pages/index_spec.js new file mode 100644 index 00000000000..c0afb7931b1 --- /dev/null +++ b/spec/frontend/repository/pages/index_spec.js @@ -0,0 +1,42 @@ +import { shallowMount } from '@vue/test-utils'; +import IndexPage from '~/repository/pages/index.vue'; +import TreePage from '~/repository/pages/tree.vue'; +import { updateElementsVisibility } from '~/repository/utils/dom'; + +jest.mock('~/repository/utils/dom'); + +describe('Repository index page component', () => { + let wrapper; + + function factory() { + wrapper = shallowMount(IndexPage); + } + + afterEach(() => { + wrapper.destroy(); + + updateElementsVisibility.mockClear(); + }); + + it('calls updateElementsVisibility on mounted', () => { + factory(); + + expect(updateElementsVisibility).toHaveBeenCalledWith('.js-show-on-project-root', true); + }); + + it('calls updateElementsVisibility after destroy', () => { + factory(); + wrapper.destroy(); + + expect(updateElementsVisibility.mock.calls.pop()).toEqual(['.js-show-on-project-root', false]); + }); + + it('renders TreePage', () => { + factory(); + + const child = wrapper.find(TreePage); + + expect(child.exists()).toBe(true); + expect(child.props()).toEqual({ path: '/' }); + }); +}); diff --git a/spec/frontend/repository/pages/tree_spec.js b/spec/frontend/repository/pages/tree_spec.js new file mode 100644 index 00000000000..36662696c91 --- /dev/null +++ b/spec/frontend/repository/pages/tree_spec.js @@ -0,0 +1,60 @@ +import { shallowMount } from '@vue/test-utils'; +import TreePage from '~/repository/pages/tree.vue'; +import { updateElementsVisibility } from '~/repository/utils/dom'; + +jest.mock('~/repository/utils/dom'); + +describe('Repository tree page component', () => { + let wrapper; + + function factory(path) { + wrapper = shallowMount(TreePage, { propsData: { path } }); + } + + afterEach(() => { + wrapper.destroy(); + + updateElementsVisibility.mockClear(); + }); + + describe('when root path', () => { + beforeEach(() => { + factory('/'); + }); + + it('shows root elements', () => { + expect(updateElementsVisibility.mock.calls).toEqual([ + ['.js-show-on-root', true], + ['.js-hide-on-root', false], + ]); + }); + + describe('when changed', () => { + beforeEach(() => { + updateElementsVisibility.mockClear(); + + wrapper.setProps({ path: '/test' }); + }); + + it('hides root elements', () => { + expect(updateElementsVisibility.mock.calls).toEqual([ + ['.js-show-on-root', false], + ['.js-hide-on-root', true], + ]); + }); + }); + }); + + describe('when non-root path', () => { + beforeEach(() => { + factory('/test'); + }); + + it('hides root elements', () => { + expect(updateElementsVisibility.mock.calls).toEqual([ + ['.js-show-on-root', false], + ['.js-hide-on-root', true], + ]); + }); + }); +}); diff --git a/spec/frontend/repository/utils/dom_spec.js b/spec/frontend/repository/utils/dom_spec.js new file mode 100644 index 00000000000..678d444904d --- /dev/null +++ b/spec/frontend/repository/utils/dom_spec.js @@ -0,0 +1,20 @@ +import { setHTMLFixture } from '../../helpers/fixtures'; +import { updateElementsVisibility } from '~/repository/utils/dom'; + +describe('updateElementsVisibility', () => { + it('adds hidden class', () => { + setHTMLFixture('<div class="js-test"></div>'); + + updateElementsVisibility('.js-test', false); + + expect(document.querySelector('.js-test').classList).toContain('hidden'); + }); + + it('removes hidden class', () => { + setHTMLFixture('<div class="hidden js-test"></div>'); + + updateElementsVisibility('.js-test', true); + + expect(document.querySelector('.js-test').classList).not.toContain('hidden'); + }); +}); diff --git a/spec/frontend/repository/utils/title_spec.js b/spec/frontend/repository/utils/title_spec.js index c4879716fd7..63035933424 100644 --- a/spec/frontend/repository/utils/title_spec.js +++ b/spec/frontend/repository/utils/title_spec.js @@ -8,8 +8,8 @@ describe('setTitle', () => { ${'app/assets'} | ${'app/assets'} ${'app/assets/javascripts'} | ${'app/assets/javascripts'} `('sets document title as $title for $path', ({ path, title }) => { - setTitle(path, 'master', 'GitLab'); + setTitle(path, 'master', 'GitLab Org / GitLab'); - expect(document.title).toEqual(`${title} · master · GitLab`); + expect(document.title).toEqual(`${title} · master · GitLab Org / GitLab · GitLab`); }); }); |