diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-26 09:08:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-26 09:08:36 +0000 |
commit | 23d237110e6a646dec08e1f5b4696d2d9c51cfef (patch) | |
tree | 3c568514c8e22203f50d38940cbb9865aad5bb02 /spec/javascripts/diffs | |
parent | 274dff4f027da636f62361c811285cbb5d5a7c0c (diff) | |
download | gitlab-ce-23d237110e6a646dec08e1f5b4696d2d9c51cfef.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts/diffs')
-rw-r--r-- | spec/javascripts/diffs/components/app_spec.js | 67 | ||||
-rw-r--r-- | spec/javascripts/diffs/store/actions_spec.js | 89 | ||||
-rw-r--r-- | spec/javascripts/diffs/store/mutations_spec.js | 27 |
3 files changed, 180 insertions, 3 deletions
diff --git a/spec/javascripts/diffs/components/app_spec.js b/spec/javascripts/diffs/components/app_spec.js index fdf8bcee756..52f7674a7b3 100644 --- a/spec/javascripts/diffs/components/app_spec.js +++ b/spec/javascripts/diffs/components/app_spec.js @@ -34,6 +34,8 @@ describe('diffs/components/app', () => { localVue, propsData: { endpoint: `${TEST_HOST}/diff/endpoint`, + endpointMetadata: `${TEST_HOST}/diff/endpointMetadata`, + endpointBatch: `${TEST_HOST}/diff/endpointBatch`, projectPath: 'namespace/project', currentUser: {}, changesEmptyStateIllustration: '', @@ -42,6 +44,11 @@ describe('diffs/components/app', () => { ...props, }, store, + methods: { + isLatestVersion() { + return true; + }, + }, }); } @@ -59,6 +66,58 @@ describe('diffs/components/app', () => { wrapper.destroy(); }); + describe('fetch diff methods', () => { + beforeEach(() => { + spyOn(window, 'requestIdleCallback').and.callFake(fn => fn()); + createComponent(); + spyOn(wrapper.vm, 'fetchDiffFiles').and.callFake(() => Promise.resolve()); + spyOn(wrapper.vm, 'fetchDiffFilesMeta').and.callFake(() => Promise.resolve()); + spyOn(wrapper.vm, 'fetchDiffFilesBatch').and.callFake(() => Promise.resolve()); + spyOn(wrapper.vm, 'setDiscussions'); + spyOn(wrapper.vm, 'startRenderDiffsQueue'); + }); + + it('calls fetchDiffFiles if diffsBatchLoad is not enabled', () => { + wrapper.vm.glFeatures.diffsBatchLoad = false; + wrapper.vm.fetchData(false); + + expect(wrapper.vm.fetchDiffFiles).toHaveBeenCalled(); + wrapper.vm.$nextTick(() => { + expect(wrapper.vm.setDiscussions).toHaveBeenCalled(); + expect(wrapper.vm.startRenderDiffsQueue).toHaveBeenCalled(); + expect(wrapper.vm.fetchDiffFilesMeta).not.toHaveBeenCalled(); + expect(wrapper.vm.fetchDiffFilesBatch).not.toHaveBeenCalled(); + }); + }); + + it('calls fetchDiffFiles if diffsBatchLoad is enabled, and not latest version', () => { + wrapper.vm.glFeatures.diffsBatchLoad = true; + wrapper.vm.isLatestVersion = () => false; + wrapper.vm.fetchData(false); + + expect(wrapper.vm.fetchDiffFiles).toHaveBeenCalled(); + wrapper.vm.$nextTick(() => { + expect(wrapper.vm.setDiscussions).toHaveBeenCalled(); + expect(wrapper.vm.startRenderDiffsQueue).toHaveBeenCalled(); + expect(wrapper.vm.fetchDiffFilesMeta).not.toHaveBeenCalled(); + expect(wrapper.vm.fetchDiffFilesBatch).not.toHaveBeenCalled(); + }); + }); + + it('calls batch methods if diffsBatchLoad is enabled, and latest version', () => { + wrapper.vm.glFeatures.diffsBatchLoad = true; + wrapper.vm.fetchData(false); + + expect(wrapper.vm.fetchDiffFiles).not.toHaveBeenCalled(); + wrapper.vm.$nextTick(() => { + expect(wrapper.vm.setDiscussions).toHaveBeenCalled(); + expect(wrapper.vm.startRenderDiffsQueue).toHaveBeenCalled(); + expect(wrapper.vm.fetchDiffFilesMeta).toHaveBeenCalled(); + expect(wrapper.vm.fetchDiffFilesBatch).toHaveBeenCalled(); + }); + }); + }); + it('adds container-limiting classes when showFileTree is false with inline diffs', () => { createComponent({}, ({ state }) => { state.diffs.showTreeList = false; @@ -93,6 +152,14 @@ describe('diffs/components/app', () => { expect(wrapper.contains(GlLoadingIcon)).toBe(true); }); + it('displays loading icon on batch loading', () => { + createComponent({}, ({ state }) => { + state.diffs.isBatchLoading = true; + }); + + expect(wrapper.contains(GlLoadingIcon)).toBe(true); + }); + it('displays diffs container when not loading', () => { createComponent(); diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js index 874891fcc6e..3235febe0dc 100644 --- a/spec/javascripts/diffs/store/actions_spec.js +++ b/spec/javascripts/diffs/store/actions_spec.js @@ -8,6 +8,8 @@ import { import actions, { setBaseConfig, fetchDiffFiles, + fetchDiffFilesBatch, + fetchDiffFilesMeta, assignDiscussionsToDiff, removeDiscussionsFromDiff, startRenderDiffsQueue, @@ -68,18 +70,41 @@ describe('DiffsStoreActions', () => { describe('setBaseConfig', () => { it('should set given endpoint and project path', done => { const endpoint = '/diffs/set/endpoint'; + const endpointMetadata = '/diffs/set/endpoint/metadata'; + const endpointBatch = '/diffs/set/endpoint/batch'; const projectPath = '/root/project'; const dismissEndpoint = '/-/user_callouts'; const showSuggestPopover = false; testAction( setBaseConfig, - { endpoint, projectPath, dismissEndpoint, showSuggestPopover }, - { endpoint: '', projectPath: '', dismissEndpoint: '', showSuggestPopover: true }, + { + endpoint, + endpointBatch, + endpointMetadata, + projectPath, + dismissEndpoint, + showSuggestPopover, + }, + { + endpoint: '', + endpointBatch: '', + endpointMetadata: '', + projectPath: '', + dismissEndpoint: '', + showSuggestPopover: true, + }, [ { type: types.SET_BASE_CONFIG, - payload: { endpoint, projectPath, dismissEndpoint, showSuggestPopover }, + payload: { + endpoint, + endpointMetadata, + endpointBatch, + projectPath, + dismissEndpoint, + showSuggestPopover, + }, }, ], [], @@ -114,6 +139,64 @@ describe('DiffsStoreActions', () => { }); }); + describe('fetchDiffFilesBatch', () => { + it('should fetch batch diff files', done => { + const endpointBatch = '/fetch/diffs_batch'; + const batch1 = `${endpointBatch}?per_page=10`; + const batch2 = `${endpointBatch}?per_page=10&page=2`; + const mock = new MockAdapter(axios); + const res1 = { diff_files: [], pagination: { next_page: 2 } }; + const res2 = { diff_files: [], pagination: {} }; + mock.onGet(batch1).reply(200, res1); + mock.onGet(batch2).reply(200, res2); + + testAction( + fetchDiffFilesBatch, + {}, + { endpointBatch }, + [ + { type: types.SET_BATCH_LOADING, payload: true }, + { type: types.SET_DIFF_DATA_BATCH, payload: { diff_files: res1.diff_files } }, + { type: types.SET_BATCH_LOADING, payload: false }, + { type: types.SET_DIFF_DATA_BATCH, payload: { diff_files: [] } }, + { type: types.SET_BATCH_LOADING, payload: false }, + ], + [], + () => { + mock.restore(); + done(); + }, + ); + }); + }); + + describe('fetchDiffFilesMeta', () => { + it('should fetch diff meta information', done => { + const endpointMetadata = '/fetch/diffs_meta'; + const mock = new MockAdapter(axios); + const data = { diff_files: [] }; + const res = { data }; + mock.onGet(endpointMetadata).reply(200, res); + + testAction( + fetchDiffFilesMeta, + {}, + { endpointMetadata }, + [ + { type: types.SET_LOADING, payload: true }, + { type: types.SET_LOADING, payload: false }, + { type: types.SET_MERGE_REQUEST_DIFFS, payload: [] }, + { type: types.SET_DIFF_DATA, payload: { data, diff_files: [] } }, + ], + [], + () => { + mock.restore(); + done(); + }, + ); + }); + }); + describe('setHighlightedRow', () => { it('should mark currently selected diff and set lineHash and fileHash of highlightedRow', () => { testAction(setHighlightedRow, 'ABC_123', {}, [ diff --git a/spec/javascripts/diffs/store/mutations_spec.js b/spec/javascripts/diffs/store/mutations_spec.js index 3e033b6c9dc..19bf5bdd592 100644 --- a/spec/javascripts/diffs/store/mutations_spec.js +++ b/spec/javascripts/diffs/store/mutations_spec.js @@ -28,6 +28,16 @@ describe('DiffsStoreMutations', () => { }); }); + describe('SET_BATCH_LOADING', () => { + it('should set loading state', () => { + const state = {}; + + mutations[types.SET_BATCH_LOADING](state, false); + + expect(state.isBatchLoading).toEqual(false); + }); + }); + describe('SET_DIFF_DATA', () => { it('should set diff data type properly', () => { const state = {}; @@ -45,6 +55,23 @@ describe('DiffsStoreMutations', () => { }); }); + describe('SET_DIFFSET_DIFF_DATA_BATCH_DATA', () => { + it('should set diff data batch type properly', () => { + const state = { diffFiles: [] }; + const diffMock = { + diff_files: [diffFileMockData], + }; + + mutations[types.SET_DIFF_DATA_BATCH](state, diffMock); + + const firstLine = state.diffFiles[0].parallel_diff_lines[0]; + + expect(firstLine.right.text).toBeUndefined(); + expect(state.diffFiles[0].renderIt).toEqual(true); + expect(state.diffFiles[0].collapsed).toEqual(false); + }); + }); + describe('SET_DIFF_VIEW_TYPE', () => { it('should set diff view type properly', () => { const state = {}; |