diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-28 03:06:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-28 03:06:07 +0300 |
commit | 2c0b1b6259d83e37c2a2b456a1f9afdb8817a3d5 (patch) | |
tree | d0229b7b578533e43406d18ef0caf76b73ef595e /spec/frontend/diffs | |
parent | 20758bc3b33c04121d214cb89646baf880037a27 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/diffs')
-rw-r--r-- | spec/frontend/diffs/components/compare_versions_spec.js | 156 | ||||
-rw-r--r-- | spec/frontend/diffs/mock_data/diff_with_commit.js | 7 | ||||
-rw-r--r-- | spec/frontend/diffs/mock_data/merge_request_diffs.js | 46 |
3 files changed, 209 insertions, 0 deletions
diff --git a/spec/frontend/diffs/components/compare_versions_spec.js b/spec/frontend/diffs/components/compare_versions_spec.js new file mode 100644 index 00000000000..9900fcdb6e1 --- /dev/null +++ b/spec/frontend/diffs/components/compare_versions_spec.js @@ -0,0 +1,156 @@ +import { trimText } from 'helpers/text_helper'; +import { mount, createLocalVue } from '@vue/test-utils'; +import Vuex from 'vuex'; +import CompareVersionsComponent from '~/diffs/components/compare_versions.vue'; +import Icon from '~/vue_shared/components/icon.vue'; +import { createStore } from '~/mr_notes/stores'; +import diffsMockData from '../mock_data/merge_request_diffs'; +import getDiffWithCommit from '../mock_data/diff_with_commit'; + +const localVue = createLocalVue(); +localVue.use(Vuex); + +describe('CompareVersions', () => { + let wrapper; + const targetBranch = { branchName: 'tmp-wine-dev', versionIndex: -1 }; + + const createWrapper = props => { + const store = createStore(); + + store.state.diffs.addedLines = 10; + store.state.diffs.removedLines = 20; + store.state.diffs.diffFiles.push('test'); + + wrapper = mount(CompareVersionsComponent, { + sync: false, + attachToDocument: true, + localVue, + store, + propsData: { + mergeRequestDiffs: diffsMockData, + mergeRequestDiff: diffsMockData[0], + targetBranch, + ...props, + }, + }); + }; + + beforeEach(() => { + createWrapper(); + }); + + afterEach(() => { + wrapper.destroy(); + wrapper = null; + }); + + describe('template', () => { + it('should render Tree List toggle button with correct attribute values', () => { + const treeListBtn = wrapper.find('.js-toggle-tree-list'); + + expect(treeListBtn.exists()).toBe(true); + expect(treeListBtn.attributes('data-original-title')).toBe('Hide file browser'); + expect(treeListBtn.findAll(Icon).length).not.toBe(0); + expect(treeListBtn.find(Icon).props('name')).toBe('collapse-left'); + }); + + it('should render comparison dropdowns with correct values', () => { + const sourceDropdown = wrapper.find('.mr-version-dropdown'); + const targetDropdown = wrapper.find('.mr-version-compare-dropdown'); + + expect(sourceDropdown.exists()).toBe(true); + expect(targetDropdown.exists()).toBe(true); + expect(sourceDropdown.find('a span').html()).toContain('latest version'); + expect(targetDropdown.find('a span').html()).toContain(targetBranch.branchName); + }); + + it('should not render comparison dropdowns if no mergeRequestDiffs are specified', () => { + createWrapper({ mergeRequestDiffs: [] }); + + const sourceDropdown = wrapper.find('.mr-version-dropdown'); + const targetDropdown = wrapper.find('.mr-version-compare-dropdown'); + + expect(sourceDropdown.exists()).toBe(false); + expect(targetDropdown.exists()).toBe(false); + }); + + it('should render view types buttons with correct values', () => { + const inlineBtn = wrapper.find('#inline-diff-btn'); + const parallelBtn = wrapper.find('#parallel-diff-btn'); + + expect(inlineBtn.exists()).toBe(true); + expect(parallelBtn.exists()).toBe(true); + expect(inlineBtn.attributes('data-view-type')).toEqual('inline'); + expect(parallelBtn.attributes('data-view-type')).toEqual('parallel'); + expect(inlineBtn.html()).toContain('Inline'); + expect(parallelBtn.html()).toContain('Side-by-side'); + }); + + it('adds container-limiting classes when showFileTree is false with inline diffs', () => { + createWrapper({ isLimitedContainer: true }); + + const limitedContainer = wrapper.find('.container-limited.limit-container-width'); + + expect(limitedContainer.exists()).toBe(true); + }); + + it('does not add container-limiting classes when showFileTree is false with inline diffs', () => { + createWrapper({ isLimitedContainer: false }); + + const limitedContainer = wrapper.find('.container-limited.limit-container-width'); + + expect(limitedContainer.exists()).toBe(false); + }); + }); + + describe('setInlineDiffViewType', () => { + it('should persist the view type in the url', () => { + const viewTypeBtn = wrapper.find('#inline-diff-btn'); + viewTypeBtn.trigger('click'); + + expect(window.location.toString()).toContain('?view=inline'); + }); + }); + + describe('setParallelDiffViewType', () => { + it('should persist the view type in the url', () => { + const viewTypeBtn = wrapper.find('#parallel-diff-btn'); + viewTypeBtn.trigger('click'); + + expect(window.location.toString()).toContain('?view=parallel'); + }); + }); + + describe('comparableDiffs', () => { + it('should not contain the first item in the mergeRequestDiffs property', () => { + const { comparableDiffs } = wrapper.vm; + const comparableDiffsMock = diffsMockData.slice(1); + + expect(comparableDiffs).toEqual(comparableDiffsMock); + }); + }); + + describe('baseVersionPath', () => { + it('should be set correctly from mergeRequestDiff', () => { + expect(wrapper.vm.baseVersionPath).toEqual(wrapper.vm.mergeRequestDiff.base_version_path); + }); + }); + + describe('commit', () => { + beforeEach(done => { + wrapper.vm.$store.state.diffs.commit = getDiffWithCommit().commit; + wrapper.mergeRequestDiffs = []; + + wrapper.vm.$nextTick(done); + }); + + it('renders latest version button', () => { + expect(trimText(wrapper.find('.js-latest-version').text())).toBe('Show latest version'); + }); + + it('renders short commit ID', () => { + expect(wrapper.text()).toContain('Viewing commit'); + expect(wrapper.text()).toContain(wrapper.vm.commit.short_id); + }); + }); +}); diff --git a/spec/frontend/diffs/mock_data/diff_with_commit.js b/spec/frontend/diffs/mock_data/diff_with_commit.js new file mode 100644 index 00000000000..d646294ee84 --- /dev/null +++ b/spec/frontend/diffs/mock_data/diff_with_commit.js @@ -0,0 +1,7 @@ +const FIXTURE = 'merge_request_diffs/with_commit.json'; + +preloadFixtures(FIXTURE); + +export default function getDiffWithCommit() { + return getJSONFixture(FIXTURE); +} diff --git a/spec/frontend/diffs/mock_data/merge_request_diffs.js b/spec/frontend/diffs/mock_data/merge_request_diffs.js new file mode 100644 index 00000000000..4bbef146336 --- /dev/null +++ b/spec/frontend/diffs/mock_data/merge_request_diffs.js @@ -0,0 +1,46 @@ +export default [ + { + base_version_path: '/gnuwget/wget2/merge_requests/6/diffs?diff_id=37', + version_index: 4, + created_at: '2018-10-23T11:49:16.611Z', + commits_count: 4, + latest: true, + short_commit_sha: 'de7a8f7f', + version_path: '/gnuwget/wget2/merge_requests/6/diffs?diff_id=37', + compare_path: + '/gnuwget/wget2/merge_requests/6/diffs?diff_id=37&start_sha=de7a8f7f20c3ea2e0bef3ba01cfd41c21f6b4995', + }, + { + base_version_path: '/gnuwget/wget2/merge_requests/6/diffs?diff_id=36', + version_index: 3, + created_at: '2018-10-23T11:46:40.617Z', + commits_count: 3, + latest: false, + short_commit_sha: 'e78fc18f', + version_path: '/gnuwget/wget2/merge_requests/6/diffs?diff_id=36', + compare_path: + '/gnuwget/wget2/merge_requests/6/diffs?diff_id=37&start_sha=e78fc18fa37acb2185c59ca94d4a964464feb50e', + }, + { + base_version_path: '/gnuwget/wget2/merge_requests/6/diffs?diff_id=35', + version_index: 2, + created_at: '2018-10-04T09:57:39.648Z', + commits_count: 2, + latest: false, + short_commit_sha: '48da7e7e', + version_path: '/gnuwget/wget2/merge_requests/6/diffs?diff_id=35', + compare_path: + '/gnuwget/wget2/merge_requests/6/diffs?diff_id=37&start_sha=48da7e7e9a99d41c852578bd9cb541ca4d864b3e', + }, + { + base_version_path: '/gnuwget/wget2/merge_requests/6/diffs?diff_id=20', + version_index: 1, + created_at: '2018-09-25T20:30:39.493Z', + commits_count: 1, + latest: false, + short_commit_sha: '47bac2ed', + version_path: '/gnuwget/wget2/merge_requests/6/diffs?diff_id=20', + compare_path: + '/gnuwget/wget2/merge_requests/6/diffs?diff_id=37&start_sha=47bac2ed972c5bee344c1cea159a22cd7f711dc0', + }, +]; |