diff options
Diffstat (limited to 'spec/frontend/diffs/components')
4 files changed, 68 insertions, 67 deletions
diff --git a/spec/frontend/diffs/components/app_spec.js b/spec/frontend/diffs/components/app_spec.js index b5eb3e1713c..1464dd84666 100644 --- a/spec/frontend/diffs/components/app_spec.js +++ b/spec/frontend/diffs/components/app_spec.js @@ -4,6 +4,7 @@ import MockAdapter from 'axios-mock-adapter'; import Mousetrap from 'mousetrap'; import Vue, { nextTick } from 'vue'; import Vuex from 'vuex'; +import setWindowLocation from 'helpers/set_window_location_helper'; import { TEST_HOST } from 'spec/test_constants'; import App from '~/diffs/components/app.vue'; import CommitWidget from '~/diffs/components/commit_widget.vue'; @@ -16,7 +17,6 @@ import TreeList from '~/diffs/components/tree_list.vue'; /* You know what: sometimes alphabetical isn't the best order */ import CollapsedFilesWarning from '~/diffs/components/collapsed_files_warning.vue'; import HiddenFilesWarning from '~/diffs/components/hidden_files_warning.vue'; -import MergeConflictWarning from '~/diffs/components/merge_conflict_warning.vue'; /* eslint-enable import/order */ import axios from '~/lib/utils/axios_utils'; @@ -258,6 +258,8 @@ describe('diffs/components/app', () => { }); it('marks current diff file based on currently highlighted row', async () => { + window.location.hash = 'ABC_123'; + createComponent({ shouldShow: true, }); @@ -428,12 +430,9 @@ describe('diffs/components/app', () => { jest.spyOn(wrapper.vm, 'refetchDiffData').mockImplementation(() => {}); jest.spyOn(wrapper.vm, 'adjustView').mockImplementation(() => {}); }; - let location; - beforeAll(() => { - location = window.location; - delete window.location; - window.location = COMMIT_URL; + beforeEach(() => { + setWindowLocation(COMMIT_URL); document.title = 'My Title'; }); @@ -441,10 +440,6 @@ describe('diffs/components/app', () => { jest.spyOn(urlUtils, 'updateHistory'); }); - afterAll(() => { - window.location = location; - }); - it('when the commit changes and the app is not loading it should update the history, refetch the diff data, and update the view', async () => { createComponent({}, ({ state }) => { state.diffs.commit = { ...state.diffs.commit, id: 'OLD' }; @@ -546,43 +541,6 @@ describe('diffs/components/app', () => { expect(getCollapsedFilesWarning(wrapper).exists()).toBe(false); }); }); - - describe('merge conflicts', () => { - it('should render the merge conflicts banner if viewing the whole changeset and there are conflicts', () => { - createComponent({}, ({ state }) => { - Object.assign(state.diffs, { - latestDiff: true, - startVersion: null, - hasConflicts: true, - canMerge: false, - conflictResolutionPath: 'path', - }); - }); - - expect(wrapper.find(MergeConflictWarning).exists()).toBe(true); - }); - - it.each` - prop | value - ${'latestDiff'} | ${false} - ${'startVersion'} | ${'notnull'} - ${'hasConflicts'} | ${false} - `( - "should not render if any of the MR properties aren't correct - like $prop: $value", - ({ prop, value }) => { - createComponent({}, ({ state }) => { - Object.assign(state.diffs, { - latestDiff: true, - startVersion: null, - hasConflicts: true, - [prop]: value, - }); - }); - - expect(wrapper.find(MergeConflictWarning).exists()).toBe(false); - }, - ); - }); }); it('should display commit widget if store has a commit', () => { diff --git a/spec/frontend/diffs/components/compare_versions_spec.js b/spec/frontend/diffs/components/compare_versions_spec.js index 80a51ee137a..1c0cb1193fa 100644 --- a/spec/frontend/diffs/components/compare_versions_spec.js +++ b/spec/frontend/diffs/components/compare_versions_spec.js @@ -1,5 +1,6 @@ import { mount, createLocalVue } from '@vue/test-utils'; import Vuex from 'vuex'; +import setWindowLocation from 'helpers/set_window_location_helper'; import { TEST_HOST } from 'helpers/test_constants'; import { trimText } from 'helpers/text_helper'; import CompareVersionsComponent from '~/diffs/components/compare_versions.vue'; @@ -13,6 +14,10 @@ localVue.use(Vuex); const NEXT_COMMIT_URL = `${TEST_HOST}/?commit_id=next`; const PREV_COMMIT_URL = `${TEST_HOST}/?commit_id=prev`; +beforeEach(() => { + setWindowLocation(TEST_HOST); +}); + describe('CompareVersions', () => { let wrapper; let store; @@ -215,15 +220,7 @@ describe('CompareVersions', () => { describe('prev commit', () => { beforeAll(() => { - global.jsdom.reconfigure({ - url: `${TEST_HOST}?commit_id=${mrCommit.id}`, - }); - }); - - afterAll(() => { - global.jsdom.reconfigure({ - url: TEST_HOST, - }); + setWindowLocation(`?commit_id=${mrCommit.id}`); }); beforeEach(() => { @@ -258,15 +255,7 @@ describe('CompareVersions', () => { describe('next commit', () => { beforeAll(() => { - global.jsdom.reconfigure({ - url: `${TEST_HOST}?commit_id=${mrCommit.id}`, - }); - }); - - afterAll(() => { - global.jsdom.reconfigure({ - url: TEST_HOST, - }); + setWindowLocation(`?commit_id=${mrCommit.id}`); }); beforeEach(() => { diff --git a/spec/frontend/diffs/components/diff_file_spec.js b/spec/frontend/diffs/components/diff_file_spec.js index 99dda8d5deb..3dec56f2fe3 100644 --- a/spec/frontend/diffs/components/diff_file_spec.js +++ b/spec/frontend/diffs/components/diff_file_spec.js @@ -521,4 +521,54 @@ describe('DiffFile', () => { expect(button.attributes('href')).toBe('/file/view/path'); }); }); + + it('loads collapsed file on mounted when single file mode is enabled', async () => { + wrapper.destroy(); + + const file = { + ...getReadableFile(), + load_collapsed_diff_url: '/diff_for_path', + highlighted_diff_lines: [], + parallel_diff_lines: [], + viewer: { name: 'collapsed', automaticallyCollapsed: true }, + }; + + axiosMock.onGet(file.load_collapsed_diff_url).reply(httpStatus.OK, getReadableFile()); + + ({ wrapper, store } = createComponent({ file, props: { viewDiffsFileByFile: true } })); + + await wrapper.vm.$nextTick(); + + expect(findLoader(wrapper).exists()).toBe(true); + }); + + describe('merge conflicts', () => { + beforeEach(() => { + wrapper.destroy(); + }); + + it('does not render conflict alert', () => { + const file = { + ...getReadableFile(), + conflict_type: null, + renderIt: true, + }; + + ({ wrapper, store } = createComponent({ file })); + + expect(wrapper.find('[data-testid="conflictsAlert"]').exists()).toBe(false); + }); + + it('renders conflict alert when conflict_type is present', () => { + const file = { + ...getReadableFile(), + conflict_type: 'both_modified', + renderIt: true, + }; + + ({ wrapper, store } = createComponent({ file })); + + expect(wrapper.find('[data-testid="conflictsAlert"]').exists()).toBe(true); + }); + }); }); diff --git a/spec/frontend/diffs/components/settings_dropdown_spec.js b/spec/frontend/diffs/components/settings_dropdown_spec.js index 43b9c5871a6..2dd35519464 100644 --- a/spec/frontend/diffs/components/settings_dropdown_spec.js +++ b/spec/frontend/diffs/components/settings_dropdown_spec.js @@ -48,13 +48,17 @@ describe('Diff settings dropdown component', () => { it('list view button dispatches setRenderTreeList with false', () => { wrapper.find('.js-list-view').trigger('click'); - expect(store.dispatch).toHaveBeenCalledWith('diffs/setRenderTreeList', false); + expect(store.dispatch).toHaveBeenCalledWith('diffs/setRenderTreeList', { + renderTreeList: false, + }); }); it('tree view button dispatches setRenderTreeList with true', () => { wrapper.find('.js-tree-view').trigger('click'); - expect(store.dispatch).toHaveBeenCalledWith('diffs/setRenderTreeList', true); + expect(store.dispatch).toHaveBeenCalledWith('diffs/setRenderTreeList', { + renderTreeList: true, + }); }); it('sets list button as selected when renderTreeList is false', () => { |