diff options
author | Phil Hughes <me@iamphill.com> | 2018-11-09 19:48:41 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-11-14 19:16:46 +0000 |
commit | 234563ba30d759870cb33d479116becb85e06eca (patch) | |
tree | fc9f553066f2d6a9ba8be7af20b181866750d246 /spec/javascripts | |
parent | 63b4b4b2688fa4f068772026536b2250bce39070 (diff) | |
download | gitlab-ce-234563ba30d759870cb33d479116becb85e06eca.tar.gz |
Made diff & note data consistent
This caused many pain points when working with it.
Part of the data was camel cased the other snake case.
Other parts where snake case & then getting converted in components,
this conversion has the potential for leaking memory.
This changes that & makes it consistent with what it returned from the
API, snake case.
Diffstat (limited to 'spec/javascripts')
16 files changed, 424 insertions, 426 deletions
diff --git a/spec/javascripts/diffs/components/commit_item_spec.js b/spec/javascripts/diffs/components/commit_item_spec.js index 7606847ada9..8b2ca6506c4 100644 --- a/spec/javascripts/diffs/components/commit_item_spec.js +++ b/spec/javascripts/diffs/components/commit_item_spec.js @@ -21,7 +21,7 @@ const getAvatarElement = vm => vm.$el.querySelector('.user-avatar-link'); const getCommitterElement = vm => vm.$el.querySelector('.commiter'); const getCommitActionsElement = vm => vm.$el.querySelector('.commit-actions'); -describe('diffs/components/commit_widget', () => { +describe('diffs/components/commit_item', () => { const Component = Vue.extend(CommitItem); const timeago = getTimeago(); const { commit } = getDiffWithCommit(); @@ -37,15 +37,15 @@ describe('diffs/components/commit_widget', () => { it('renders commit title', () => { const titleElement = getTitleElement(vm); - expect(titleElement).toHaveAttr('href', commit.commitUrl); - expect(titleElement).toHaveText(commit.titleHtml); + expect(titleElement).toHaveAttr('href', commit.commit_url); + expect(titleElement).toHaveText(commit.title_html); }); it('renders commit description', () => { const descElement = getDescElement(vm); const descExpandElement = getDescExpandElement(vm); - const expected = commit.descriptionHtml.replace(/
/g, ''); + const expected = commit.description_html.replace(/
/g, ''); expect(trimText(descElement.innerHTML)).toEqual(trimText(expected)); expect(descExpandElement).not.toBeNull(); @@ -56,7 +56,7 @@ describe('diffs/components/commit_widget', () => { const labelElement = shaElement.querySelector('.label'); const buttonElement = shaElement.querySelector('button'); - expect(labelElement.textContent).toEqual(commit.shortId); + expect(labelElement.textContent).toEqual(commit.short_id); expect(buttonElement).toHaveData('clipboard-text', commit.id); }); @@ -64,27 +64,27 @@ describe('diffs/components/commit_widget', () => { const avatarElement = getAvatarElement(vm); const imgElement = avatarElement.querySelector('img'); - expect(avatarElement).toHaveAttr('href', commit.author.webUrl); + expect(avatarElement).toHaveAttr('href', commit.author.web_url); expect(imgElement).toHaveClass('s36'); expect(imgElement).toHaveAttr('alt', commit.author.name); - expect(imgElement).toHaveAttr('src', commit.author.avatarUrl); + expect(imgElement).toHaveAttr('src', commit.author.avatar_url); }); it('renders committer text', () => { const committerElement = getCommitterElement(vm); const nameElement = committerElement.querySelector('a'); - const expectTimeText = timeago.format(commit.authoredDate); + const expectTimeText = timeago.format(commit.authored_date); const expectedText = `${commit.author.name} authored ${expectTimeText}`; expect(trimText(committerElement.textContent)).toEqual(expectedText); - expect(nameElement).toHaveAttr('href', commit.author.webUrl); + expect(nameElement).toHaveAttr('href', commit.author.web_url); expect(nameElement).toHaveText(commit.author.name); }); describe('without commit description', () => { beforeEach(done => { - vm.commit.descriptionHtml = ''; + vm.commit.description_html = ''; vm.$nextTick() .then(done) @@ -103,9 +103,9 @@ describe('diffs/components/commit_widget', () => { describe('with no matching user', () => { beforeEach(done => { vm.commit.author = null; - vm.commit.authorEmail = TEST_AUTHOR_EMAIL; - vm.commit.authorName = TEST_AUTHOR_NAME; - vm.commit.authorGravatarUrl = TEST_AUTHOR_GRAVATAR; + vm.commit.author_email = TEST_AUTHOR_EMAIL; + vm.commit.author_name = TEST_AUTHOR_NAME; + vm.commit.author_gravatar_url = TEST_AUTHOR_GRAVATAR; vm.$nextTick() .then(done) @@ -132,7 +132,7 @@ describe('diffs/components/commit_widget', () => { describe('with signature', () => { beforeEach(done => { - vm.commit.signatureHtml = TEST_SIGNATURE_HTML; + vm.commit.signature_html = TEST_SIGNATURE_HTML; vm.$nextTick() .then(done) @@ -148,7 +148,7 @@ describe('diffs/components/commit_widget', () => { describe('with pipeline status', () => { beforeEach(done => { - vm.commit.pipelineStatusPath = TEST_PIPELINE_STATUS_PATH; + vm.commit.pipeline_status_path = TEST_PIPELINE_STATUS_PATH; vm.$nextTick() .then(done) diff --git a/spec/javascripts/diffs/components/commit_widget_spec.js b/spec/javascripts/diffs/components/commit_widget_spec.js index 951eb57255d..2b60bd232ed 100644 --- a/spec/javascripts/diffs/components/commit_widget_spec.js +++ b/spec/javascripts/diffs/components/commit_widget_spec.js @@ -19,6 +19,6 @@ describe('diffs/components/commit_widget', () => { const commitElement = vm.$el.querySelector('li.commit'); expect(commitElement).not.toBeNull(); - expect(commitElement).toContainText(commit.shortId); + expect(commitElement).toContainText(commit.short_id); }); }); diff --git a/spec/javascripts/diffs/components/diff_content_spec.js b/spec/javascripts/diffs/components/diff_content_spec.js index 36bd042f3c4..c25f6167163 100644 --- a/spec/javascripts/diffs/components/diff_content_spec.js +++ b/spec/javascripts/diffs/components/diff_content_spec.js @@ -56,14 +56,14 @@ describe('DiffContent', () => { describe('image diff', () => { beforeEach(done => { - vm.diffFile.newPath = GREEN_BOX_IMAGE_URL; - vm.diffFile.newSha = 'DEF'; - vm.diffFile.oldPath = RED_BOX_IMAGE_URL; - vm.diffFile.oldSha = 'ABC'; - vm.diffFile.viewPath = ''; + vm.diffFile.new_path = GREEN_BOX_IMAGE_URL; + vm.diffFile.new_sha = 'DEF'; + vm.diffFile.old_path = RED_BOX_IMAGE_URL; + vm.diffFile.old_sha = 'ABC'; + vm.diffFile.view_path = ''; vm.diffFile.discussions = [{ ...discussionsMockData }]; vm.$store.state.diffs.commentForms.push({ - fileHash: vm.diffFile.fileHash, + fileHash: vm.diffFile.file_hash, x: 10, y: 20, width: 100, @@ -113,10 +113,10 @@ describe('DiffContent', () => { describe('file diff', () => { it('should have download buttons in place', done => { const el = vm.$el; - vm.diffFile.newPath = 'test.abc'; - vm.diffFile.newSha = 'DEF'; - vm.diffFile.oldPath = 'test.abc'; - vm.diffFile.oldSha = 'ABC'; + vm.diffFile.new_path = 'test.abc'; + vm.diffFile.new_sha = 'DEF'; + vm.diffFile.old_path = 'test.abc'; + vm.diffFile.old_sha = 'ABC'; vm.$nextTick(() => { expect(el.querySelectorAll('.js-diff-inline-view').length).toEqual(0); diff --git a/spec/javascripts/diffs/components/diff_file_header_spec.js b/spec/javascripts/diffs/components/diff_file_header_spec.js index 0192d583c6c..9530b50c729 100644 --- a/spec/javascripts/diffs/components/diff_file_header_spec.js +++ b/spec/javascripts/diffs/components/diff_file_header_spec.js @@ -3,7 +3,6 @@ import Vuex from 'vuex'; import diffsModule from '~/diffs/store/modules'; import notesModule from '~/notes/stores/modules'; import DiffFileHeader from '~/diffs/components/diff_file_header.vue'; -import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; Vue.use(Vuex); @@ -24,9 +23,9 @@ describe('diff_file_header', () => { }); beforeEach(() => { - const diffFile = convertObjectPropsToCamelCase(diffDiscussionMock.diff_file, { deep: true }); + const diffFile = diffDiscussionMock.diff_file; props = { - diffFile, + diffFile: { ...diffFile }, canCurrentUserFork: false, }; }); @@ -62,8 +61,8 @@ describe('diff_file_header', () => { beforeEach(() => { props.discussionPath = 'link://to/discussion'; Object.assign(props.diffFile, { - submoduleLink: 'link://to/submodule', - submoduleTreeUrl: 'some://tree/url', + submodule_link: 'link://to/submodule', + submodule_tree_url: 'some://tree/url', }); }); @@ -80,18 +79,18 @@ describe('diff_file_header', () => { vm = mountComponentWithStore(Component, { props, store }); - expect(vm.titleLink).toBe(props.diffFile.submoduleTreeUrl); + expect(vm.titleLink).toBe(props.diffFile.submodule_tree_url); }); it('returns the submoduleLink for submodules without submoduleTreeUrl', () => { Object.assign(props.diffFile, { submodule: true, - submoduleTreeUrl: null, + submodule_tree_url: null, }); vm = mountComponentWithStore(Component, { props, store }); - expect(vm.titleLink).toBe(props.diffFile.submoduleLink); + expect(vm.titleLink).toBe(props.diffFile.submodule_link); }); it('sets the correct path to the discussion', () => { @@ -107,7 +106,7 @@ describe('diff_file_header', () => { beforeEach(() => { Object.assign(props.diffFile, { blob: { id: 'b10b1db10b1d' }, - filePath: 'path/to/file', + file_path: 'path/to/file', }); }); @@ -116,7 +115,7 @@ describe('diff_file_header', () => { vm = mountComponentWithStore(Component, { props, store }); - expect(vm.filePath).toBe(props.diffFile.filePath); + expect(vm.filePath).toBe(props.diffFile.file_path); }); it('appends the truncated blob id for submodules', () => { @@ -125,14 +124,14 @@ describe('diff_file_header', () => { vm = mountComponentWithStore(Component, { props, store }); expect(vm.filePath).toBe( - `${props.diffFile.filePath} @ ${props.diffFile.blob.id.substr(0, 8)}`, + `${props.diffFile.file_path} @ ${props.diffFile.blob.id.substr(0, 8)}`, ); }); }); describe('titleTag', () => { it('returns a link tag if fileHash is set', () => { - props.diffFile.fileHash = 'some hash'; + props.diffFile.file_hash = 'some hash'; vm = mountComponentWithStore(Component, { props, store }); @@ -140,7 +139,7 @@ describe('diff_file_header', () => { }); it('returns a span tag if fileHash is not set', () => { - props.diffFile.fileHash = null; + props.diffFile.file_hash = null; vm = mountComponentWithStore(Component, { props, store }); @@ -151,8 +150,8 @@ describe('diff_file_header', () => { describe('isUsingLfs', () => { beforeEach(() => { Object.assign(props.diffFile, { - storedExternally: true, - externalStorage: 'lfs', + stored_externally: true, + external_storage: 'lfs', }); }); @@ -163,7 +162,7 @@ describe('diff_file_header', () => { }); it('returns false if file is not stored externally', () => { - props.diffFile.storedExternally = false; + props.diffFile.stored_externally = false; vm = mountComponentWithStore(Component, { props, store }); @@ -171,7 +170,7 @@ describe('diff_file_header', () => { }); it('returns false if file is not stored in LFS', () => { - props.diffFile.externalStorage = 'not lfs'; + props.diffFile.external_storage = 'not lfs'; vm = mountComponentWithStore(Component, { props, store }); @@ -200,7 +199,7 @@ describe('diff_file_header', () => { describe('viewFileButtonText', () => { it('contains the truncated content SHA', () => { const dummySha = 'deebd00f is no SHA'; - props.diffFile.contentSha = dummySha; + props.diffFile.content_sha = dummySha; vm = mountComponentWithStore(Component, { props, store }); @@ -212,7 +211,7 @@ describe('diff_file_header', () => { describe('viewReplacedFileButtonText', () => { it('contains the truncated base SHA', () => { const dummySha = 'deadabba sings no more'; - props.diffFile.diffRefs.baseSha = dummySha; + props.diffFile.diff_refs.base_sha = dummySha; vm = mountComponentWithStore(Component, { props, store }); @@ -281,32 +280,32 @@ describe('diff_file_header', () => { const filePaths = () => vm.$el.querySelectorAll('.file-title-name'); it('displays the path of a added file', () => { - props.diffFile.renamedFile = false; + props.diffFile.renamed_file = false; vm = mountComponentWithStore(Component, { props, store }); expect(filePaths()).toHaveLength(1); - expect(filePaths()[0]).toHaveText(props.diffFile.filePath); + expect(filePaths()[0]).toHaveText(props.diffFile.file_path); }); it('displays path for deleted file', () => { - props.diffFile.renamedFile = false; - props.diffFile.deletedFile = true; + props.diffFile.renamed_file = false; + props.diffFile.deleted_file = true; vm = mountComponentWithStore(Component, { props, store }); expect(filePaths()).toHaveLength(1); - expect(filePaths()[0]).toHaveText(`${props.diffFile.filePath} deleted`); + expect(filePaths()[0]).toHaveText(`${props.diffFile.file_path} deleted`); }); it('displays old and new path if the file was renamed', () => { - props.diffFile.renamedFile = true; + props.diffFile.renamed_file = true; vm = mountComponentWithStore(Component, { props, store }); expect(filePaths()).toHaveLength(2); - expect(filePaths()[0]).toHaveText(props.diffFile.oldPath); - expect(filePaths()[1]).toHaveText(props.diffFile.newPath); + expect(filePaths()[0]).toHaveText(props.diffFile.old_path); + expect(filePaths()[1]).toHaveText(props.diffFile.new_path); }); }); @@ -323,19 +322,19 @@ describe('diff_file_header', () => { describe('file mode', () => { it('it displays old and new file mode if it changed', () => { - props.diffFile.modeChanged = true; + props.diffFile.mode_changed = true; vm = mountComponentWithStore(Component, { props, store }); const { fileMode } = vm.$refs; expect(fileMode).not.toBe(undefined); - expect(fileMode).toContainText(props.diffFile.aMode); - expect(fileMode).toContainText(props.diffFile.bMode); + expect(fileMode).toContainText(props.diffFile.a_mode); + expect(fileMode).toContainText(props.diffFile.b_mode); }); it('does not display the file mode if it has not changed', () => { - props.diffFile.modeChanged = false; + props.diffFile.mode_changed = false; vm = mountComponentWithStore(Component, { props, store }); @@ -350,8 +349,8 @@ describe('diff_file_header', () => { it('displays the LFS label for files stored in LFS', () => { Object.assign(props.diffFile, { - storedExternally: true, - externalStorage: 'lfs', + stored_externally: true, + external_storage: 'lfs', }); vm = mountComponentWithStore(Component, { props, store }); @@ -361,7 +360,7 @@ describe('diff_file_header', () => { }); it('does not display the LFS label for files stored in repository', () => { - props.diffFile.storedExternally = false; + props.diffFile.stored_externally = false; vm = mountComponentWithStore(Component, { props, store }); @@ -378,7 +377,7 @@ describe('diff_file_header', () => { it('should show edit button when file is editable', () => { props.addMergeRequestButtons = true; - props.diffFile.editPath = '/'; + props.diffFile.edit_path = '/'; vm = mountComponentWithStore(Component, { props, store }); expect(vm.$el.querySelector('.js-edit-blob')).toContainText('Edit'); @@ -386,8 +385,8 @@ describe('diff_file_header', () => { it('should not show edit button when file is deleted', () => { props.addMergeRequestButtons = true; - props.diffFile.deletedFile = true; - props.diffFile.editPath = '/'; + props.diffFile.deleted_file = true; + props.diffFile.edit_path = '/'; vm = mountComponentWithStore(Component, { props, store }); expect(vm.$el.querySelector('.js-edit-blob')).toEqual(null); @@ -397,7 +396,7 @@ describe('diff_file_header', () => { describe('addMergeRequestButtons', () => { beforeEach(() => { props.addMergeRequestButtons = true; - props.diffFile.editPath = ''; + props.diffFile.edit_path = ''; }); describe('view on environment button', () => { @@ -405,8 +404,8 @@ describe('diff_file_header', () => { const title = 'url.title'; it('displays link to external url', () => { - props.diffFile.externalUrl = url; - props.diffFile.formattedExternalUrl = title; + props.diffFile.external_url = url; + props.diffFile.formatted_external_url = title; vm = mountComponentWithStore(Component, { props, store }); @@ -415,8 +414,8 @@ describe('diff_file_header', () => { }); it('hides link if no external url', () => { - props.diffFile.externalUrl = ''; - props.diffFile.formattedExternalUrl = title; + props.diffFile.external_url = ''; + props.diffFile.formattedExternal_url = title; vm = mountComponentWithStore(Component, { props, store }); @@ -434,11 +433,11 @@ describe('diff_file_header', () => { path: 'lib/base.js', name: 'base.js', mode: '100644', - readableText: true, + readable_text: true, icon: 'file-text-o', }; propsCopy.addMergeRequestButtons = true; - propsCopy.diffFile.deletedFile = true; + propsCopy.diffFile.deleted_file = true; vm = mountComponentWithStore(Component, { props: propsCopy, @@ -459,11 +458,11 @@ describe('diff_file_header', () => { path: 'lib/base.js', name: 'base.js', mode: '100644', - readableText: true, + readable_text: true, icon: 'file-text-o', }; propsCopy.addMergeRequestButtons = true; - propsCopy.diffFile.deletedFile = true; + propsCopy.diffFile.deleted_file = true; const discussionGetter = () => [diffDiscussionMock]; const notesModuleMock = notesModule(); diff --git a/spec/javascripts/diffs/components/diff_file_spec.js b/spec/javascripts/diffs/components/diff_file_spec.js index 431944eee96..51bb4807960 100644 --- a/spec/javascripts/diffs/components/diff_file_spec.js +++ b/spec/javascripts/diffs/components/diff_file_spec.js @@ -17,14 +17,14 @@ describe('DiffFile', () => { describe('template', () => { it('should render component with file header, file content components', () => { const el = vm.$el; - const { fileHash, filePath } = vm.file; + const { file_hash, file_path } = vm.file; - expect(el.id).toEqual(fileHash); + expect(el.id).toEqual(file_hash); expect(el.classList.contains('diff-file')).toEqual(true); expect(el.querySelectorAll('.diff-content.hidden').length).toEqual(0); expect(el.querySelector('.js-file-title')).toBeDefined(); - expect(el.querySelector('.file-title-name').innerText.indexOf(filePath)).toBeGreaterThan(-1); + expect(el.querySelector('.file-title-name').innerText.indexOf(file_path)).toBeGreaterThan(-1); expect(el.querySelector('.js-syntax-highlight')).toBeDefined(); expect(vm.file.renderIt).toEqual(false); @@ -52,7 +52,7 @@ describe('DiffFile', () => { it('should have collapsed text and link', done => { vm.file.renderIt = true; vm.file.collapsed = false; - vm.file.highlightedDiffLines = null; + vm.file.highlighted_diff_lines = null; vm.$nextTick(() => { expect(vm.$el.innerText).toContain('This diff is collapsed'); @@ -90,8 +90,8 @@ describe('DiffFile', () => { describe('too large diff', () => { it('should have too large warning and blob link', done => { const BLOB_LINK = '/file/view/path'; - vm.file.tooLarge = true; - vm.file.viewPath = BLOB_LINK; + vm.file.too_large = true; + vm.file.view_path = BLOB_LINK; vm.$nextTick(() => { expect(vm.$el.innerText).toContain( @@ -112,8 +112,8 @@ describe('DiffFile', () => { it('calls handleLoadCollapsedDiff if collapsed changed & file has no lines', done => { spyOn(vm, 'handleLoadCollapsedDiff'); - vm.file.highlightedDiffLines = undefined; - vm.file.parallelDiffLines = []; + vm.file.highlighted_diff_lines = undefined; + vm.file.parallel_diff_lines = []; vm.file.collapsed = true; vm.$nextTick() diff --git a/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js b/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js index 6972e0ee913..038db8eaa7c 100644 --- a/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js +++ b/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js @@ -11,16 +11,16 @@ describe('DiffLineGutterContent', () => { const cmp = Vue.extend(DiffLineGutterContent); const props = Object.assign({}, options); props.line = { - lineCode: 'LC_42', + line_code: 'LC_42', type: 'new', - oldLine: null, - newLine: 1, - discussions: [], + old_line: null, + new_line: 1, + discussions: [{ ...discussionsMockData }], text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', - richText: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', - metaData: null, + rich_text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', + meta_data: null, }; - props.fileHash = getDiffFileMock().fileHash; + props.fileHash = getDiffFileMock().file_hash; props.contextLinesPath = '/context/lines/path'; return createComponentWithStore(cmp, store, props).$mount(); @@ -37,7 +37,7 @@ describe('DiffLineGutterContent', () => { it('should return # if there is no lineCode', () => { const component = createComponent(); - component.line.lineCode = ''; + component.line.line_code = ''; expect(component.lineHref).toEqual('#'); }); @@ -46,6 +46,7 @@ describe('DiffLineGutterContent', () => { describe('discussions, hasDiscussions, shouldShowAvatarsOnGutter', () => { it('should return empty array when there is no discussion', () => { const component = createComponent(); + component.line.discussions = []; expect(component.hasDiscussions).toEqual(false); expect(component.shouldShowAvatarsOnGutter).toEqual(false); @@ -54,8 +55,8 @@ describe('DiffLineGutterContent', () => { it('should return discussions for the given lineCode', () => { const cmp = Vue.extend(DiffLineGutterContent); const props = { - line: getDiffFileMock().highlightedDiffLines[1], - fileHash: getDiffFileMock().fileHash, + line: getDiffFileMock().highlighted_diff_lines[1], + fileHash: getDiffFileMock().file_hash, showCommentButton: true, contextLinesPath: '/context/lines/path', }; @@ -104,10 +105,10 @@ describe('DiffLineGutterContent', () => { it('should render user avatars', () => { const component = createComponent({ showCommentButton: true, - lineCode: getDiffFileMock().highlightedDiffLines[1].lineCode, + lineCode: getDiffFileMock().highlighted_diff_lines[1].line_code, }); - expect(component.$el.querySelector('.diff-comment-avatar-holders')).toBeDefined(); + expect(component.$el.querySelector('.diff-comment-avatar-holders')).not.toBe(null); }); }); }); diff --git a/spec/javascripts/diffs/components/diff_line_note_form_spec.js b/spec/javascripts/diffs/components/diff_line_note_form_spec.js index c39b54d9cc9..81b66cf7c9b 100644 --- a/spec/javascripts/diffs/components/diff_line_note_form_spec.js +++ b/spec/javascripts/diffs/components/diff_line_note_form_spec.js @@ -13,10 +13,10 @@ describe('DiffLineNoteForm', () => { beforeEach(() => { diffFile = getDiffFileMock(); - diffLines = diffFile.highlightedDiffLines; + diffLines = diffFile.highlighted_diff_lines; component = createComponentWithStore(Vue.extend(DiffLineNoteForm), store, { - diffFileHash: diffFile.fileHash, + diffFileHash: diffFile.file_hash, diffLines, line: diffLines[0], noteTargetLine: diffLines[0], @@ -61,7 +61,7 @@ describe('DiffLineNoteForm', () => { expect(window.confirm).not.toHaveBeenCalled(); component.$nextTick(() => { expect(component.cancelCommentForm).toHaveBeenCalledWith({ - lineCode: diffLines[0].lineCode, + lineCode: diffLines[0].line_code, }); expect(component.resetAutoSave).toHaveBeenCalled(); diff --git a/spec/javascripts/diffs/components/inline_diff_view_spec.js b/spec/javascripts/diffs/components/inline_diff_view_spec.js index 705558e860b..2316ee29106 100644 --- a/spec/javascripts/diffs/components/inline_diff_view_spec.js +++ b/spec/javascripts/diffs/components/inline_diff_view_spec.js @@ -1,4 +1,5 @@ import Vue from 'vue'; +import '~/behaviors/markdown/render_gfm'; import InlineDiffView from '~/diffs/components/inline_diff_view.vue'; import store from '~/mr_notes/stores'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; @@ -10,14 +11,16 @@ describe('InlineDiffView', () => { const getDiffFileMock = () => Object.assign({}, diffFileMockData); const getDiscussionsMockData = () => [Object.assign({}, discussionsMockData)]; - beforeEach(() => { + beforeEach(done => { const diffFile = getDiffFileMock(); store.dispatch('diffs/setInlineDiffViewType'); component = createComponentWithStore(Vue.extend(InlineDiffView), store, { diffFile, - diffLines: diffFile.highlightedDiffLines, + diffLines: diffFile.highlighted_diff_lines, }).$mount(); + + Vue.nextTick(done); }); describe('template', () => { @@ -32,7 +35,7 @@ describe('InlineDiffView', () => { it('should render discussions', done => { const el = component.$el; - component.$store.dispatch('setInitialNotes', getDiscussionsMockData()); + component.diffLines[1].discussions = getDiscussionsMockData(); Vue.nextTick(() => { expect(el.querySelectorAll('.notes_holder').length).toEqual(1); diff --git a/spec/javascripts/diffs/components/parallel_diff_view_spec.js b/spec/javascripts/diffs/components/parallel_diff_view_spec.js index 091e01868d3..6f6b1c41915 100644 --- a/spec/javascripts/diffs/components/parallel_diff_view_spec.js +++ b/spec/javascripts/diffs/components/parallel_diff_view_spec.js @@ -14,7 +14,7 @@ describe('ParallelDiffView', () => { component = createComponentWithStore(Vue.extend(ParallelDiffView), store, { diffFile, - diffLines: diffFile.parallelDiffLines, + diffLines: diffFile.parallel_diff_lines, }).$mount(); }); diff --git a/spec/javascripts/diffs/mock_data/diff_file.js b/spec/javascripts/diffs/mock_data/diff_file.js index be194ab414f..031c9842f2f 100644 --- a/spec/javascripts/diffs/mock_data/diff_file.js +++ b/spec/javascripts/diffs/mock_data/diff_file.js @@ -1,130 +1,130 @@ export default { submodule: false, - submoduleLink: null, + submodule_link: null, blob: { id: '9e10516ca50788acf18c518a231914a21e5f16f7', path: 'CHANGELOG', name: 'CHANGELOG', mode: '100644', - readableText: true, + readable_text: true, icon: 'file-text-o', }, - blobPath: 'CHANGELOG', - blobName: 'CHANGELOG', - blobIcon: '<i aria-hidden="true" data-hidden="true" class="fa fa-file-text-o fa-fw"></i>', - fileHash: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a', - filePath: 'CHANGELOG', - newFile: false, - deletedFile: false, - renamedFile: false, - oldPath: 'CHANGELOG', - newPath: 'CHANGELOG', - modeChanged: false, - aMode: '100644', - bMode: '100644', + blob_path: 'CHANGELOG', + blob_name: 'CHANGELOG', + blob_icon: '<i aria-hidden="true" data-hidden="true" class="fa fa-file-text-o fa-fw"></i>', + file_hash: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a', + file_path: 'CHANGELOG', + new_file: false, + deleted_file: false, + renamed_file: false, + old_path: 'CHANGELOG', + new_path: 'CHANGELOG', + mode_changed: false, + a_mode: '100644', + b_mode: '100644', text: true, viewer: { name: 'text', }, - addedLines: 2, - removedLines: 0, - diffRefs: { - baseSha: 'e63f41fe459e62e1228fcef60d7189127aeba95a', - startSha: 'd9eaefe5a676b820c57ff18cf5b68316025f7962', - headSha: 'c48ee0d1bf3b30453f5b32250ce03134beaa6d13', + added_lines: 2, + removed_lines: 0, + diff_refs: { + base_sha: 'e63f41fe459e62e1228fcef60d7189127aeba95a', + start_sha: 'd9eaefe5a676b820c57ff18cf5b68316025f7962', + head_sha: 'c48ee0d1bf3b30453f5b32250ce03134beaa6d13', }, - contentSha: 'c48ee0d1bf3b30453f5b32250ce03134beaa6d13', - storedExternally: null, - externalStorage: null, - oldPathHtml: 'CHANGELOG', - newPathHtml: 'CHANGELOG', - editPath: '/gitlab-org/gitlab-test/edit/spooky-stuff/CHANGELOG', - viewPath: '/gitlab-org/gitlab-test/blob/spooky-stuff/CHANGELOG', - replacedViewPath: null, + content_sha: 'c48ee0d1bf3b30453f5b32250ce03134beaa6d13', + stored_externally: null, + external_storage: null, + old_path_html: 'CHANGELOG', + new_path_html: 'CHANGELOG', + edit_path: '/gitlab-org/gitlab-test/edit/spooky-stuff/CHANGELOG', + view_path: '/gitlab-org/gitlab-test/blob/spooky-stuff/CHANGELOG', + replaced_view_path: null, collapsed: false, renderIt: false, - tooLarge: false, - contextLinesPath: + too_large: false, + context_lines_path: '/gitlab-org/gitlab-test/blob/c48ee0d1bf3b30453f5b32250ce03134beaa6d13/CHANGELOG/diff', - highlightedDiffLines: [ + highlighted_diff_lines: [ { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1', + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1', type: 'new', - oldLine: null, - newLine: 1, + old_line: null, + new_line: 1, discussions: [], text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', - richText: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', - metaData: null, + rich_text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', + meta_data: null, }, { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', type: 'new', - oldLine: null, - newLine: 2, + old_line: null, + new_line: 2, discussions: [], text: '+<span id="LC2" class="line" lang="plaintext"></span>\n', - richText: '+<span id="LC2" class="line" lang="plaintext"></span>\n', - metaData: null, + rich_text: '+<span id="LC2" class="line" lang="plaintext"></span>\n', + meta_data: null, }, { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', type: null, - oldLine: 1, - newLine: 3, + old_line: 1, + new_line: 3, discussions: [], text: ' <span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n', - richText: ' <span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n', - metaData: null, + rich_text: ' <span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n', + meta_data: null, }, { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4', + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4', type: null, - oldLine: 2, - newLine: 4, + old_line: 2, + new_line: 4, discussions: [], text: ' <span id="LC4" class="line" lang="plaintext"></span>\n', - richText: ' <span id="LC4" class="line" lang="plaintext"></span>\n', - metaData: null, + rich_text: ' <span id="LC4" class="line" lang="plaintext"></span>\n', + meta_data: null, }, { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5', + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5', type: null, - oldLine: 3, - newLine: 5, + old_line: 3, + new_line: 5, discussions: [], text: ' <span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n', - richText: ' <span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n', - metaData: null, + rich_text: ' <span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n', + meta_data: null, }, { - lineCode: null, + line_code: null, type: 'match', - oldLine: null, - newLine: null, + old_line: null, + new_line: null, discussions: [], text: '', - richText: '', - metaData: { - oldPos: 3, - newPos: 5, + rich_text: '', + meta_data: { + old_pos: 3, + new_pos: 5, }, }, ], - parallelDiffLines: [ + parallel_diff_lines: [ { left: { type: 'empty-cell', }, right: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1', + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1', type: 'new', - oldLine: null, - newLine: 1, + old_line: null, + new_line: 1, discussions: [], text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', - richText: '<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', - metaData: null, + rich_text: '<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', + meta_data: null, }, }, { @@ -132,107 +132,107 @@ export default { type: 'empty-cell', }, right: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', type: 'new', - oldLine: null, - newLine: 2, + old_line: null, + new_line: 2, discussions: [], text: '+<span id="LC2" class="line" lang="plaintext"></span>\n', - richText: '<span id="LC2" class="line" lang="plaintext"></span>\n', - metaData: null, + rich_text: '<span id="LC2" class="line" lang="plaintext"></span>\n', + meta_data: null, }, }, { left: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', + line_Code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', type: null, - oldLine: 1, - newLine: 3, + old_line: 1, + new_line: 3, discussions: [], text: ' <span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n', - richText: '<span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n', - metaData: null, + rich_text: '<span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n', + meta_data: null, }, right: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', type: null, - oldLine: 1, - newLine: 3, + old_line: 1, + new_line: 3, discussions: [], text: ' <span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n', - richText: '<span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n', - metaData: null, + rich_text: '<span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n', + meta_data: null, }, }, { left: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4', + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4', type: null, - oldLine: 2, - newLine: 4, + old_line: 2, + new_line: 4, discussions: [], text: ' <span id="LC4" class="line" lang="plaintext"></span>\n', - richText: '<span id="LC4" class="line" lang="plaintext"></span>\n', - metaData: null, + rich_text: '<span id="LC4" class="line" lang="plaintext"></span>\n', + meta_data: null, }, right: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4', + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4', type: null, - oldLine: 2, - newLine: 4, + old_line: 2, + new_line: 4, discussions: [], text: ' <span id="LC4" class="line" lang="plaintext"></span>\n', - richText: '<span id="LC4" class="line" lang="plaintext"></span>\n', - metaData: null, + rich_text: '<span id="LC4" class="line" lang="plaintext"></span>\n', + meta_data: null, }, }, { left: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5', + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5', type: null, - oldLine: 3, - newLine: 5, + old_line: 3, + new_line: 5, discussions: [], text: ' <span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n', - richText: '<span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n', - metaData: null, + rich_text: '<span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n', + meta_data: null, }, right: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5', + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5', type: null, - oldLine: 3, - newLine: 5, + old_line: 3, + new_line: 5, discussions: [], text: ' <span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n', - richText: '<span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n', - metaData: null, + rich_text: '<span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n', + meta_data: null, }, }, { left: { - lineCode: null, + line_code: null, type: 'match', - oldLine: null, - newLine: null, + old_line: null, + new_line: null, discussions: [], text: '', - richText: '', - metaData: { - oldPos: 3, - newPos: 5, + rich_text: '', + meta_data: { + old_pos: 3, + new_pos: 5, }, }, right: { - lineCode: null, + line_code: null, type: 'match', - oldLine: null, - newLine: null, + old_line: null, + new_line: null, discussions: [], text: '', - richText: '', - metaData: { - oldPos: 3, - newPos: 5, + rich_text: '', + meta_data: { + old_pos: 3, + new_pos: 5, }, }, }, diff --git a/spec/javascripts/diffs/mock_data/diff_with_commit.js b/spec/javascripts/diffs/mock_data/diff_with_commit.js index bee04fa4932..d646294ee84 100644 --- a/spec/javascripts/diffs/mock_data/diff_with_commit.js +++ b/spec/javascripts/diffs/mock_data/diff_with_commit.js @@ -1,9 +1,7 @@ -import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; - const FIXTURE = 'merge_request_diffs/with_commit.json'; preloadFixtures(FIXTURE); export default function getDiffWithCommit() { - return convertObjectPropsToCamelCase(getJSONFixture(FIXTURE), { deep: true }); + return getJSONFixture(FIXTURE); } diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js index 17d0f31bdd3..d94a9cd1710 100644 --- a/spec/javascripts/diffs/store/actions_spec.js +++ b/spec/javascripts/diffs/store/actions_spec.js @@ -97,46 +97,46 @@ describe('DiffsStoreActions', () => { const state = { diffFiles: [ { - fileHash: 'ABC', - parallelDiffLines: [ + file_hash: 'ABC', + parallel_diff_lines: [ { left: { - lineCode: 'ABC_1_1', + line_code: 'ABC_1_1', discussions: [], }, right: { - lineCode: 'ABC_1_1', + line_code: 'ABC_1_1', discussions: [], }, }, ], - highlightedDiffLines: [ + highlighted_diff_lines: [ { - lineCode: 'ABC_1_1', + line_code: 'ABC_1_1', discussions: [], - oldLine: 5, - newLine: null, + old_line: 5, + new_line: null, }, ], - diffRefs: { - baseSha: 'abc', - headSha: 'def', - startSha: 'ghi', + diff_refs: { + base_sha: 'abc', + head_sha: 'def', + start_sha: 'ghi', }, - newPath: 'file1', - oldPath: 'file2', + new_path: 'file1', + old_path: 'file2', }, ], }; const diffPosition = { - baseSha: 'abc', - headSha: 'def', - startSha: 'ghi', - newLine: null, - newPath: 'file1', - oldLine: 5, - oldPath: 'file2', + base_sha: 'abc', + head_sha: 'def', + start_sha: 'ghi', + new_line: null, + new_path: 'file1', + old_line: 5, + old_path: 'file2', }; const singleDiscussion = { @@ -145,7 +145,7 @@ describe('DiffsStoreActions', () => { diff_file: { file_hash: 'ABC', }, - fileHash: 'ABC', + file_hash: 'ABC', resolvable: true, position: diffPosition, original_position: diffPosition, @@ -164,24 +164,22 @@ describe('DiffsStoreActions', () => { discussion: singleDiscussion, diffPositionByLineCode: { ABC_1_1: { - baseSha: 'abc', - headSha: 'def', - startSha: 'ghi', - newLine: null, - newPath: 'file1', - oldLine: 5, - oldPath: 'file2', - lineCode: 'ABC_1_1', - positionType: 'text', + base_sha: 'abc', + head_sha: 'def', + start_sha: 'ghi', + new_line: null, + new_path: 'file1', + old_line: 5, + old_path: 'file2', + line_code: 'ABC_1_1', + position_type: 'text', }, }, }, }, ], [], - () => { - done(); - }, + done, ); }); }); @@ -191,11 +189,11 @@ describe('DiffsStoreActions', () => { const state = { diffFiles: [ { - fileHash: 'ABC', - parallelDiffLines: [ + file_hash: 'ABC', + parallel_diff_lines: [ { left: { - lineCode: 'ABC_1_1', + line_code: 'ABC_1_1', discussions: [ { id: 1, @@ -203,14 +201,14 @@ describe('DiffsStoreActions', () => { ], }, right: { - lineCode: 'ABC_1_1', + line_code: 'ABC_1_1', discussions: [], }, }, ], - highlightedDiffLines: [ + highlighted_diff_lines: [ { - lineCode: 'ABC_1_1', + line_code: 'ABC_1_1', discussions: [], }, ], @@ -219,7 +217,7 @@ describe('DiffsStoreActions', () => { }; const singleDiscussion = { id: '1', - fileHash: 'ABC', + file_hash: 'ABC', line_code: 'ABC_1_1', }; @@ -238,9 +236,7 @@ describe('DiffsStoreActions', () => { }, ], [], - () => { - done(); - }, + done, ); }); }); diff --git a/spec/javascripts/diffs/store/getters_spec.js b/spec/javascripts/diffs/store/getters_spec.js index 9c3a38fd526..2449bb65d07 100644 --- a/spec/javascripts/diffs/store/getters_spec.js +++ b/spec/javascripts/diffs/store/getters_spec.js @@ -195,12 +195,12 @@ describe('Diffs Module Getters', () => { discussionMock.expanded = true; line.left = { - lineCode: 'ABC', + line_code: 'ABC', discussions: [discussionMock], }; line.right = { - lineCode: 'DEF', + line_code: 'DEF', discussions: [discussionMock1], }; }); @@ -259,7 +259,7 @@ describe('Diffs Module Getters', () => { describe('getDiffFileDiscussions', () => { it('returns an array with discussions when fileHash matches and the discussion belongs to a diff', () => { - discussionMock.diff_file.file_hash = diffFileMock.fileHash; + discussionMock.diff_file.file_hash = diffFileMock.file_hash; expect( getters.getDiffFileDiscussions(localState, {}, {}, { discussions: [discussionMock] })( @@ -279,10 +279,10 @@ describe('Diffs Module Getters', () => { describe('getDiffFileByHash', () => { it('returns file by hash', () => { const fileA = { - fileHash: '123', + file_hash: '123', }; const fileB = { - fileHash: '456', + file_hash: '456', }; localState.diffFiles = [fileA, fileB]; diff --git a/spec/javascripts/diffs/store/mutations_spec.js b/spec/javascripts/diffs/store/mutations_spec.js index 8821cde76f4..598d723c940 100644 --- a/spec/javascripts/diffs/store/mutations_spec.js +++ b/spec/javascripts/diffs/store/mutations_spec.js @@ -37,7 +37,7 @@ describe('DiffsStoreMutations', () => { mutations[types.SET_DIFF_DATA](state, diffMock); - const firstLine = state.diffFiles[0].parallelDiffLines[0]; + const firstLine = state.diffFiles[0].parallel_diff_lines[0]; expect(firstLine.right.text).toBeUndefined(); expect(state.diffFiles[0].renderIt).toEqual(true); @@ -98,19 +98,19 @@ describe('DiffsStoreMutations', () => { it('should call utils.addContextLines with proper params', () => { const options = { lineNumbers: { oldLineNumber: 1, newLineNumber: 2 }, - contextLines: [{ oldLine: 1, newLine: 1, lineCode: 'ff9200_1_1', discussions: [] }], + contextLines: [{ old_line: 1, new_line: 1, line_code: 'ff9200_1_1', discussions: [] }], fileHash: 'ff9200', params: { bottom: true, }, }; const diffFile = { - fileHash: options.fileHash, - highlightedDiffLines: [], - parallelDiffLines: [], + file_hash: options.fileHash, + highlighted_diff_lines: [], + parallel_diff_lines: [], }; const state = { diffFiles: [diffFile] }; - const lines = [{ oldLine: 1, newLine: 1 }]; + const lines = [{ old_line: 1, new_line: 1 }]; const findDiffFileSpy = spyOnDependency(mutations, 'findDiffFile').and.returnValue(diffFile); const removeMatchLineSpy = spyOnDependency(mutations, 'removeMatchLine'); @@ -133,8 +133,8 @@ describe('DiffsStoreMutations', () => { ); expect(addContextLinesSpy).toHaveBeenCalledWith({ - inlineLines: diffFile.highlightedDiffLines, - parallelLines: diffFile.parallelDiffLines, + inlineLines: diffFile.highlighted_diff_lines, + parallelLines: diffFile.parallel_diff_lines, contextLines: options.contextLines, bottom: options.params.bottom, lineNumbers: options.lineNumbers, @@ -144,54 +144,50 @@ describe('DiffsStoreMutations', () => { describe('ADD_COLLAPSED_DIFFS', () => { it('should update the state with the given data for the given file hash', () => { - const spy = spyOnDependency(mutations, 'convertObjectPropsToCamelCase').and.callThrough(); - const fileHash = 123; - const state = { diffFiles: [{}, { fileHash, existingField: 0 }] }; - const data = { diff_files: [{ file_hash: fileHash, extra_field: 1, existingField: 1 }] }; + const state = { diffFiles: [{}, { file_hash: fileHash, existing_field: 0 }] }; + const data = { diff_files: [{ file_hash: fileHash, extra_field: 1, existing_field: 1 }] }; mutations[types.ADD_COLLAPSED_DIFFS](state, { file: state.diffFiles[1], data }); - expect(spy).toHaveBeenCalledWith(data, { deep: true }); - - expect(state.diffFiles[1].fileHash).toEqual(fileHash); - expect(state.diffFiles[1].existingField).toEqual(1); - expect(state.diffFiles[1].extraField).toEqual(1); + expect(state.diffFiles[1].file_hash).toEqual(fileHash); + expect(state.diffFiles[1].existing_field).toEqual(1); + expect(state.diffFiles[1].extra_field).toEqual(1); }); }); describe('SET_LINE_DISCUSSIONS_FOR_FILE', () => { it('should add discussions to the given line', () => { const diffPosition = { - baseSha: 'ed13df29948c41ba367caa757ab3ec4892509910', - headSha: 'b921914f9a834ac47e6fd9420f78db0f83559130', - newLine: null, - newPath: '500-lines-4.txt', - oldLine: 5, - oldPath: '500-lines-4.txt', - startSha: 'ed13df29948c41ba367caa757ab3ec4892509910', + base_sha: 'ed13df29948c41ba367caa757ab3ec4892509910', + head_sha: 'b921914f9a834ac47e6fd9420f78db0f83559130', + new_line: null, + new_path: '500-lines-4.txt', + old_line: 5, + old_path: '500-lines-4.txt', + start_sha: 'ed13df29948c41ba367caa757ab3ec4892509910', }; const state = { latestDiff: true, diffFiles: [ { - fileHash: 'ABC', - parallelDiffLines: [ + file_hash: 'ABC', + parallel_diff_lines: [ { left: { - lineCode: 'ABC_1', + line_code: 'ABC_1', discussions: [], }, right: { - lineCode: 'ABC_1', + line_code: 'ABC_1', discussions: [], }, }, ], - highlightedDiffLines: [ + highlighted_diff_lines: [ { - lineCode: 'ABC_1', + line_code: 'ABC_1', discussions: [], }, ], @@ -206,7 +202,7 @@ describe('DiffsStoreMutations', () => { original_position: diffPosition, position: diffPosition, diff_file: { - file_hash: state.diffFiles[0].fileHash, + file_hash: state.diffFiles[0].file_hash, }, }; @@ -219,46 +215,46 @@ describe('DiffsStoreMutations', () => { diffPositionByLineCode, }); - expect(state.diffFiles[0].parallelDiffLines[0].left.discussions.length).toEqual(1); - expect(state.diffFiles[0].parallelDiffLines[0].left.discussions[0].id).toEqual(1); - expect(state.diffFiles[0].parallelDiffLines[0].right.discussions).toEqual([]); + expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions.length).toEqual(1); + expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions[0].id).toEqual(1); + expect(state.diffFiles[0].parallel_diff_lines[0].right.discussions).toEqual([]); - expect(state.diffFiles[0].highlightedDiffLines[0].discussions.length).toEqual(1); - expect(state.diffFiles[0].highlightedDiffLines[0].discussions[0].id).toEqual(1); + expect(state.diffFiles[0].highlighted_diff_lines[0].discussions.length).toEqual(1); + expect(state.diffFiles[0].highlighted_diff_lines[0].discussions[0].id).toEqual(1); }); it('should add legacy discussions to the given line', () => { const diffPosition = { - baseSha: 'ed13df29948c41ba367caa757ab3ec4892509910', - headSha: 'b921914f9a834ac47e6fd9420f78db0f83559130', - newLine: null, - newPath: '500-lines-4.txt', - oldLine: 5, - oldPath: '500-lines-4.txt', - startSha: 'ed13df29948c41ba367caa757ab3ec4892509910', - lineCode: 'ABC_1', + base_sha: 'ed13df29948c41ba367caa757ab3ec4892509910', + head_sha: 'b921914f9a834ac47e6fd9420f78db0f83559130', + new_line: null, + new_path: '500-lines-4.txt', + old_line: 5, + old_path: '500-lines-4.txt', + start_sha: 'ed13df29948c41ba367caa757ab3ec4892509910', + line_code: 'ABC_1', }; const state = { latestDiff: true, diffFiles: [ { - fileHash: 'ABC', - parallelDiffLines: [ + file_hash: 'ABC', + parallel_diff_lines: [ { left: { - lineCode: 'ABC_1', + line_code: 'ABC_1', discussions: [], }, right: { - lineCode: 'ABC_1', + line_code: 'ABC_1', discussions: [], }, }, ], - highlightedDiffLines: [ + highlighted_diff_lines: [ { - lineCode: 'ABC_1', + line_code: 'ABC_1', discussions: [], }, ], @@ -271,7 +267,7 @@ describe('DiffsStoreMutations', () => { diff_discussion: true, active: true, diff_file: { - file_hash: state.diffFiles[0].fileHash, + file_hash: state.diffFiles[0].file_hash, }, }; @@ -284,11 +280,11 @@ describe('DiffsStoreMutations', () => { diffPositionByLineCode, }); - expect(state.diffFiles[0].parallelDiffLines[0].left.discussions.length).toEqual(1); - expect(state.diffFiles[0].parallelDiffLines[0].left.discussions[0].id).toEqual(1); + expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions.length).toEqual(1); + expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions[0].id).toEqual(1); - expect(state.diffFiles[0].highlightedDiffLines[0].discussions.length).toEqual(1); - expect(state.diffFiles[0].highlightedDiffLines[0].discussions[0].id).toEqual(1); + expect(state.diffFiles[0].highlighted_diff_lines[0].discussions.length).toEqual(1); + expect(state.diffFiles[0].highlighted_diff_lines[0].discussions[0].id).toEqual(1); }); }); @@ -297,11 +293,11 @@ describe('DiffsStoreMutations', () => { const state = { diffFiles: [ { - fileHash: 'ABC', - parallelDiffLines: [ + file_hash: 'ABC', + parallel_diff_lines: [ { left: { - lineCode: 'ABC_1', + line_code: 'ABC_1', discussions: [ { id: 1, @@ -314,14 +310,14 @@ describe('DiffsStoreMutations', () => { ], }, right: { - lineCode: 'ABC_1', + line_code: 'ABC_1', discussions: [], }, }, ], - highlightedDiffLines: [ + highlighted_diff_lines: [ { - lineCode: 'ABC_1', + line_code: 'ABC_1', discussions: [ { id: 1, @@ -343,8 +339,8 @@ describe('DiffsStoreMutations', () => { lineCode: 'ABC_1', }); - expect(state.diffFiles[0].parallelDiffLines[0].left.discussions.length).toEqual(0); - expect(state.diffFiles[0].highlightedDiffLines[0].discussions.length).toEqual(0); + expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions.length).toEqual(0); + expect(state.diffFiles[0].highlighted_diff_lines[0].discussions.length).toEqual(0); }); }); diff --git a/spec/javascripts/diffs/store/utils_spec.js b/spec/javascripts/diffs/store/utils_spec.js index f49dee3696d..d4ef17c5ef8 100644 --- a/spec/javascripts/diffs/store/utils_spec.js +++ b/spec/javascripts/diffs/store/utils_spec.js @@ -18,7 +18,7 @@ const getDiffFileMock = () => Object.assign({}, diffFileMockData); describe('DiffsStoreUtils', () => { describe('findDiffFile', () => { - const files = [{ fileHash: 1, name: 'one' }]; + const files = [{ file_hash: 1, name: 'one' }]; it('should return correct file', () => { expect(utils.findDiffFile(files, 1).name).toEqual('one'); @@ -41,13 +41,13 @@ describe('DiffsStoreUtils', () => { describe('findIndexInInlineLines', () => { it('should return correct index for given line numbers', () => { - expectSet(utils.findIndexInInlineLines, getDiffFileMock().highlightedDiffLines); + expectSet(utils.findIndexInInlineLines, getDiffFileMock().highlighted_diff_lines); }); }); describe('findIndexInParallelLines', () => { it('should return correct index for given line numbers', () => { - expectSet(utils.findIndexInParallelLines, getDiffFileMock().parallelDiffLines, {}); + expectSet(utils.findIndexInParallelLines, getDiffFileMock().parallel_diff_lines, {}); }); }); }); @@ -56,33 +56,39 @@ describe('DiffsStoreUtils', () => { it('should remove match line properly by regarding the bottom parameter', () => { const diffFile = getDiffFileMock(); const lineNumbers = { oldLineNumber: 3, newLineNumber: 5 }; - const inlineIndex = utils.findIndexInInlineLines(diffFile.highlightedDiffLines, lineNumbers); - const parallelIndex = utils.findIndexInParallelLines(diffFile.parallelDiffLines, lineNumbers); - const atInlineIndex = diffFile.highlightedDiffLines[inlineIndex]; - const atParallelIndex = diffFile.parallelDiffLines[parallelIndex]; + const inlineIndex = utils.findIndexInInlineLines( + diffFile.highlighted_diff_lines, + lineNumbers, + ); + const parallelIndex = utils.findIndexInParallelLines( + diffFile.parallel_diff_lines, + lineNumbers, + ); + const atInlineIndex = diffFile.highlighted_diff_lines[inlineIndex]; + const atParallelIndex = diffFile.parallel_diff_lines[parallelIndex]; utils.removeMatchLine(diffFile, lineNumbers, false); - expect(diffFile.highlightedDiffLines[inlineIndex]).not.toEqual(atInlineIndex); - expect(diffFile.parallelDiffLines[parallelIndex]).not.toEqual(atParallelIndex); + expect(diffFile.highlighted_diff_lines[inlineIndex]).not.toEqual(atInlineIndex); + expect(diffFile.parallel_diff_lines[parallelIndex]).not.toEqual(atParallelIndex); utils.removeMatchLine(diffFile, lineNumbers, true); - expect(diffFile.highlightedDiffLines[inlineIndex + 1]).not.toEqual(atInlineIndex); - expect(diffFile.parallelDiffLines[parallelIndex + 1]).not.toEqual(atParallelIndex); + expect(diffFile.highlighted_diff_lines[inlineIndex + 1]).not.toEqual(atInlineIndex); + expect(diffFile.parallel_diff_lines[parallelIndex + 1]).not.toEqual(atParallelIndex); }); }); describe('addContextLines', () => { it('should add context lines properly with bottom parameter', () => { const diffFile = getDiffFileMock(); - const inlineLines = diffFile.highlightedDiffLines; - const parallelLines = diffFile.parallelDiffLines; + const inlineLines = diffFile.highlighted_diff_lines; + const parallelLines = diffFile.parallel_diff_lines; const lineNumbers = { oldLineNumber: 3, newLineNumber: 5 }; const contextLines = [{ lineNumber: 42 }]; const options = { inlineLines, parallelLines, contextLines, lineNumbers, bottom: true }; - const inlineIndex = utils.findIndexInInlineLines(diffFile.highlightedDiffLines, lineNumbers); - const parallelIndex = utils.findIndexInParallelLines(diffFile.parallelDiffLines, lineNumbers); + const inlineIndex = utils.findIndexInInlineLines(inlineLines, lineNumbers); + const parallelIndex = utils.findIndexInParallelLines(parallelLines, lineNumbers); const normalizedParallelLine = { left: options.contextLines[0], right: options.contextLines[0], @@ -112,30 +118,30 @@ describe('DiffsStoreUtils', () => { noteableType: MERGE_REQUEST_NOTEABLE_TYPE, diffFile, noteTargetLine: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', - metaData: null, - newLine: 3, - oldLine: 1, + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', + meta_data: null, + new_line: 3, + old_line: 1, }, diffViewType: PARALLEL_DIFF_VIEW_TYPE, linePosition: LINE_POSITION_LEFT, }; const position = JSON.stringify({ - base_sha: diffFile.diffRefs.baseSha, - start_sha: diffFile.diffRefs.startSha, - head_sha: diffFile.diffRefs.headSha, - old_path: diffFile.oldPath, - new_path: diffFile.newPath, + base_sha: diffFile.diff_refs.base_sha, + start_sha: diffFile.diff_refs.start_sha, + head_sha: diffFile.diff_refs.head_sha, + old_path: diffFile.old_path, + new_path: diffFile.new_path, position_type: TEXT_DIFF_POSITION_TYPE, - old_line: options.noteTargetLine.oldLine, - new_line: options.noteTargetLine.newLine, + old_line: options.noteTargetLine.old_line, + new_line: options.noteTargetLine.new_line, }); const postData = { view: options.diffViewType, line_type: options.linePosition === LINE_POSITION_RIGHT ? NEW_LINE_TYPE : OLD_LINE_TYPE, - merge_request_diff_head_sha: diffFile.diffRefs.headSha, + merge_request_diff_head_sha: diffFile.diff_refs.head_sha, in_reply_to_discussion_id: '', note_project_id: '', target_type: options.noteableType, @@ -146,7 +152,7 @@ describe('DiffsStoreUtils', () => { noteable_id: options.noteableData.id, commit_id: '', type: DIFF_NOTE_TYPE, - line_code: options.noteTargetLine.lineCode, + line_code: options.noteTargetLine.line_code, note: options.note, position, }, @@ -160,8 +166,8 @@ describe('DiffsStoreUtils', () => { it('should create legacy note form data', () => { const diffFile = getDiffFileMock(); - delete diffFile.diffRefs.startSha; - delete diffFile.diffRefs.headSha; + delete diffFile.diff_refs.start_sha; + delete diffFile.diff_refs.head_sha; noteableDataMock.targetType = MERGE_REQUEST_NOTEABLE_TYPE; @@ -171,24 +177,24 @@ describe('DiffsStoreUtils', () => { noteableType: MERGE_REQUEST_NOTEABLE_TYPE, diffFile, noteTargetLine: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', - metaData: null, - newLine: 3, - oldLine: 1, + line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', + meta_data: null, + new_line: 3, + old_line: 1, }, diffViewType: PARALLEL_DIFF_VIEW_TYPE, linePosition: LINE_POSITION_LEFT, }; const position = JSON.stringify({ - base_sha: diffFile.diffRefs.baseSha, + base_sha: diffFile.diff_refs.base_sha, start_sha: undefined, head_sha: undefined, - old_path: diffFile.oldPath, - new_path: diffFile.newPath, + old_path: diffFile.old_path, + new_path: diffFile.new_path, position_type: TEXT_DIFF_POSITION_TYPE, - old_line: options.noteTargetLine.oldLine, - new_line: options.noteTargetLine.newLine, + old_line: options.noteTargetLine.old_line, + new_line: options.noteTargetLine.new_line, }); const postData = { @@ -205,7 +211,7 @@ describe('DiffsStoreUtils', () => { noteable_id: options.noteableData.id, commit_id: '', type: LEGACY_DIFF_NOTE_TYPE, - line_code: options.noteTargetLine.lineCode, + line_code: options.noteTargetLine.line_code, note: options.note, position, }, @@ -225,61 +231,61 @@ describe('DiffsStoreUtils', () => { const lines = [{ type: null }, { type: MATCH_LINE_TYPE }]; const linesWithReferences = utils.addLineReferences(lines, lineNumbers, true); - expect(linesWithReferences[0].oldLine).toEqual(lineNumbers.oldLineNumber + 1); - expect(linesWithReferences[0].newLine).toEqual(lineNumbers.newLineNumber + 1); - expect(linesWithReferences[1].metaData.oldPos).toEqual(4); - expect(linesWithReferences[1].metaData.newPos).toEqual(5); + expect(linesWithReferences[0].old_line).toEqual(lineNumbers.oldLineNumber + 1); + expect(linesWithReferences[0].new_line).toEqual(lineNumbers.newLineNumber + 1); + expect(linesWithReferences[1].meta_data.old_pos).toEqual(4); + expect(linesWithReferences[1].meta_data.new_pos).toEqual(5); }); it('should add correct line references when bottom falsy', () => { const lines = [{ type: null }, { type: MATCH_LINE_TYPE }, { type: null }]; const linesWithReferences = utils.addLineReferences(lines, lineNumbers); - expect(linesWithReferences[0].oldLine).toEqual(0); - expect(linesWithReferences[0].newLine).toEqual(1); - expect(linesWithReferences[1].metaData.oldPos).toEqual(2); - expect(linesWithReferences[1].metaData.newPos).toEqual(3); + expect(linesWithReferences[0].old_line).toEqual(0); + expect(linesWithReferences[0].new_line).toEqual(1); + expect(linesWithReferences[1].meta_data.old_pos).toEqual(2); + expect(linesWithReferences[1].meta_data.new_pos).toEqual(3); }); }); describe('trimFirstCharOfLineContent', () => { it('trims the line when it starts with a space', () => { - expect(utils.trimFirstCharOfLineContent({ richText: ' diff' })).toEqual({ + expect(utils.trimFirstCharOfLineContent({ rich_text: ' diff' })).toEqual({ discussions: [], - richText: 'diff', + rich_text: 'diff', }); }); it('trims the line when it starts with a +', () => { - expect(utils.trimFirstCharOfLineContent({ richText: '+diff' })).toEqual({ + expect(utils.trimFirstCharOfLineContent({ rich_text: '+diff' })).toEqual({ discussions: [], - richText: 'diff', + rich_text: 'diff', }); }); it('trims the line when it starts with a -', () => { - expect(utils.trimFirstCharOfLineContent({ richText: '-diff' })).toEqual({ + expect(utils.trimFirstCharOfLineContent({ rich_text: '-diff' })).toEqual({ discussions: [], - richText: 'diff', + rich_text: 'diff', }); }); it('does not trims the line when it starts with a letter', () => { - expect(utils.trimFirstCharOfLineContent({ richText: 'diff' })).toEqual({ + expect(utils.trimFirstCharOfLineContent({ rich_text: 'diff' })).toEqual({ discussions: [], - richText: 'diff', + rich_text: 'diff', }); }); it('does not modify the provided object', () => { const lineObj = { discussions: [], - richText: ' diff', + rich_text: ' diff', }; utils.trimFirstCharOfLineContent(lineObj); - expect(lineObj).toEqual({ discussions: [], richText: ' diff' }); + expect(lineObj).toEqual({ discussions: [], rich_text: ' diff' }); }); it('handles a undefined or null parameter', () => { @@ -289,33 +295,33 @@ describe('DiffsStoreUtils', () => { describe('prepareDiffData', () => { it('sets the renderIt and collapsed attribute on files', () => { - const preparedDiff = { diffFiles: [getDiffFileMock()] }; + const preparedDiff = { diff_files: [getDiffFileMock()] }; utils.prepareDiffData(preparedDiff); - const firstParallelDiffLine = preparedDiff.diffFiles[0].parallelDiffLines[2]; + const firstParallelDiffLine = preparedDiff.diff_files[0].parallel_diff_lines[2]; expect(firstParallelDiffLine.left.discussions.length).toBe(0); expect(firstParallelDiffLine.left).not.toHaveAttr('text'); expect(firstParallelDiffLine.right.discussions.length).toBe(0); expect(firstParallelDiffLine.right).not.toHaveAttr('text'); - const firstParallelChar = firstParallelDiffLine.right.richText.charAt(0); + const firstParallelChar = firstParallelDiffLine.right.rich_text.charAt(0); expect(firstParallelChar).not.toBe(' '); expect(firstParallelChar).not.toBe('+'); expect(firstParallelChar).not.toBe('-'); - const checkLine = preparedDiff.diffFiles[0].highlightedDiffLines[0]; + const checkLine = preparedDiff.diff_files[0].highlighted_diff_lines[0]; expect(checkLine.discussions.length).toBe(0); expect(checkLine).not.toHaveAttr('text'); - const firstChar = checkLine.richText.charAt(0); + const firstChar = checkLine.rich_text.charAt(0); expect(firstChar).not.toBe(' '); expect(firstChar).not.toBe('+'); expect(firstChar).not.toBe('-'); - expect(preparedDiff.diffFiles[0].renderIt).toBeTruthy(); - expect(preparedDiff.diffFiles[0].collapsed).toBeFalsy(); + expect(preparedDiff.diff_files[0].renderIt).toBeTruthy(); + expect(preparedDiff.diff_files[0].collapsed).toBeFalsy(); }); }); @@ -398,7 +404,7 @@ describe('DiffsStoreUtils', () => { discussion, diffPosition: { ...diffPosition, - lineCode: 'ABC_1', + line_code: 'ABC_1', }, latestDiff: true, }), @@ -429,36 +435,36 @@ describe('DiffsStoreUtils', () => { beforeAll(() => { files = [ { - newPath: 'app/index.js', - deletedFile: false, - newFile: false, - removedLines: 10, - addedLines: 0, - fileHash: 'test', + new_path: 'app/index.js', + deleted_file: false, + new_file: false, + removed_lines: 10, + added_lines: 0, + file_hash: 'test', }, { - newPath: 'app/test/index.js', - deletedFile: false, - newFile: true, - removedLines: 0, - addedLines: 0, - fileHash: 'test', + new_path: 'app/test/index.js', + deleted_file: false, + new_file: true, + removed_lines: 0, + added_lines: 0, + file_hash: 'test', }, { - newPath: 'app/test/filepathneedstruncating.js', - deletedFile: false, - newFile: true, - removedLines: 0, - addedLines: 0, - fileHash: 'test', + new_path: 'app/test/filepathneedstruncating.js', + deleted_file: false, + new_file: true, + removed_lines: 0, + added_lines: 0, + file_hash: 'test', }, { - newPath: 'package.json', - deletedFile: true, - newFile: false, - removedLines: 0, - addedLines: 0, - fileHash: 'test', + new_path: 'package.json', + deleted_file: true, + new_file: false, + removed_lines: 0, + added_lines: 0, + file_hash: 'test', }, ]; }); diff --git a/spec/javascripts/notes/components/diff_with_note_spec.js b/spec/javascripts/notes/components/diff_with_note_spec.js index 0c16103714a..95461396f10 100644 --- a/spec/javascripts/notes/components/diff_with_note_spec.js +++ b/spec/javascripts/notes/components/diff_with_note_spec.js @@ -1,6 +1,5 @@ import Vue from 'vue'; import DiffWithNote from '~/notes/components/diff_with_note.vue'; -import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { createStore } from '~/mr_notes/stores'; import { mountComponentWithStore } from 'spec/helpers'; @@ -11,7 +10,7 @@ describe('diff_with_note', () => { let store; let vm; const diffDiscussionMock = getJSONFixture(discussionFixture)[0]; - const diffDiscussion = convertObjectPropsToCamelCase(diffDiscussionMock); + const diffDiscussion = diffDiscussionMock; const Component = Vue.extend(DiffWithNote); const props = { discussion: diffDiscussion, @@ -65,7 +64,7 @@ describe('diff_with_note', () => { describe('image diff', () => { beforeEach(() => { const imageDiffDiscussionMock = getJSONFixture(imageDiscussionFixture)[0]; - props.discussion = convertObjectPropsToCamelCase(imageDiffDiscussionMock); + props.discussion = imageDiffDiscussionMock; }); it('shows image diff', () => { |