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/javascripts/diffs | |
parent | 20758bc3b33c04121d214cb89646baf880037a27 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts/diffs')
3 files changed, 12 insertions, 196 deletions
diff --git a/spec/javascripts/diffs/components/compare_versions_spec.js b/spec/javascripts/diffs/components/compare_versions_spec.js deleted file mode 100644 index ef4bb470734..00000000000 --- a/spec/javascripts/diffs/components/compare_versions_spec.js +++ /dev/null @@ -1,145 +0,0 @@ -import Vue from 'vue'; -import CompareVersionsComponent from '~/diffs/components/compare_versions.vue'; -import { createStore } from '~/mr_notes/stores'; -import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; -import diffsMockData from '../mock_data/merge_request_diffs'; -import getDiffWithCommit from '../mock_data/diff_with_commit'; - -describe('CompareVersions', () => { - let vm; - const targetBranch = { branchName: 'tmp-wine-dev', versionIndex: -1 }; - - beforeEach(() => { - const store = createStore(); - - store.state.diffs.addedLines = 10; - store.state.diffs.removedLines = 20; - store.state.diffs.diffFiles.push('test'); - - vm = createComponentWithStore(Vue.extend(CompareVersionsComponent), store, { - mergeRequestDiffs: diffsMockData, - mergeRequestDiff: diffsMockData[0], - targetBranch, - }).$mount(); - }); - - describe('template', () => { - it('should render Tree List toggle button with correct attribute values', () => { - const treeListBtn = vm.$el.querySelector('.js-toggle-tree-list'); - - expect(treeListBtn).not.toBeNull(); - expect(treeListBtn.dataset.originalTitle).toBe('Hide file browser'); - expect(treeListBtn.querySelectorAll('svg use').length).not.toBe(0); - expect(treeListBtn.querySelector('svg use').getAttribute('xlink:href')).toContain( - '#collapse-left', - ); - }); - - it('should render comparison dropdowns with correct values', () => { - const sourceDropdown = vm.$el.querySelector('.mr-version-dropdown'); - const targetDropdown = vm.$el.querySelector('.mr-version-compare-dropdown'); - - expect(sourceDropdown).not.toBeNull(); - expect(targetDropdown).not.toBeNull(); - expect(sourceDropdown.querySelector('a span').innerHTML).toContain('latest version'); - expect(targetDropdown.querySelector('a span').innerHTML).toContain(targetBranch.branchName); - }); - - it('should not render comparison dropdowns if no mergeRequestDiffs are specified', () => { - vm.mergeRequestDiffs = []; - - vm.$nextTick(() => { - const sourceDropdown = vm.$el.querySelector('.mr-version-dropdown'); - const targetDropdown = vm.$el.querySelector('.mr-version-compare-dropdown'); - - expect(sourceDropdown).toBeNull(); - expect(targetDropdown).toBeNull(); - }); - }); - - it('should render view types buttons with correct values', () => { - const inlineBtn = vm.$el.querySelector('#inline-diff-btn'); - const parallelBtn = vm.$el.querySelector('#parallel-diff-btn'); - - expect(inlineBtn).not.toBeNull(); - expect(parallelBtn).not.toBeNull(); - expect(inlineBtn.dataset.viewType).toEqual('inline'); - expect(parallelBtn.dataset.viewType).toEqual('parallel'); - expect(inlineBtn.innerHTML).toContain('Inline'); - expect(parallelBtn.innerHTML).toContain('Side-by-side'); - }); - - it('adds container-limiting classes when showFileTree is false with inline diffs', () => { - vm.isLimitedContainer = true; - - vm.$nextTick(() => { - const limitedContainer = vm.$el.querySelector('.container-limited.limit-container-width'); - - expect(limitedContainer).not.toBeNull(); - }); - }); - - it('does not add container-limiting classes when showFileTree is false with inline diffs', () => { - vm.isLimitedContainer = false; - - vm.$nextTick(() => { - const limitedContainer = vm.$el.querySelector('.container-limited.limit-container-width'); - - expect(limitedContainer).toBeNull(); - }); - }); - }); - - describe('setInlineDiffViewType', () => { - it('should persist the view type in the url', () => { - const viewTypeBtn = vm.$el.querySelector('#inline-diff-btn'); - viewTypeBtn.click(); - - expect(window.location.toString()).toContain('?view=inline'); - }); - }); - - describe('setParallelDiffViewType', () => { - it('should persist the view type in the url', () => { - const viewTypeBtn = vm.$el.querySelector('#parallel-diff-btn'); - viewTypeBtn.click(); - - expect(window.location.toString()).toContain('?view=parallel'); - }); - }); - - describe('comparableDiffs', () => { - it('should not contain the first item in the mergeRequestDiffs property', () => { - const { comparableDiffs } = vm; - const comparableDiffsMock = diffsMockData.slice(1); - - expect(comparableDiffs).toEqual(comparableDiffsMock); - }); - }); - - describe('baseVersionPath', () => { - it('should be set correctly from mergeRequestDiff', () => { - expect(vm.baseVersionPath).toEqual(vm.mergeRequestDiff.base_version_path); - }); - }); - - describe('commit', () => { - beforeEach(done => { - vm.$store.state.diffs.commit = getDiffWithCommit().commit; - vm.mergeRequestDiffs = []; - - vm.$nextTick(done); - }); - - it('renders latest version button', () => { - expect(vm.$el.querySelector('.js-latest-version').textContent.trim()).toBe( - 'Show latest version', - ); - }); - - it('renders short commit ID', () => { - expect(vm.$el.textContent).toContain('Viewing commit'); - expect(vm.$el.textContent).toContain(vm.commit.short_id); - }); - }); -}); diff --git a/spec/javascripts/diffs/mock_data/diff_with_commit.js b/spec/javascripts/diffs/mock_data/diff_with_commit.js index d646294ee84..c36b0239060 100644 --- a/spec/javascripts/diffs/mock_data/diff_with_commit.js +++ b/spec/javascripts/diffs/mock_data/diff_with_commit.js @@ -1,7 +1,7 @@ -const FIXTURE = 'merge_request_diffs/with_commit.json'; +// No new code should be added to this file. Instead, modify the +// file this one re-exports from. For more detail about why, see: +// https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/31349 -preloadFixtures(FIXTURE); +import getDiffWithCommit from '../../../frontend/diffs/mock_data/diff_with_commit'; -export default function getDiffWithCommit() { - return getJSONFixture(FIXTURE); -} +export default getDiffWithCommit; diff --git a/spec/javascripts/diffs/mock_data/merge_request_diffs.js b/spec/javascripts/diffs/mock_data/merge_request_diffs.js index 4bbef146336..de29eb7e560 100644 --- a/spec/javascripts/diffs/mock_data/merge_request_diffs.js +++ b/spec/javascripts/diffs/mock_data/merge_request_diffs.js @@ -1,46 +1,7 @@ -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', - }, -]; +// No new code should be added to this file. Instead, modify the +// file this one re-exports from. For more detail about why, see: +// https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/31349 + +import diffsMockData from '../../../frontend/diffs/mock_data/merge_request_diffs'; + +export default diffsMockData; |