Commit e0078aba authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'notes-consistent-key-object-case' into 'master'

Made diff & note data consistent

See merge request gitlab-org/gitlab-ce!22950
parents d645df82 234563ba
...@@ -94,7 +94,7 @@ export default { ...@@ -94,7 +94,7 @@ export default {
return __('Show latest version'); return __('Show latest version');
}, },
canCurrentUserFork() { canCurrentUserFork() {
return this.currentUser.canFork === true && this.currentUser.canCreateMergeRequest; return this.currentUser.can_fork === true && this.currentUser.can_create_merge_request;
}, },
showCompareVersions() { showCompareVersions() {
return this.mergeRequestDiffs && this.mergeRequestDiff; return this.mergeRequestDiffs && this.mergeRequestDiff;
......
...@@ -40,15 +40,17 @@ export default { ...@@ -40,15 +40,17 @@ export default {
}, },
computed: { computed: {
authorName() { authorName() {
return (this.commit.author && this.commit.author.name) || this.commit.authorName; return (this.commit.author && this.commit.author.name) || this.commit.author_name;
}, },
authorUrl() { authorUrl() {
return ( return (
(this.commit.author && this.commit.author.webUrl) || `mailto:${this.commit.authorEmail}` (this.commit.author && this.commit.author.web_url) || `mailto:${this.commit.author_email}`
); );
}, },
authorAvatar() { authorAvatar() {
return (this.commit.author && this.commit.author.avatarUrl) || this.commit.authorGravatarUrl; return (
(this.commit.author && this.commit.author.avatar_url) || this.commit.author_gravatar_url
);
}, },
}, },
}; };
...@@ -66,18 +68,18 @@ export default { ...@@ -66,18 +68,18 @@ export default {
<div class="commit-detail flex-list"> <div class="commit-detail flex-list">
<div class="commit-content qa-commit-content"> <div class="commit-content qa-commit-content">
<a <a
:href="commit.commitUrl" :href="commit.commit_url"
class="commit-row-message item-title" class="commit-row-message item-title"
v-html="commit.titleHtml" v-html="commit.title_html"
></a> ></a>
<span class="commit-row-message d-block d-sm-none"> <span class="commit-row-message d-block d-sm-none">
&middot; &middot;
{{ commit.shortId }} {{ commit.short_id }}
</span> </span>
<button <button
v-if="commit.descriptionHtml" v-if="commit.description_html"
class="text-expander js-toggle-button" class="text-expander js-toggle-button"
type="button" type="button"
:aria-label="__('Toggle commit description')" :aria-label="__('Toggle commit description')"
...@@ -95,29 +97,29 @@ export default { ...@@ -95,29 +97,29 @@ export default {
></a> ></a>
{{ s__('CommitWidget|authored') }} {{ s__('CommitWidget|authored') }}
<time-ago-tooltip <time-ago-tooltip
:time="commit.authoredDate" :time="commit.authored_date"
/> />
</div> </div>
<pre <pre
v-if="commit.descriptionHtml" v-if="commit.description_html"
class="commit-row-description js-toggle-content append-bottom-8" class="commit-row-description js-toggle-content append-bottom-8"
v-html="commit.descriptionHtml" v-html="commit.description_html"
></pre> ></pre>
</div> </div>
<div class="commit-actions flex-row d-none d-sm-flex"> <div class="commit-actions flex-row d-none d-sm-flex">
<div <div
v-if="commit.signatureHtml" v-if="commit.signature_html"
v-html="commit.signatureHtml" v-html="commit.signature_html"
></div> ></div>
<commit-pipeline-status <commit-pipeline-status
v-if="commit.pipelineStatusPath" v-if="commit.pipeline_status_path"
:endpoint="commit.pipelineStatusPath" :endpoint="commit.pipeline_status_path"
/> />
<div class="commit-sha-group"> <div class="commit-sha-group">
<div <div
class="label label-monospace" class="label label-monospace"
v-text="commit.shortId" v-text="commit.short_id"
></div> ></div>
<clipboard-button <clipboard-button
:text="commit.id" :text="commit.id"
......
...@@ -56,16 +56,16 @@ export default { ...@@ -56,16 +56,16 @@ export default {
methods: { methods: {
commitsText(version) { commitsText(version) {
return n__( return n__(
`${version.commitsCount} commit,`, `${version.commits_count} commit,`,
`${version.commitsCount} commits,`, `${version.commits_count} commits,`,
version.commitsCount, version.commits_count,
); );
}, },
href(version) { href(version) {
if (this.showCommitCount) { if (this.showCommitCount) {
return version.versionPath; return version.version_path;
} }
return version.comparePath; return version.compare_path;
}, },
versionName(version) { versionName(version) {
if (this.isLatest(version)) { if (this.isLatest(version)) {
...@@ -74,7 +74,7 @@ export default { ...@@ -74,7 +74,7 @@ export default {
if (this.targetBranch && (this.isBase(version) || !version)) { if (this.targetBranch && (this.isBase(version) || !version)) {
return this.targetBranch.branchName; return this.targetBranch.branchName;
} }
return `version ${version.versionIndex}`; return `version ${version.version_index}`;
}, },
isActive(version) { isActive(version) {
if (!version) { if (!version) {
...@@ -84,11 +84,11 @@ export default { ...@@ -84,11 +84,11 @@ export default {
if (this.targetBranch) { if (this.targetBranch) {
return ( return (
(this.isBase(version) && !this.startVersion) || (this.isBase(version) && !this.startVersion) ||
(this.startVersion && this.startVersion.versionIndex === version.versionIndex) (this.startVersion && this.startVersion.version_index === version.version_index)
); );
} }
return version.versionIndex === this.mergeRequestVersion.versionIndex; return version.version_index === this.mergeRequestVersion.version_index;
}, },
isBase(version) { isBase(version) {
if (!version || !this.targetBranch) { if (!version || !this.targetBranch) {
...@@ -98,7 +98,7 @@ export default { ...@@ -98,7 +98,7 @@ export default {
}, },
isLatest(version) { isLatest(version) {
return ( return (
this.mergeRequestVersion && version.versionIndex === this.targetVersions[0].versionIndex this.mergeRequestVersion && version.version_index === this.targetVersions[0].version_index
); );
}, },
}, },
...@@ -142,7 +142,7 @@ export default { ...@@ -142,7 +142,7 @@ export default {
</div> </div>
<div> <div>
<small class="commit-sha"> <small class="commit-sha">
{{ version.truncatedCommitSha }} {{ version.truncated_commit_sha }}
</small> </small>
</div> </div>
<div> <div>
...@@ -151,8 +151,8 @@ export default { ...@@ -151,8 +151,8 @@ export default {
{{ commitsText(version) }} {{ commitsText(version) }}
</template> </template>
<time-ago <time-ago
v-if="version.createdAt" v-if="version.created_at"
:time="version.createdAt" :time="version.created_at"
class="js-timeago js-timeago-render" class="js-timeago js-timeago-render"
/> />
</small> </small>
......
...@@ -39,7 +39,7 @@ export default { ...@@ -39,7 +39,7 @@ export default {
return this.diffFile.viewer.name === 'text'; return this.diffFile.viewer.name === 'text';
}, },
diffFileCommentForm() { diffFileCommentForm() {
return this.getCommentFormForDiffFile(this.diffFile.fileHash); return this.getCommentFormForDiffFile(this.diffFile.file_hash);
}, },
showNotesContainer() { showNotesContainer() {
return this.diffFile.discussions.length || this.diffFileCommentForm; return this.diffFile.discussions.length || this.diffFileCommentForm;
...@@ -73,28 +73,28 @@ export default { ...@@ -73,28 +73,28 @@ export default {
<inline-diff-view <inline-diff-view
v-if="isInlineView" v-if="isInlineView"
:diff-file="diffFile" :diff-file="diffFile"
:diff-lines="diffFile.highlightedDiffLines || []" :diff-lines="diffFile.highlighted_diff_lines || []"
/> />
<parallel-diff-view <parallel-diff-view
v-if="isParallelView" v-if="isParallelView"
:diff-file="diffFile" :diff-file="diffFile"
:diff-lines="diffFile.parallelDiffLines || []" :diff-lines="diffFile.parallel_diff_lines || []"
/> />
</template> </template>
<diff-viewer <diff-viewer
v-else v-else
:diff-mode="diffMode" :diff-mode="diffMode"
:new-path="diffFile.newPath" :new-path="diffFile.new_path"
:new-sha="diffFile.diffRefs.headSha" :new-sha="diffFile.diff_refs.head_sha"
:old-path="diffFile.oldPath" :old-path="diffFile.old_path"
:old-sha="diffFile.diffRefs.baseSha" :old-sha="diffFile.diff_refs.base_sha"
:file-hash="diffFile.fileHash" :file-hash="diffFile.file_hash"
:project-path="projectPath" :project-path="projectPath"
> >
<image-diff-overlay <image-diff-overlay
slot="image-overlay" slot="image-overlay"
:discussions="diffFile.discussions" :discussions="diffFile.discussions"
:file-hash="diffFile.fileHash" :file-hash="diffFile.file_hash"
:can-comment="getNoteableData.current_user.can_create_note" :can-comment="getNoteableData.current_user.can_create_note"
/> />
<div <div
...@@ -115,7 +115,7 @@ export default { ...@@ -115,7 +115,7 @@ export default {
:save-button-title="__('Comment')" :save-button-title="__('Comment')"
class="diff-comment-form new-note discussion-form discussion-form-container" class="diff-comment-form new-note discussion-form discussion-form-container"
@handleFormUpdate="handleSaveNote" @handleFormUpdate="handleSaveNote"
@cancelForm="closeDiffFileCommentForm(diffFile.fileHash)" @cancelForm="closeDiffFileCommentForm(diffFile.file_hash)"
/> />
</div> </div>
</diff-viewer> </diff-viewer>
......
...@@ -40,7 +40,7 @@ export default { ...@@ -40,7 +40,7 @@ export default {
return sprintf( return sprintf(
__('You can %{linkStart}view the blob%{linkEnd} instead.'), __('You can %{linkStart}view the blob%{linkEnd} instead.'),
{ {
linkStart: `<a href="${_.escape(this.file.viewPath)}">`, linkStart: `<a href="${_.escape(this.file.view_path)}">`,
linkEnd: '</a>', linkEnd: '</a>',
}, },
false, false,
...@@ -49,9 +49,9 @@ export default { ...@@ -49,9 +49,9 @@ export default {
showExpandMessage() { showExpandMessage() {
return ( return (
this.isCollapsed || this.isCollapsed ||
(!this.file.highlightedDiffLines && (!this.file.highlighted_diff_lines &&
!this.isLoadingCollapsedDiff && !this.isLoadingCollapsedDiff &&
!this.file.tooLarge && !this.file.too_large &&
this.file.text) this.file.text)
); );
}, },
...@@ -59,9 +59,11 @@ export default { ...@@ -59,9 +59,11 @@ export default {
return this.isLoadingCollapsedDiff || (!this.file.renderIt && !this.isCollapsed); return this.isLoadingCollapsedDiff || (!this.file.renderIt && !this.isCollapsed);
}, },
hasDiffLines() { hasDiffLines() {
const { highlightedDiffLines, parallelDiffLines } = this.file; return (
this.file.highlighted_diff_lines &&
return highlightedDiffLines && parallelDiffLines && parallelDiffLines.length > 0; this.file.parallel_diff_lines &&
this.file.parallel_diff_lines.length > 0
);
}, },
}, },
watch: { watch: {
...@@ -115,9 +117,9 @@ export default { ...@@ -115,9 +117,9 @@ export default {
<template> <template>
<div <div
:id="file.fileHash" :id="file.file_hash"
:class="{ :class="{
'is-active': currentDiffFileId === file.fileHash 'is-active': currentDiffFileId === file.file_hash
}" }"
class="diff-file file-holder" class="diff-file file-holder"
> >
...@@ -141,7 +143,7 @@ export default { ...@@ -141,7 +143,7 @@ export default {
make your changes there, and submit a merge request. make your changes there, and submit a merge request.
</span> </span>
<a <a
:href="file.forkPath" :href="file.fork_path"
class="js-fork-suggestion-button btn btn-grouped btn-inverted btn-success" class="js-fork-suggestion-button btn btn-grouped btn-inverted btn-success"
> >
Fork Fork
...@@ -157,7 +159,7 @@ export default { ...@@ -157,7 +159,7 @@ export default {
<diff-content <diff-content
v-if="!isCollapsed && file.renderIt" v-if="!isCollapsed && file.renderIt"
:class="{ hidden: isCollapsed || file.tooLarge }" :class="{ hidden: isCollapsed || file.too_large }"
:diff-file="file" :diff-file="file"
/> />
<gl-loading-icon <gl-loading-icon
...@@ -178,7 +180,7 @@ export default { ...@@ -178,7 +180,7 @@ export default {
</a> </a>
</div> </div>
<div <div
v-if="file.tooLarge" v-if="file.too_large"
class="nothing-here-block diff-collapsed js-too-large-diff" class="nothing-here-block diff-collapsed js-too-large-diff"
> >
{{ __('This source diff could not be displayed because it is too large.') }} {{ __('This source diff could not be displayed because it is too large.') }}
......
...@@ -68,32 +68,32 @@ export default { ...@@ -68,32 +68,32 @@ export default {
}, },
titleLink() { titleLink() {
if (this.diffFile.submodule) { if (this.diffFile.submodule) {
return this.diffFile.submoduleTreeUrl || this.diffFile.submoduleLink; return this.diffFile.submodule_tree_url || this.diffFile.submodule_link;
} }
return this.discussionPath; return this.discussionPath;
}, },
filePath() { filePath() {
if (this.diffFile.submodule) { if (this.diffFile.submodule) {
return `${this.diffFile.filePath} @ ${truncateSha(this.diffFile.blob.id)}`; return `${this.diffFile.file_path} @ ${truncateSha(this.diffFile.blob.id)}`;
} }
if (this.diffFile.deletedFile) { if (this.diffFile.deleted_file) {
return sprintf(__('%{filePath} deleted'), { filePath: this.diffFile.filePath }, false); return sprintf(__('%{filePath} deleted'), { filePath: this.diffFile.file_path }, false);
} }
return this.diffFile.filePath; return this.diffFile.file_path;
}, },
titleTag() { titleTag() {
return this.diffFile.fileHash ? 'a' : 'span'; return this.diffFile.file_hash ? 'a' : 'span';
}, },
isUsingLfs() { isUsingLfs() {
return this.diffFile.storedExternally && this.diffFile.externalStorage === 'lfs'; return this.diffFile.stored_externally && this.diffFile.external_storage === 'lfs';
}, },
collapseIcon() { collapseIcon() {
return this.expanded ? 'chevron-down' : 'chevron-right'; return this.expanded ? 'chevron-down' : 'chevron-right';
}, },
viewFileButtonText() { viewFileButtonText() {
const truncatedContentSha = _.escape(truncateSha(this.diffFile.contentSha)); const truncatedContentSha = _.escape(truncateSha(this.diffFile.content_sha));
return sprintf( return sprintf(
s__('MergeRequests|View file @ %{commitId}'), s__('MergeRequests|View file @ %{commitId}'),
{ {
...@@ -103,7 +103,7 @@ export default { ...@@ -103,7 +103,7 @@ export default {
); );
}, },
viewReplacedFileButtonText() { viewReplacedFileButtonText() {
const truncatedBaseSha = _.escape(truncateSha(this.diffFile.diffRefs.baseSha)); const truncatedBaseSha = _.escape(truncateSha(this.diffFile.diff_refs.base_sha));
return sprintf( return sprintf(
s__('MergeRequests|View replaced file @ %{commitId}'), s__('MergeRequests|View replaced file @ %{commitId}'),
{ {
...@@ -113,7 +113,7 @@ export default { ...@@ -113,7 +113,7 @@ export default {
); );
}, },
gfmCopyText() { gfmCopyText() {
return `\`${this.diffFile.filePath}\``; return `\`${this.diffFile.file_path}\``;
}, },
}, },
methods: { methods: {
...@@ -164,21 +164,21 @@ export default { ...@@ -164,21 +164,21 @@ export default {
aria-hidden="true" aria-hidden="true"
css-classes="js-file-icon append-right-5" css-classes="js-file-icon append-right-5"
/> />
<span v-if="diffFile.renamedFile"> <span v-if="diffFile.renamed_file">
<strong <strong
v-tooltip v-tooltip
:title="diffFile.oldPath" :title="diffFile.old_path"
class="file-title-name" class="file-title-name"
data-container="body" data-container="body"
v-html="diffFile.oldPathHtml" v-html="diffFile.old_path_html"
></strong> ></strong>
<strong <strong
v-tooltip v-tooltip
:title="diffFile.newPath" :title="diffFile.new_path"
class="file-title-name" class="file-title-name"
data-container="body" data-container="body"
v-html="diffFile.newPathHtml" v-html="diffFile.new_path_html"
></strong> ></strong>
</span> </span>
...@@ -195,16 +195,16 @@ export default { ...@@ -195,16 +195,16 @@ export default {
<clipboard-button <clipboard-button
:title="__('Copy file path to clipboard')" :title="__('Copy file path to clipboard')"
:text="diffFile.filePath" :text="diffFile.file_path"
:gfm="gfmCopyText" :gfm="gfmCopyText"
css-class="btn-default btn-transparent btn-clipboard" css-class="btn-default btn-transparent btn-clipboard"
/> />
<small <small
v-if="diffFile.modeChanged" v-if="diffFile.mode_changed"
ref="fileMode" ref="fileMode"
> >
{{ diffFile.aMode }}{{ diffFile.bMode }} {{ diffFile.a_mode }}{{ diffFile.b_mode }}
</small> </small>
<span <span
...@@ -220,7 +220,7 @@ export default { ...@@ -220,7 +220,7 @@ export default {
class="file-actions d-none d-sm-block" class="file-actions d-none d-sm-block"
> >
<template <template
v-if="diffFile.blob && diffFile.blob.readableText" v-if="diffFile.blob && diffFile.blob.readable_text"
> >
<button <button
:disabled="!diffHasDiscussions(diffFile)" :disabled="!diffHasDiscussions(diffFile)"
...@@ -234,33 +234,33 @@ export default { ...@@ -234,33 +234,33 @@ export default {
</button> </button>
<edit-button <edit-button
v-if="!diffFile.deletedFile" v-if="!diffFile.deleted_file"
:can-current-user-fork="canCurrentUserFork" :can-current-user-fork="canCurrentUserFork"
:edit-path="diffFile.editPath" :edit-path="diffFile.edit_path"
:can-modify-blob="diffFile.canModifyBlob" :can-modify-blob="diffFile.can_modify_blob"
@showForkMessage="showForkMessage" @showForkMessage="showForkMessage"
/> />
</template> </template>
<a <a
v-if="diffFile.replacedViewPath" v-if="diffFile.replaced_view_path"
:href="diffFile.replacedViewPath" :href="diffFile.replaced_view_path"
class="btn view-file js-view-file" class="btn view-file js-view-file"
v-html="viewReplacedFileButtonText" v-html="viewReplacedFileButtonText"
> >
</a> </a>
<a <a
:href="diffFile.viewPath" :href="diffFile.view_path"
class="btn view-file js-view-file" class="btn view-file js-view-file"
v-html="viewFileButtonText" v-html="viewFileButtonText"
> >
</a> </a>
<a <a
v-if="diffFile.externalUrl" v-if="diffFile.external_url"
v-tooltip v-tooltip
:href="diffFile.externalUrl" :href="diffFile.external_url"
:title="`View on ${diffFile.formattedExternalUrl}`" :title="`View on ${diffFile.formatted_external_url}`"
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
class="btn btn-file-option" class="btn btn-file-option"
......
...@@ -73,7 +73,7 @@ export default { ...@@ -73,7 +73,7 @@ export default {
}), }),
...mapGetters(['isLoggedIn']), ...mapGetters(['isLoggedIn']),
lineHref() { lineHref() {
return `#${this.line.lineCode || ''}`; return `#${this.line.line_code || ''}`;
}, },
shouldShowCommentButton() { shouldShowCommentButton() {
return ( return (
...@@ -99,7 +99,7 @@ export default { ...@@ -99,7 +99,7 @@ export default {
methods: { methods: {
...mapActions('diffs', ['loadMoreLines', 'showCommentForm']), ...mapActions('diffs', ['loadMoreLines', 'showCommentForm']),
handleCommentButton() { handleCommentButton() {
this.showCommentForm({ lineCode: this.line.lineCode }); this.showCommentForm({ lineCode: this.line.line_code });
}, },
handleLoadMoreLines() { handleLoadMoreLines() {
if (this.isRequesting) { if (this.isRequesting) {
...@@ -108,8 +108,8 @@ export default { ...@@ -108,8 +108,8 @@ export default {
this.isRequesting = true; this.isRequesting = true;
const endpoint = this.contextLinesPath; const endpoint = this.contextLinesPath;
const oldLineNumber = this.line.metaData.oldPos || 0; const oldLineNumber = this.line.meta_data.old_pos || 0;
const newLineNumber = this.line.metaData.newPos || 0; const newLineNumber = this.line.meta_data.new_pos || 0;
const offset = newLineNumber - oldLineNumber; const offset = newLineNumber - oldLineNumber;
const bottom = this.isBottom; const bottom = this.isBottom;
const { fileHash } = this; const { fileHash } = this;
...@@ -125,12 +125,12 @@ export default { ...@@ -125,12 +125,12 @@ export default {
to = lineNumber + UNFOLD_COUNT; to = lineNumber + UNFOLD_COUNT;
} else { } else {
const diffFile = utils.findDiffFile(this.diffFiles, this.fileHash); const diffFile = utils.findDiffFile(this.diffFiles, this.fileHash);
const indexForInline = utils.findIndexInInlineLines(diffFile.highlightedDiffLines, { const indexForInline = utils.findIndexInInlineLines(diffFile.highlighted_diff_lines, {
oldLineNumber, oldLineNumber,
newLineNumber, newLineNumber,
}); });
const prevLine = diffFile.highlightedDiffLines[indexForInline - 2]; const prevLine = diffFile.highlighted_diff_lines[indexForInline - 2];
const prevLineNumber = (prevLine && prevLine.newLine) || 0; const prevLineNumber = (prevLine && prevLine.new_line) || 0;
if (since <= prevLineNumber + 1) { if (since <= prevLineNumber + 1) {
since = prevLineNumber + 1; since = prevLineNumber + 1;
......
...@@ -53,7 +53,7 @@ export default { ...@@ -53,7 +53,7 @@ export default {
this.noteableData.diff_head_sha, this.noteableData.diff_head_sha,
DIFF_NOTE_TYPE, DIFF_NOTE_TYPE,
this.noteableData.source_project_id, this.noteableData.source_project_id,
this.line.lineCode, this.line.line_code,
]; ];
this.initAutoSave(this.noteableData, keys); this.initAutoSave(this.noteableData, keys);
...@@ -72,7 +72,7 @@ export default { ...@@ -72,7 +72,7 @@ export default {
} }
this.cancelCommentForm({ this.cancelCommentForm({
lineCode: this.line.lineCode, lineCode: this.line.line_code,
}); });
this.$nextTick(() => { this.$nextTick(() => {
this.resetAutoSave(); this.resetAutoSave();
...@@ -94,7 +94,7 @@ export default { ...@@ -94,7 +94,7 @@ export default {
<note-form <note-form
ref="noteForm" ref="noteForm"
:is-editing="true" :is-editing="true"
:line-code="line.lineCode" :line-code="line.line_code"
save-button-title="Comment" save-button-title="Comment"
class="diff-comment-form" class="diff-comment-form"
@cancelForm="handleCancelCommentForm" @cancelForm="handleCancelCommentForm"
......
...@@ -96,9 +96,7 @@ export default { ...@@ -96,9 +96,7 @@ export default {
}; };
}, },
lineNumber() { lineNumber() {
const { lineType } = this; return this.lineType === OLD_LINE_TYPE ? this.line.old_line : this.line.new_line;
return lineType === OLD_LINE_TYPE ? this.line.oldLine : this.line.newLine;
}, },
}, },
}; };
......
...@@ -48,7 +48,7 @@ export default { ...@@ -48,7 +48,7 @@ export default {
:discussions="line.discussions" :discussions="line.discussions"
/> />
<diff-line-note-form <diff-line-note-form
v-if="diffLineCommentForms[line.lineCode]" v-if="diffLineCommentForms[line.line_code]"
:diff-file-hash="diffFileHash" :diff-file-hash="diffFileHash"
:line="line" :line="line"
:note-target-line="line" :note-target-line="line"
......
...@@ -52,9 +52,7 @@ export default { ...@@ -52,9 +52,7 @@ export default {
}; };
}, },
inlineRowId() { inlineRowId() {
const { lineCode, oldLine, newLine } = this.line; return this.line.line_code || `${this.fileHash}_${this.line.old_line}_${this.line.new_line}`;
return lineCode || `${this.fileHash}_${oldLine}_${newLine}`;
}, },
}, },
created() { created() {
...@@ -107,7 +105,7 @@ export default { ...@@ -107,7 +105,7 @@ export default {
<td <td
:class="line.type" :class="line.type"
class="line_content" class="line_content"
v-html="line.richText" v-html="line.rich_text"
> >
</td> </td>
</tr> </tr>
......
...@@ -43,16 +43,16 @@ export default { ...@@ -43,16 +43,16 @@ export default {
v-for="(line, index) in diffLines" v-for="(line, index) in diffLines"
> >
<inline-diff-table-row <inline-diff-table-row
:key="line.lineCode" :key="line.line_code"
:file-hash="diffFile.fileHash" :file-hash="diffFile.file_hash"
:context-lines-path="diffFile.contextLinesPath" :context-lines-path="diffFile.context_lines_path"
:line="line" :line="line"
:is-bottom="index + 1 === diffLinesLength" :is-bottom="index + 1 === diffLinesLength"
/> />
<inline-diff-comment-row <inline-diff-comment-row
v-if="shouldRenderInlineCommentRow(line)" v-if="shouldRenderInlineCommentRow(line)"
:key="index" :key="index"
:diff-file-hash="diffFile.fileHash" :diff-file-hash="diffFile.file_hash"
:line="line" :line="line"
:line-index="index" :line-index="index"
/> />
......
...@@ -27,10 +27,10 @@ export default { ...@@ -27,10 +27,10 @@ export default {
diffLineCommentForms: state => state.diffs.diffLineCommentForms, diffLineCommentForms: state => state.diffs.diffLineCommentForms,
}), }),
leftLineCode() { leftLineCode() {
return this.line.left && this.line.left.lineCode; return this.line.left && this.line.left.line_code;
}, },
rightLineCode() { rightLineCode() {
return this.line.right && this.line.right.lineCode; return this.line.right && this.line.right.line_code;
}, },
hasExpandedDiscussionOnLeft() { hasExpandedDiscussionOnLeft() {
return this.line.left && this.line.left.discussions return this.line.left && this.line.left.discussions
......
...@@ -120,11 +120,11 @@ export default { ...@@ -120,11 +120,11 @@ export default {
class="diff-line-num old_line" class="diff-line-num old_line"
/> />
<td <td
:id="line.left.lineCode" :id="line.left.line_code"
:class="parallelViewLeftLineType" :class="parallelViewLeftLineType"
class="line_content parallel left-side" class="line_content parallel left-side"
@mousedown.native="handleParallelLineMouseDown" @mousedown.native="handleParallelLineMouseDown"
v-html="line.left.richText" v-html="line.left.rich_text"
> >
</td> </td>
</template> </template>
...@@ -146,11 +146,11 @@ export default { ...@@ -146,11 +146,11 @@ export default {
class="diff-line-num new_line" class="diff-line-num new_line"
/> />
<td <td
:id="line.right.lineCode" :id="line.right.line_code"
:class="line.right.type" :class="line.right.type"
class="line_content parallel right-side" class="line_content parallel right-side"
@mousedown.native="handleParallelLineMouseDown" @mousedown.native="handleParallelLineMouseDown"
v-html="line.right.richText" v-html="line.right.rich_text"
> >
</td> </td>
</template> </template>
......
...@@ -46,8 +46,8 @@ export default { ...@@ -46,8 +46,8 @@ export default {
> >
<parallel-diff-table-row <parallel-diff-table-row
:key="index" :key="index"
:file-hash="diffFile.fileHash" :file-hash="diffFile.file_hash"
:context-lines-path="diffFile.contextLinesPath" :context-lines-path="diffFile.context_lines_path"
:line="line" :line="line"
:is-bottom="index + 1 === diffLinesLength" :is-bottom="index + 1 === diffLinesLength"
/> />
...@@ -55,7 +55,7 @@ export default { ...@@ -55,7 +55,7 @@ export default {
v-if="shouldRenderParallelCommentRow(line)" v-if="shouldRenderParallelCommentRow(line)"
:key="`dcr-${index}`" :key="`dcr-${index}`"
:line="line" :line="line"
:diff-file-hash="diffFile.fileHash" :diff-file-hash="diffFile.file_hash"
:line-index="index" :line-index="index"
/> />
</template> </template>
......
import Vue from 'vue'; import Vue from 'vue';
import { mapState } from 'vuex'; import { mapState } from 'vuex';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import diffsApp from './components/app.vue'; import diffsApp from './components/app.vue';
export default function initDiffsApp(store) { export default function initDiffsApp(store) {
...@@ -17,9 +16,7 @@ export default function initDiffsApp(store) { ...@@ -17,9 +16,7 @@ export default function initDiffsApp(store) {
return { return {
endpoint: dataset.endpoint, endpoint: dataset.endpoint,
projectPath: dataset.projectPath, projectPath: dataset.projectPath,
currentUser: convertObjectPropsToCamelCase(JSON.parse(dataset.currentUserData), { currentUser: JSON.parse(dataset.currentUserData) || {},
deep: true,
}),
}; };
}, },
computed: { computed: {
......
...@@ -50,8 +50,8 @@ export const assignDiscussionsToDiff = ( ...@@ -50,8 +50,8 @@ export const assignDiscussionsToDiff = (
}; };
export const removeDiscussionsFromDiff = ({ commit }, removeDiscussion) => { export const removeDiscussionsFromDiff = ({ commit }, removeDiscussion) => {
const { fileHash, line_code, id } = removeDiscussion; const { file_hash, line_code, id } = removeDiscussion;
commit(types.REMOVE_LINE_DISCUSSIONS_FOR_FILE, { fileHash, lineCode: line_code, id }); commit(types.REMOVE_LINE_DISCUSSIONS_FOR_FILE, { fileHash: file_hash, lineCode: line_code, id });
}; };
export const startRenderDiffsQueue = ({ state, commit }) => { export const startRenderDiffsQueue = ({ state, commit }) => {
...@@ -189,7 +189,7 @@ export const saveDiffDiscussion = ({ dispatch }, { note, formData }) => { ...@@ -189,7 +189,7 @@ export const saveDiffDiscussion = ({ dispatch }, { note, formData }) => {
return dispatch('saveNote', postData, { root: true }) return dispatch('saveNote', postData, { root: true })
.then(result => dispatch('updateDiscussion', result.discussion, { root: true })) .then(result => dispatch('updateDiscussion', result.discussion, { root: true }))
.then(discussion => dispatch('assignDiscussionsToDiff', [discussion])) .then(discussion => dispatch('assignDiscussionsToDiff', [discussion]))
.then(() => dispatch('closeDiffFileCommentForm', formData.diffFile.fileHash)) .then(() => dispatch('closeDiffFileCommentForm', formData.diffFile.file_hash))
.then(() => dispatch('startTaskList', null, { root: true })) .then(() => dispatch('startTaskList', null, { root: true }))
.catch(() => createFlash(s__('MergeRequests|Saving the comment failed'))); .catch(() => createFlash(s__('MergeRequests|Saving the comment failed')));
}; };
......
import _ from 'underscore';
import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '../constants'; import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '../constants';
export const isParallelView = state => state.diffViewType === PARALLEL_DIFF_VIEW_TYPE; export const isParallelView = state => state.diffViewType === PARALLEL_DIFF_VIEW_TYPE;
...@@ -68,8 +67,7 @@ export const diffHasDiscussions = (state, getters) => diff => ...@@ -68,8 +67,7 @@ export const diffHasDiscussions = (state, getters) => diff =>
*/ */
export const getDiffFileDiscussions = (state, getters, rootState, rootGetters) => diff => export const getDiffFileDiscussions = (state, getters, rootState, rootGetters) => diff =>
rootGetters.discussions.filter( rootGetters.discussions.filter(
discussion => discussion => discussion.diff_discussion && discussion.diff_file.file_hash === diff.file_hash,
discussion.diff_discussion && _.isEqual(discussion.diff_file.file_hash, diff.fileHash),
) || []; ) || [];
export const shouldRenderParallelCommentRow = state => line => { export const shouldRenderParallelCommentRow = state => line => {
...@@ -90,14 +88,14 @@ export const shouldRenderParallelCommentRow = state => line => { ...@@ -90,14 +88,14 @@ export const shouldRenderParallelCommentRow = state => line => {
return true; return true;
} }
const hasCommentFormOnLeft = line.left && state.diffLineCommentForms[line.left.lineCode]; const hasCommentFormOnLeft = line.left && state.diffLineCommentForms[line.left.line_code];
const hasCommentFormOnRight = line.right && state.diffLineCommentForms[line.right.lineCode]; const hasCommentFormOnRight = line.right && state.diffLineCommentForms[line.right.line_code];
return hasCommentFormOnLeft || hasCommentFormOnRight; return hasCommentFormOnLeft || hasCommentFormOnRight;
}; };
export const shouldRenderInlineCommentRow = state => line => { export const shouldRenderInlineCommentRow = state => line => {
if (state.diffLineCommentForms[line.lineCode]) return true; if (state.diffLineCommentForms[line.line_code]) return true;
if (!line.discussions || line.discussions.length === 0) { if (!line.discussions || line.discussions.length === 0) {
return false; return false;
...@@ -108,7 +106,7 @@ export const shouldRenderInlineCommentRow = state => line => { ...@@ -108,7 +106,7 @@ export const shouldRenderInlineCommentRow = state => line => {
// prevent babel-plugin-rewire from generating an invalid default during karma∂ tests // prevent babel-plugin-rewire from generating an invalid default during karma∂ tests
export const getDiffFileByHash = state => fileHash => export const getDiffFileByHash = state => fileHash =>
state.diffFiles.find(file => file.fileHash === fileHash); state.diffFiles.find(file => file.file_hash === fileHash);
export const allBlobs = state => Object.values(state.treeEntries).filter(f => f.type === 'blob'); export const allBlobs = state => Object.values(state.treeEntries).filter(f => f.type === 'blob');
......
...@@ -23,12 +23,11 @@ export default { ...@@ -23,12 +23,11 @@ export default {
}, },
[types.SET_DIFF_DATA](state, data) { [types.SET_DIFF_DATA](state, data) {
const diffData = convertObjectPropsToCamelCase(data, { deep: true }); prepareDiffData(data);
prepareDiffData(diffData); const { tree, treeEntries } = generateTreeList(data.diff_files);
const { tree, treeEntries } = generateTreeList(diffData.diffFiles);
Object.assign(state, { Object.assign(state, {
...diffData, ...convertObjectPropsToCamelCase(data),
tree: sortTree(tree), tree: sortTree(tree),
treeEntries, treeEntries,
}); });
...@@ -42,7 +41,7 @@ export default { ...@@ -42,7 +41,7 @@ export default {
[types.SET_MERGE_REQUEST_DIFFS](state, mergeRequestDiffs) { [types.SET_MERGE_REQUEST_DIFFS](state, mergeRequestDiffs) {
Object.assign(state, { Object.assign(state, {
mergeRequestDiffs: convertObjectPropsToCamelCase(mergeRequestDiffs, { deep: true }), mergeRequestDiffs,
}); });
}, },
...@@ -62,19 +61,18 @@ export default { ...@@ -62,19 +61,18 @@ export default {
const { lineNumbers, contextLines, fileHash } = options; const { lineNumbers, contextLines, fileHash } = options;
const { bottom } = options.params; const { bottom } = options.params;
const diffFile = findDiffFile(state.diffFiles, fileHash); const diffFile = findDiffFile(state.diffFiles, fileHash);
const { highlightedDiffLines, parallelDiffLines } = diffFile;
removeMatchLine(diffFile, lineNumbers, bottom); removeMatchLine(diffFile, lineNumbers, bottom);
const lines = addLineReferences(contextLines, lineNumbers, bottom).map(line => ({ const lines = addLineReferences(contextLines, lineNumbers, bottom).map(line => ({
...line, ...line,
lineCode: line.lineCode || `${fileHash}_${line.oldLine}_${line.newLine}`, line_code: line.line_code || `${fileHash}_${line.old_line}_${line.new_line}`,
discussions: line.discussions || [], discussions: line.discussions || [],
})); }));
addContextLines({ addContextLines({
inlineLines: highlightedDiffLines, inlineLines: diffFile.highlighted_diff_lines,
parallelLines: parallelDiffLines, parallelLines: diffFile.parallel_diff_lines,
contextLines: lines, contextLines: lines,
bottom, bottom,
lineNumbers, lineNumbers,
...@@ -82,10 +80,9 @@ export default { ...@@ -82,10 +80,9 @@ export default {
}, },
[types.ADD_COLLAPSED_DIFFS](state, { file, data }) { [types.ADD_COLLAPSED_DIFFS](state, { file, data }) {
const normalizedData = convertObjectPropsToCamelCase(data, { deep: true }); prepareDiffData(data);
prepareDiffData(normalizedData); const [newFileData] = data.diff_files.filter(f => f.file_hash === file.file_hash);
const [newFileData] = normalizedData.diffFiles.filter(f => f.fileHash === file.fileHash); const selectedFile = state.diffFiles.find(f => f.file_hash === file.file_hash);
const selectedFile = state.diffFiles.find(f => f.fileHash === file.fileHash);
Object.assign(selectedFile, { ...newFileData }); Object.assign(selectedFile, { ...newFileData });
}, },
...@@ -101,20 +98,20 @@ export default { ...@@ -101,20 +98,20 @@ export default {
const discussionLineCode = discussion.line_code; const discussionLineCode = discussion.line_code;
const fileHash = discussion.diff_file.file_hash; const fileHash = discussion.diff_file.file_hash;
const lineCheck = ({ lineCode }) => const lineCheck = line =>
lineCode === discussionLineCode && line.line_code === discussionLineCode &&
isDiscussionApplicableToLine({ isDiscussionApplicableToLine({
discussion, discussion,
diffPosition: diffPositionByLineCode[lineCode], diffPosition: diffPositionByLineCode[line.line_code],
latestDiff, latestDiff,
}); });
state.diffFiles = state.diffFiles.map(diffFile => { state.diffFiles = state.diffFiles.map(diffFile => {
if (diffFile.fileHash === fileHash) { if (diffFile.file_hash === fileHash) {
const file = { ...diffFile }; const file = { ...diffFile };
if (file.highlightedDiffLines) { if (file.highlighted_diff_lines) {
file.highlightedDiffLines = file.highlightedDiffLines.map(line => { file.highlighted_diff_lines = file.highlighted_diff_lines.map(line => {
if (lineCheck(line)) { if (lineCheck(line)) {
return { return {
...line, ...line,
...@@ -126,8 +123,8 @@ export default { ...@@ -126,8 +123,8 @@ export default {
}); });
} }
if (file.parallelDiffLines) { if (file.parallel_diff_lines) {
file.parallelDiffLines = file.parallelDiffLines.map(line => { file.parallel_diff_lines = file.parallel_diff_lines.map(line => {
const left = line.left && lineCheck(line.left); const left = line.left && lineCheck(line.left);
const right = line.right && lineCheck(line.right); const right = line.right && lineCheck(line.right);
...@@ -148,7 +145,7 @@ export default { ...@@ -148,7 +145,7 @@ export default {
}); });
} }
if (!file.parallelDiffLines || !file.highlightedDiffLines) { if (!file.parallel_diff_lines || !file.highlighted_diff_lines) {
file.discussions = file.discussions.concat(discussion); file.discussions = file.discussions.concat(discussion);
} }
...@@ -160,16 +157,16 @@ export default { ...@@ -160,16 +157,16 @@ export default {
}, },
[types.REMOVE_LINE_DISCUSSIONS_FOR_FILE](state, { fileHash, lineCode, id }) { [types.REMOVE_LINE_DISCUSSIONS_FOR_FILE](state, { fileHash, lineCode, id }) {
const selectedFile = state.diffFiles.find(f => f.fileHash === fileHash); const selectedFile = state.diffFiles.find(f => f.file_hash === fileHash);
if (selectedFile) { if (selectedFile) {
if (selectedFile.parallelDiffLines) { if (selectedFile.parallel_diff_lines) {
const targetLine = selectedFile.parallelDiffLines.find( const targetLine = selectedFile.parallel_diff_lines.find(
line => line =>
(line.left && line.left.lineCode === lineCode) || (line.left && line.left.line_code === lineCode) ||
(line.right && line.right.lineCode === lineCode), (line.right && line.right.line_code === lineCode),
); );
if (targetLine) { if (targetLine) {
const side = targetLine.left && targetLine.left.lineCode === lineCode ? 'left' : 'right'; const side = targetLine.left && targetLine.left.line_code === lineCode ? 'left' : 'right';
Object.assign(targetLine[side], { Object.assign(targetLine[side], {
discussions: [], discussions: [],
...@@ -177,9 +174,9 @@ export default { ...@@ -177,9 +174,9 @@ export default {
} }
} }
if (selectedFile.highlightedDiffLines) { if (selectedFile.highlighted_diff_lines) {
const targetInlineLine = selectedFile.highlightedDiffLines.find( const targetInlineLine = selectedFile.highlighted_diff_lines.find(
line => line.lineCode === lineCode, line => line.line_code === lineCode,
); );
if (targetInlineLine) { if (targetInlineLine) {
......
import _ from 'underscore'; import _ from 'underscore';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { diffModes } from '~/ide/constants'; import { diffModes } from '~/ide/constants';
import { import {
LINE_POSITION_LEFT, LINE_POSITION_LEFT,
...@@ -15,7 +14,7 @@ import { ...@@ -15,7 +14,7 @@ import {
} from '../constants'; } from '../constants';
export function findDiffFile(files, hash) { export function findDiffFile(files, hash) {
return files.filter(file => file.fileHash === hash)[0]; return files.filter(file => file.file_hash === hash)[0];
} }
export const getReversePosition = linePosition => { export const getReversePosition = linePosition => {
...@@ -39,14 +38,14 @@ export function getFormData(params) { ...@@ -39,14 +38,14 @@ export function getFormData(params) {
} = params; } = params;
const position = JSON.stringify({ const position = JSON.stringify({
base_sha: diffFile.diffRefs.baseSha, base_sha: diffFile.diff_refs.base_sha,
start_sha: diffFile.diffRefs.startSha, start_sha: diffFile.diff_refs.start_sha,
head_sha: diffFile.diffRefs.headSha, head_sha: diffFile.diff_refs.head_sha,
old_path: diffFile.oldPath, old_path: diffFile.old_path,
new_path: diffFile.newPath, new_path: diffFile.new_path,
position_type: positionType || TEXT_DIFF_POSITION_TYPE, position_type: positionType || TEXT_DIFF_POSITION_TYPE,
old_line: noteTargetLine ? noteTargetLine.oldLine : null, old_line: noteTargetLine ? noteTargetLine.old_line : null,
new_line: noteTargetLine ? noteTargetLine.newLine : null, new_line: noteTargetLine ? noteTargetLine.new_line : null,
x: params.x, x: params.x,
y: params.y, y: params.y,
width: params.width, width: params.width,
...@@ -56,7 +55,7 @@ export function getFormData(params) { ...@@ -56,7 +55,7 @@ export function getFormData(params) {
const postData = { const postData = {
view: diffViewType, view: diffViewType,
line_type: linePosition === LINE_POSITION_RIGHT ? NEW_LINE_TYPE : OLD_LINE_TYPE, line_type: 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: '', in_reply_to_discussion_id: '',
note_project_id: '', note_project_id: '',
target_type: noteableData.targetType, target_type: noteableData.targetType,
...@@ -69,10 +68,10 @@ export function getFormData(params) { ...@@ -69,10 +68,10 @@ export function getFormData(params) {
noteable_id: noteableData.id, noteable_id: noteableData.id,
commit_id: '', commit_id: '',
type: type:
diffFile.diffRefs.startSha && diffFile.diffRefs.headSha diffFile.diff_refs.start_sha && diffFile.diff_refs.head_sha
? DIFF_NOTE_TYPE ? DIFF_NOTE_TYPE
: LEGACY_DIFF_NOTE_TYPE, : LEGACY_DIFF_NOTE_TYPE,
line_code: noteTargetLine ? noteTargetLine.lineCode : null, line_code: noteTargetLine ? noteTargetLine.line_code : null,
}, },
}; };
...@@ -93,7 +92,7 @@ export const findIndexInInlineLines = (lines, lineNumbers) => { ...@@ -93,7 +92,7 @@ export const findIndexInInlineLines = (lines, lineNumbers) => {
return _.findIndex( return _.findIndex(
lines, lines,
line => line.oldLine === oldLineNumber && line.newLine === newLineNumber, line => line.old_line === oldLineNumber && line.new_line === newLineNumber,
); );
}; };
...@@ -105,18 +104,18 @@ export const findIndexInParallelLines = (lines, lineNumbers) => { ...@@ -105,18 +104,18 @@ export const findIndexInParallelLines = (lines, lineNumbers) => {
line => line =>
line.left && line.left &&
line.right && line.right &&
line.left.oldLine === oldLineNumber && line.left.old_line === oldLineNumber &&
line.right.newLine === newLineNumber, line.right.new_line === newLineNumber,
); );
}; };
export function removeMatchLine(diffFile, lineNumbers, bottom) { export function removeMatchLine(diffFile, lineNumbers, bottom) {
const indexForInline = findIndexInInlineLines(diffFile.highlightedDiffLines, lineNumbers); const indexForInline = findIndexInInlineLines(diffFile.highlighted_diff_lines, lineNumbers);
const indexForParallel = findIndexInParallelLines(diffFile.parallelDiffLines, lineNumbers); const indexForParallel = findIndexInParallelLines(diffFile.parallel_diff_lines, lineNumbers);
const factor = bottom ? 1 : -1; const factor = bottom ? 1 : -1;
diffFile.highlightedDiffLines.splice(indexForInline + factor, 1); diffFile.highlighted_diff_lines.splice(indexForInline + factor, 1);
diffFile.parallelDiffLines.splice(indexForParallel + factor, 1); diffFile.parallel_diff_lines.splice(indexForParallel + factor, 1);
} }
export function addLineReferences(lines, lineNumbers, bottom) { export function addLineReferences(lines, lineNumbers, bottom) {
...@@ -125,18 +124,16 @@ export function addLineReferences(lines, lineNumbers, bottom) { ...@@ -125,18 +124,16 @@ export function addLineReferences(lines, lineNumbers, bottom) {
let matchLineIndex = -1; let matchLineIndex = -1;
const linesWithNumbers = lines.map((l, index) => { const linesWithNumbers = lines.map((l, index) => {
const line = convertObjectPropsToCamelCase(l); if (l.type === MATCH_LINE_TYPE) {
if (line.type === MATCH_LINE_TYPE) {
matchLineIndex = index; matchLineIndex = index;
} else { } else {
Object.assign(line, { Object.assign(l, {
oldLine: bottom ? oldLineNumber + index + 1 : oldLineNumber + index - lineCount, old_line: bottom ? oldLineNumber + index + 1 : oldLineNumber + index - lineCount,
newLine: bottom ? newLineNumber + index + 1 : newLineNumber + index - lineCount, new_line: bottom ? newLineNumber + index + 1 : newLineNumber + index - lineCount,
}); });
} }
return line; return l;
}); });
if (matchLineIndex > -1) { if (matchLineIndex > -1) {
...@@ -146,9 +143,9 @@ export function addLineReferences(lines, lineNumbers, bottom) { ...@@ -146,9 +143,9 @@ export function addLineReferences(lines, lineNumbers, bottom) {
: linesWithNumbers[matchLineIndex + 1]; : linesWithNumbers[matchLineIndex + 1];
Object.assign(line, { Object.assign(line, {
metaData: { meta_data: {
oldPos: targetLine.oldLine, old_pos: targetLine.old_line,
newPos: targetLine.newLine, new_pos: targetLine.new_line,
}, },
}); });
} }
...@@ -187,11 +184,11 @@ export function trimFirstCharOfLineContent(line = {}) { ...@@ -187,11 +184,11 @@ export function trimFirstCharOfLineContent(line = {}) {
const parsedLine = Object.assign({}, line); const parsedLine = Object.assign({}, line);
if (line.richText) { if (line.rich_text) {
const firstChar = parsedLine.richText.charAt(0); const firstChar = parsedLine.rich_text.charAt(0);
if (firstChar === ' ' || firstChar === '+' || firstChar === '-') { if (firstChar === ' ' || firstChar === '+' || firstChar === '-') {
parsedLine.richText = line.richText.substring(1); parsedLine.rich_text = line.rich_text.substring(1);
} }
} }
...@@ -201,15 +198,15 @@ export function trimFirstCharOfLineContent(line = {}) { ...@@ -201,15 +198,15 @@ export function trimFirstCharOfLineContent(line = {}) {
// This prepares and optimizes the incoming diff data from the server // This prepares and optimizes the incoming diff data from the server
// by setting up incremental rendering and removing unneeded data // by setting up incremental rendering and removing unneeded data
export function prepareDiffData(diffData) { export function prepareDiffData(diffData) {
const filesLength = diffData.diffFiles.length; const filesLength = diffData.diff_files.length;
let showingLines = 0; let showingLines = 0;
for (let i = 0; i < filesLength; i += 1) { for (let i = 0; i < filesLength; i += 1) {
const file = diffData.diffFiles[i]; const file = diffData.diff_files[i];
if (file.parallelDiffLines) { if (file.parallel_diff_lines) {
const linesLength = file.parallelDiffLines.length; const linesLength = file.parallel_diff_lines.length;
for (let u = 0; u < linesLength; u += 1) { for (let u = 0; u < linesLength; u += 1) {
const line = file.parallelDiffLines[u]; const line = file.parallel_diff_lines[u];
if (line.left) { if (line.left) {
line.left = trimFirstCharOfLineContent(line.left); line.left = trimFirstCharOfLineContent(line.left);
} }
...@@ -219,13 +216,13 @@ export function prepareDiffData(diffData) { ...@@ -219,13 +216,13 @@ export function prepareDiffData(diffData) {
} }
} }
if (file.highlightedDiffLines) { if (file.highlighted_diff_lines) {
const linesLength = file.highlightedDiffLines.length; const linesLength = file.highlighted_diff_lines.length;
for (let u = 0; u < linesLength; u += 1) { for (let u = 0; u < linesLength; u += 1) {
const line = file.highlightedDiffLines[u]; const line = file.highlighted_diff_lines[u];
Object.assign(line, { ...trimFirstCharOfLineContent(line) }); Object.assign(line, { ...trimFirstCharOfLineContent(line) });
} }
showingLines += file.parallelDiffLines.length; showingLines += file.parallel_diff_lines.length;
} }
Object.assign(file, { Object.assign(file, {
...@@ -238,26 +235,21 @@ export function prepareDiffData(diffData) { ...@@ -238,26 +235,21 @@ export function prepareDiffData(diffData) {
export function getDiffPositionByLineCode(diffFiles) { export function getDiffPositionByLineCode(diffFiles) {
return diffFiles.reduce((acc, diffFile) => { return diffFiles.reduce((acc, diffFile) => {
const { baseSha, headSha, startSha } = diffFile.diffRefs;
const { newPath, oldPath } = diffFile;
// We can only use highlightedDiffLines to create the map of diff lines because // We can only use highlightedDiffLines to create the map of diff lines because
// highlightedDiffLines will also include every parallel diff line in it. // highlightedDiffLines will also include every parallel diff line in it.
if (diffFile.highlightedDiffLines) { if (diffFile.highlighted_diff_lines) {
diffFile.highlightedDiffLines.forEach(line => { diffFile.highlighted_diff_lines.forEach(line => {
const { lineCode, oldLine, newLine } = line; if (line.line_code) {
acc[line.line_code] = {
if (lineCode) { base_sha: diffFile.diff_refs.base_sha,
acc[lineCode] = { head_sha: diffFile.diff_refs.head_sha,
baseSha, start_sha: diffFile.diff_refs.start_sha,
headSha, new_path: diffFile.new_path,
startSha, old_path: diffFile.old_path,
newPath, old_line: line.old_line,
oldPath, new_line: line.new_line,
oldLine, line_code: line.line_code,
newLine, position_type: 'text',
lineCode,
positionType: 'text',
}; };
} }
}); });
...@@ -270,30 +262,30 @@ export function getDiffPositionByLineCode(diffFiles) { ...@@ -270,30 +262,30 @@ export function getDiffPositionByLineCode(diffFiles) {
// This method will check whether the discussion is still applicable // This method will check whether the discussion is still applicable
// to the diff line in question regarding different versions of the MR // to the diff line in question regarding different versions of the MR
export function isDiscussionApplicableToLine({ discussion, diffPosition, latestDiff }) { export function isDiscussionApplicableToLine({ discussion, diffPosition, latestDiff }) {
const { lineCode, ...diffPositionCopy } = diffPosition; const { line_code, ...diffPositionCopy } = diffPosition;
if (discussion.original_position && discussion.position) { if (discussion.original_position && discussion.position) {
const originalRefs = convertObjectPropsToCamelCase(discussion.original_position); const originalRefs = discussion.original_position;
const refs = convertObjectPropsToCamelCase(discussion.position); const refs = discussion.position;
return _.isEqual(refs, diffPositionCopy) || _.isEqual(originalRefs, diffPositionCopy); return _.isEqual(refs, diffPositionCopy) || _.isEqual(originalRefs, diffPositionCopy);
} }
return latestDiff && discussion.active && lineCode === discussion.line_code; // eslint-disable-next-line
return latestDiff && discussion.active && line_code === discussion.line_code;
} }
export const generateTreeList = files => export const generateTreeList = files =>
files.reduce( files.reduce(
(acc, file) => { (acc, file) => {
const { fileHash, addedLines, removedLines, newFile, deletedFile, newPath } = file; const split = file.new_path.split('/');
const split = newPath.split('/');
split.forEach((name, i) => { split.forEach((name, i) => {
const parent = acc.treeEntries[split.slice(0, i).join('/')]; const parent = acc.treeEntries[split.slice(0, i).join('/')];
const path = `${parent ? `${parent.path}/` : ''}${name}`; const path = `${parent ? `${parent.path}/` : ''}${name}`;
if (!acc.treeEntries[path]) { if (!acc.treeEntries[path]) {
const type = path === newPath ? 'blob' : 'tree'; const type = path === file.new_path ? 'blob' : 'tree';
acc.treeEntries[path] = { acc.treeEntries[path] = {
key: path, key: path,
path, path,
...@@ -307,11 +299,11 @@ export const generateTreeList = files => ...@@ -307,11 +299,11 @@ export const generateTreeList = files =>
if (type === 'blob') { if (type === 'blob') {
Object.assign(entry, { Object.assign(entry, {
changed: true, changed: true,
tempFile: newFile, tempFile: file.new_file,
deleted: deletedFile, deleted: file.deleted_file,
fileHash, fileHash: file.file_hash,
addedLines, addedLines: file.added_lines,
removedLines, removedLines: file.removed_lines,
}); });
} else { } else {
Object.assign(entry, { Object.assign(entry, {
...@@ -329,6 +321,6 @@ export const generateTreeList = files => ...@@ -329,6 +321,6 @@ export const generateTreeList = files =>
); );
export const getDiffMode = diffFile => { export const getDiffMode = diffFile => {
const diffModeKey = Object.keys(diffModes).find(key => diffFile[`${key}File`]); const diffModeKey = Object.keys(diffModes).find(key => diffFile[`${key}_file`]);
return diffModes[diffModeKey] || diffModes.replaced; return diffModes[diffModeKey] || diffModes.replaced;
}; };
<script> <script>
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import DiffFileHeader from '~/diffs/components/diff_file_header.vue'; import DiffFileHeader from '~/diffs/components/diff_file_header.vue';
import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue'; import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue';
import ImageDiffOverlay from '~/diffs/components/image_diff_overlay.vue'; import ImageDiffOverlay from '~/diffs/components/image_diff_overlay.vue';
...@@ -34,7 +33,9 @@ export default { ...@@ -34,7 +33,9 @@ export default {
return getDiffMode(this.diffFile); return getDiffMode(this.diffFile);
}, },
hasTruncatedDiffLines() { hasTruncatedDiffLines() {
return this.discussion.truncatedDiffLines && this.discussion.truncatedDiffLines.length !== 0; return (
this.discussion.truncated_diff_lines && this.discussion.truncated_diff_lines.length !== 0
);
}, },
isDiscussionsExpanded() { isDiscussionsExpanded() {
return true; // TODO: @fatihacet - Fix this. return true; // TODO: @fatihacet - Fix this.
...@@ -50,19 +51,17 @@ export default { ...@@ -50,19 +51,17 @@ export default {
return text ? 'text-file' : 'js-image-file'; return text ? 'text-file' : 'js-image-file';
}, },
diffFile() { diffFile() {
return convertObjectPropsToCamelCase(this.discussion.diffFile, { deep: true }); return this.discussion.diff_file;
}, },
imageDiffHtml() { imageDiffHtml() {
return this.discussion.imageDiffHtml; return this.discussion.image_diff_html;
}, },
userColorScheme() { userColorScheme() {
return window.gon.user_color_scheme; return window.gon.user_color_scheme;
}, },
normalizedDiffLines() { normalizedDiffLines() {
if (this.discussion.truncatedDiffLines) { if (this.discussion.truncated_diff_lines) {
return this.discussion.truncatedDiffLines.map(line => return this.discussion.truncated_diff_lines.map(line => trimFirstCharOfLineContent(line));
trimFirstCharOfLineContent(convertObjectPropsToCamelCase(line)),
);
} }
return []; return [];
...@@ -97,7 +96,7 @@ export default { ...@@ -97,7 +96,7 @@ export default {
class="diff-file file-holder" class="diff-file file-holder"
> >
<diff-file-header <diff-file-header
:discussion-path="discussion.discussionPath" :discussion-path="discussion.discussion_path"
:diff-file="diffFile" :diff-file="diffFile"
:can-current-user-fork="false" :can-current-user-fork="false"
:discussions-expanded="isDiscussionsExpanded" :discussions-expanded="isDiscussionsExpanded"
...@@ -111,15 +110,15 @@ export default { ...@@ -111,15 +110,15 @@ export default {
<table> <table>
<tr <tr
v-for="line in normalizedDiffLines" v-for="line in normalizedDiffLines"
:key="line.lineCode" :key="line.line_code"
class="line_holder" class="line_holder"
> >
<td class="diff-line-num old_line">{{ line.oldLine }}</td> <td class="diff-line-num old_line">{{ line.old_line }}</td>
<td class="diff-line-num new_line">{{ line.newLine }}</td> <td class="diff-line-num new_line">{{ line.new_line }}</td>
<td <td
:class="line.type" :class="line.type"
class="line_content" class="line_content"
v-html="line.richText" v-html="line.rich_text"
> >
</td> </td>
</tr> </tr>
...@@ -165,17 +164,17 @@ export default { ...@@ -165,17 +164,17 @@ export default {
> >
<diff-viewer <diff-viewer
:diff-mode="diffMode" :diff-mode="diffMode"
:new-path="diffFile.newPath" :new-path="diffFile.new_path"
:new-sha="diffFile.diffRefs.headSha" :new-sha="diffFile.diff_refs.head_sha"
:old-path="diffFile.oldPath" :old-path="diffFile.old_path"
:old-sha="diffFile.diffRefs.baseSha" :old-sha="diffFile.diff_refs.base_sha"
:file-hash="diffFile.fileHash" :file-hash="diffFile.file_hash"
:project-path="projectPath" :project-path="projectPath"
> >
<image-diff-overlay <image-diff-overlay
slot="image-overlay" slot="image-overlay"
:discussions="discussion" :discussions="discussion"
:file-hash="diffFile.fileHash" :file-hash="diffFile.file_hash"
:show-comment-icon="true" :show-comment-icon="true"
:should-toggle-discussion="false" :should-toggle-discussion="false"
badge-class="image-comment-badge" badge-class="image-comment-badge"
......
<script> <script>
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { truncateSha } from '~/lib/utils/text_utility'; import { truncateSha } from '~/lib/utils/text_utility';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import systemNote from '~/vue_shared/components/notes/system_note.vue'; import systemNote from '~/vue_shared/components/notes/system_note.vue';
...@@ -88,17 +87,16 @@ export default { ...@@ -88,17 +87,16 @@ export default {
transformedDiscussion() { transformedDiscussion() {
return { return {
...this.discussion.notes[0], ...this.discussion.notes[0],
truncatedDiffLines: this.discussion.truncated_diff_lines || [], truncated_diff_lines: this.discussion.truncated_diff_lines || [],
truncatedDiffLinesPath: this.discussion.truncated_diff_lines_path, truncated_diff_lines_path: this.discussion.truncated_diff_lines_path,
diffFile: this.discussion.diff_file, diff_file: this.discussion.diff_file,
diffDiscussion: this.discussion.diff_discussion, diff_discussion: this.discussion.diff_discussion,
imageDiffHtml: this.discussion.image_diff_html,
active: this.discussion.active, active: this.discussion.active,
discussionPath: this.discussion.discussion_path, discussion_path: this.discussion.discussion_path,
resolved: this.discussion.resolved, resolved: this.discussion.resolved,
resolvedBy: this.discussion.resolved_by, resolved_by: this.discussion.resolved_by,
resolvedByPush: this.discussion.resolved_by_push, resolved_by_push: this.discussion.resolved_by_push,
resolvedAt: this.discussion.resolved_at, resolved_at: this.discussion.resolved_at,
}; };
}, },
author() { author() {
...@@ -138,7 +136,7 @@ export default { ...@@ -138,7 +136,7 @@ export default {
return null; return null;
}, },
resolvedText() { resolvedText() {
return this.transformedDiscussion.resolvedByPush ? 'Automatically resolved' : 'Resolved'; return this.transformedDiscussion.resolved_by_push ? 'Automatically resolved' : 'Resolved';
}, },
hasMultipleUnresolvedDiscussions() { hasMultipleUnresolvedDiscussions() {
return this.unresolvedDiscussions.length > 1; return this.unresolvedDiscussions.length > 1;
...@@ -150,12 +148,14 @@ export default { ...@@ -150,12 +148,14 @@ export default {
); );
}, },
shouldRenderDiffs() { shouldRenderDiffs() {
const { diffDiscussion, diffFile } = this.transformedDiscussion; return (
this.transformedDiscussion.diff_discussion &&
return diffDiscussion && diffFile && this.renderDiffFile; this.transformedDiscussion.diff_file &&
this.renderDiffFile
);
}, },
shouldGroupReplies() { shouldGroupReplies() {
return !this.shouldRenderDiffs && !this.transformedDiscussion.diffDiscussion; return !this.shouldRenderDiffs && !this.transformedDiscussion.diff_discussion;
}, },
shouldRenderHeader() { shouldRenderHeader() {
return this.shouldRenderDiffs; return this.shouldRenderDiffs;
...@@ -165,7 +165,7 @@ export default { ...@@ -165,7 +165,7 @@ export default {
}, },
wrapperComponentProps() { wrapperComponentProps() {
if (this.shouldRenderDiffs) { if (this.shouldRenderDiffs) {
return { discussion: convertObjectPropsToCamelCase(this.discussion) }; return { discussion: this.discussion };
} }
return {}; return {};
...@@ -184,8 +184,8 @@ export default { ...@@ -184,8 +184,8 @@ export default {
}, },
shouldShowDiscussions() { shouldShowDiscussions() {
const isExpanded = this.discussion.expanded; const isExpanded = this.discussion.expanded;
const { diffDiscussion, resolved } = this.transformedDiscussion; const { resolved } = this.transformedDiscussion;
const isResolvedNonDiffDiscussion = !diffDiscussion && resolved; const isResolvedNonDiffDiscussion = !this.transformedDiscussion.diff_discussion && resolved;
return isExpanded || this.alwaysExpanded || isResolvedNonDiffDiscussion; return isExpanded || this.alwaysExpanded || isResolvedNonDiffDiscussion;
}, },
...@@ -333,9 +333,9 @@ Please check your network connection and try again.`; ...@@ -333,9 +333,9 @@ Please check your network connection and try again.`;
:expanded="discussion.expanded" :expanded="discussion.expanded"
@toggleHandler="toggleDiscussionHandler" @toggleHandler="toggleDiscussionHandler"
> >
<template v-if="transformedDiscussion.diffDiscussion"> <template v-if="transformedDiscussion.diff_discussion">
started a discussion on started a discussion on
<a :href="transformedDiscussion.discussionPath"> <a :href="transformedDiscussion.discussion_path">
<template v-if="transformedDiscussion.active"> <template v-if="transformedDiscussion.active">
the diff the diff
</template> </template>
...@@ -356,8 +356,8 @@ Please check your network connection and try again.`; ...@@ -356,8 +356,8 @@ Please check your network connection and try again.`;
</note-header> </note-header>
<note-edited-text <note-edited-text
v-if="transformedDiscussion.resolved" v-if="transformedDiscussion.resolved"
:edited-at="transformedDiscussion.resolvedAt" :edited-at="transformedDiscussion.resolved_at"
:edited-by="transformedDiscussion.resolvedBy" :edited-by="transformedDiscussion.resolved_by"
:action-text="resolvedText" :action-text="resolvedText"
class-name="discussion-headline-light js-discussion-headline" class-name="discussion-headline-light js-discussion-headline"
/> />
......
...@@ -341,7 +341,7 @@ export const scrollToNoteIfNeeded = (context, el) => { ...@@ -341,7 +341,7 @@ export const scrollToNoteIfNeeded = (context, el) => {
}; };
export const fetchDiscussionDiffLines = ({ commit }, discussion) => export const fetchDiscussionDiffLines = ({ commit }, discussion) =>
axios.get(discussion.truncatedDiffLinesPath).then(({ data }) => { axios.get(discussion.truncated_diff_lines_path).then(({ data }) => {
commit(types.SET_DISCUSSION_DIFF_LINES, { commit(types.SET_DISCUSSION_DIFF_LINES, {
discussionId: discussion.id, discussionId: discussion.id,
diffLines: data.truncated_diff_lines, diffLines: data.truncated_diff_lines,
......
...@@ -102,7 +102,7 @@ export default { ...@@ -102,7 +102,7 @@ export default {
discussionsData.forEach(discussion => { discussionsData.forEach(discussion => {
if (discussion.diff_file) { if (discussion.diff_file) {
Object.assign(discussion, { Object.assign(discussion, {
fileHash: discussion.diff_file.file_hash, file_hash: discussion.diff_file.file_hash,
truncated_diff_lines: discussion.truncated_diff_lines || [], truncated_diff_lines: discussion.truncated_diff_lines || [],
}); });
} }
...@@ -195,7 +195,7 @@ export default { ...@@ -195,7 +195,7 @@ export default {
const selectedDiscussion = state.discussions.find(disc => disc.id === note.id); const selectedDiscussion = state.discussions.find(disc => disc.id === note.id);
note.expanded = true; // override expand flag to prevent collapse note.expanded = true; // override expand flag to prevent collapse
if (note.diff_file) { if (note.diff_file) {
Object.assign(note, { fileHash: note.diff_file.file_hash }); Object.assign(note, { file_hash: note.diff_file.file_hash });
} }
Object.assign(selectedDiscussion, { ...note }); Object.assign(selectedDiscussion, { ...note });
}, },
......
...@@ -21,7 +21,7 @@ const getAvatarElement = vm => vm.$el.querySelector('.user-avatar-link'); ...@@ -21,7 +21,7 @@ const getAvatarElement = vm => vm.$el.querySelector('.user-avatar-link');
const getCommitterElement = vm => vm.$el.querySelector('.commiter'); const getCommitterElement = vm => vm.$el.querySelector('.commiter');
const getCommitActionsElement = vm => vm.$el.querySelector('.commit-actions'); const getCommitActionsElement = vm => vm.$el.querySelector('.commit-actions');
describe('diffs/components/commit_widget', () => { describe('diffs/components/commit_item', () => {
const Component = Vue.extend(CommitItem); const Component = Vue.extend(CommitItem);
const timeago = getTimeago(); const timeago = getTimeago();
const { commit } = getDiffWithCommit(); const { commit } = getDiffWithCommit();
...@@ -37,15 +37,15 @@ describe('diffs/components/commit_widget', () => { ...@@ -37,15 +37,15 @@ describe('diffs/components/commit_widget', () => {
it('renders commit title', () => { it('renders commit title', () => {
const titleElement = getTitleElement(vm); const titleElement = getTitleElement(vm);
expect(titleElement).toHaveAttr('href', commit.commitUrl); expect(titleElement).toHaveAttr('href', commit.commit_url);
expect(titleElement).toHaveText(commit.titleHtml); expect(titleElement).toHaveText(commit.title_html);
}); });
it('renders commit description', () => { it('renders commit description', () => {
const descElement = getDescElement(vm); const descElement = getDescElement(vm);
const descExpandElement = getDescExpandElement(vm); const descExpandElement = getDescExpandElement(vm);
const expected = commit.descriptionHtml.replace(/&#x000A;/g, ''); const expected = commit.description_html.replace(/&#x000A;/g, '');
expect(trimText(descElement.innerHTML)).toEqual(trimText(expected)); expect(trimText(descElement.innerHTML)).toEqual(trimText(expected));
expect(descExpandElement).not.toBeNull(); expect(descExpandElement).not.toBeNull();
...@@ -56,7 +56,7 @@ describe('diffs/components/commit_widget', () => { ...@@ -56,7 +56,7 @@ describe('diffs/components/commit_widget', () => {
const labelElement = shaElement.querySelector('.label'); const labelElement = shaElement.querySelector('.label');
const buttonElement = shaElement.querySelector('button'); 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); expect(buttonElement).toHaveData('clipboard-text', commit.id);
}); });
...@@ -64,27 +64,27 @@ describe('diffs/components/commit_widget', () => { ...@@ -64,27 +64,27 @@ describe('diffs/components/commit_widget', () => {
const avatarElement = getAvatarElement(vm); const avatarElement = getAvatarElement(vm);
const imgElement = avatarElement.querySelector('img'); 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).toHaveClass('s36');
expect(imgElement).toHaveAttr('alt', commit.author.name); 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', () => { it('renders committer text', () => {
const committerElement = getCommitterElement(vm); const committerElement = getCommitterElement(vm);
const nameElement = committerElement.querySelector('a'); 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}`; const expectedText = `${commit.author.name} authored ${expectTimeText}`;
expect(trimText(committerElement.textContent)).toEqual(expectedText); 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); expect(nameElement).toHaveText(commit.author.name);
}); });
describe('without commit description', () => { describe('without commit description', () => {
beforeEach(done => { beforeEach(done => {
vm.commit.descriptionHtml = ''; vm.commit.description_html = '';
vm.$nextTick() vm.$nextTick()
.then(done) .then(done)
...@@ -103,9 +103,9 @@ describe('diffs/components/commit_widget', () => { ...@@ -103,9 +103,9 @@ describe('diffs/components/commit_widget', () => {
describe('with no matching user', () => { describe('with no matching user', () => {
beforeEach(done => { beforeEach(done => {
vm.commit.author = null; vm.commit.author = null;
vm.commit.authorEmail = TEST_AUTHOR_EMAIL; vm.commit.author_email = TEST_AUTHOR_EMAIL;
vm.commit.authorName = TEST_AUTHOR_NAME; vm.commit.author_name = TEST_AUTHOR_NAME;
vm.commit.authorGravatarUrl = TEST_AUTHOR_GRAVATAR; vm.commit.author_gravatar_url = TEST_AUTHOR_GRAVATAR;
vm.$nextTick() vm.$nextTick()
.then(done) .then(done)
...@@ -132,7 +132,7 @@ describe('diffs/components/commit_widget', () => { ...@@ -132,7 +132,7 @@ describe('diffs/components/commit_widget', () => {
describe('with signature', () => { describe('with signature', () => {
beforeEach(done => { beforeEach(done => {
vm.commit.signatureHtml = TEST_SIGNATURE_HTML; vm.commit.signature_html = TEST_SIGNATURE_HTML;
vm.$nextTick() vm.$nextTick()
.then(done) .then(done)
...@@ -148,7 +148,7 @@ describe('diffs/components/commit_widget', () => { ...@@ -148,7 +148,7 @@ describe('diffs/components/commit_widget', () => {
describe('with pipeline status', () => { describe('with pipeline status', () => {
beforeEach(done => { beforeEach(done => {
vm.commit.pipelineStatusPath = TEST_PIPELINE_STATUS_PATH; vm.commit.pipeline_status_path = TEST_PIPELINE_STATUS_PATH;
vm.$nextTick() vm.$nextTick()
.then(done) .then(done)
......
...@@ -19,6 +19,6 @@ describe('diffs/components/commit_widget', () => { ...@@ -19,6 +19,6 @@ describe('diffs/components/commit_widget', () => {
const commitElement = vm.$el.querySelector('li.commit'); const commitElement = vm.$el.querySelector('li.commit');
expect(commitElement).not.toBeNull(); expect(commitElement).not.toBeNull();
expect(commitElement).toContainText(commit.shortId); expect(commitElement).toContainText(commit.short_id);
}); });
}); });
...@@ -56,14 +56,14 @@ describe('DiffContent', () => { ...@@ -56,14 +56,14 @@ describe('DiffContent', () => {
describe('image diff', () => { describe('image diff', () => {
beforeEach(done => { beforeEach(done => {
vm.diffFile.newPath = GREEN_BOX_IMAGE_URL; vm.diffFile.new_path = GREEN_BOX_IMAGE_URL;
vm.diffFile.newSha = 'DEF'; vm.diffFile.new_sha = 'DEF';
vm.diffFile.oldPath = RED_BOX_IMAGE_URL; vm.diffFile.old_path = RED_BOX_IMAGE_URL;
vm.diffFile.oldSha = 'ABC'; vm.diffFile.old_sha = 'ABC';
vm.diffFile.viewPath = ''; vm.diffFile.view_path = '';
vm.diffFile.discussions = [{ ...discussionsMockData }]; vm.diffFile.discussions = [{ ...discussionsMockData }];
vm.$store.state.diffs.commentForms.push({ vm.$store.state.diffs.commentForms.push({
fileHash: vm.diffFile.fileHash, fileHash: vm.diffFile.file_hash,
x: 10, x: 10,
y: 20, y: 20,
width: 100, width: 100,
...@@ -113,10 +113,10 @@ describe('DiffContent', () => { ...@@ -113,10 +113,10 @@ describe('DiffContent', () => {
describe('file diff', () => { describe('file diff', () => {
it('should have download buttons in place', done => { it('should have download buttons in place', done => {
const el = vm.$el; const el = vm.$el;
vm.diffFile.newPath = 'test.abc'; vm.diffFile.new_path = 'test.abc';
vm.diffFile.newSha = 'DEF'; vm.diffFile.new_sha = 'DEF';
vm.diffFile.oldPath = 'test.abc'; vm.diffFile.old_path = 'test.abc';
vm.diffFile.oldSha = 'ABC'; vm.diffFile.old_sha = 'ABC';
vm.$nextTick(() => { vm.$nextTick(() => {
expect(el.querySelectorAll('.js-diff-inline-view').length).toEqual(0); expect(el.querySelectorAll('.js-diff-inline-view').length).toEqual(0);
......
...@@ -3,7 +3,6 @@ import Vuex from 'vuex'; ...@@ -3,7 +3,6 @@ import Vuex from 'vuex';
import diffsModule from '~/diffs/store/modules'; import diffsModule from '~/diffs/store/modules';
import notesModule from '~/notes/stores/modules'; import notesModule from '~/notes/stores/modules';
import DiffFileHeader from '~/diffs/components/diff_file_header.vue'; 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'; import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
Vue.use(Vuex); Vue.use(Vuex);
...@@ -24,9 +23,9 @@ describe('diff_file_header', () => { ...@@ -24,9 +23,9 @@ describe('diff_file_header', () => {
}); });
beforeEach(() => { beforeEach(() => {
const diffFile = convertObjectPropsToCamelCase(diffDiscussionMock.diff_file, { deep: true }); const diffFile = diffDiscussionMock.diff_file;
props = { props = {
diffFile, diffFile: { ...diffFile },
canCurrentUserFork: false, canCurrentUserFork: false,
}; };
}); });
...@@ -62,8 +61,8 @@ describe('diff_file_header', () => { ...@@ -62,8 +61,8 @@ describe('diff_file_header', () => {
beforeEach(() => { beforeEach(() => {
props.discussionPath = 'link://to/discussion'; props.discussionPath = 'link://to/discussion';
Object.assign(props.diffFile, { Object.assign(props.diffFile, {
submoduleLink: 'link://to/submodule', submodule_link: 'link://to/submodule',
submoduleTreeUrl: 'some://tree/url', submodule_tree_url: 'some://tree/url',
}); });
}); });
...@@ -80,18 +79,18 @@ describe('diff_file_header', () => { ...@@ -80,18 +79,18 @@ describe('diff_file_header', () => {
vm = mountComponentWithStore(Component, { props, store }); 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', () => { it('returns the submoduleLink for submodules without submoduleTreeUrl', () => {
Object.assign(props.diffFile, { Object.assign(props.diffFile, {
submodule: true, submodule: true,
submoduleTreeUrl: null, submodule_tree_url: null,
}); });
vm = mountComponentWithStore(Component, { props, store }); 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', () => { it('sets the correct path to the discussion', () => {
...@@ -107,7 +106,7 @@ describe('diff_file_header', () => { ...@@ -107,7 +106,7 @@ describe('diff_file_header', () => {
beforeEach(() => { beforeEach(() => {
Object.assign(props.diffFile, { Object.assign(props.diffFile, {
blob: { id: 'b10b1db10b1d' }, blob: { id: 'b10b1db10b1d' },
filePath: 'path/to/file', file_path: 'path/to/file',
}); });
}); });
...@@ -116,7 +115,7 @@ describe('diff_file_header', () => { ...@@ -116,7 +115,7 @@ describe('diff_file_header', () => {
vm = mountComponentWithStore(Component, { props, store }); 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', () => { it('appends the truncated blob id for submodules', () => {
...@@ -125,14 +124,14 @@ describe('diff_file_header', () => { ...@@ -125,14 +124,14 @@ describe('diff_file_header', () => {
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
expect(vm.filePath).toBe( 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', () => { describe('titleTag', () => {
it('returns a link tag if fileHash is set', () => { 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 }); vm = mountComponentWithStore(Component, { props, store });
...@@ -140,7 +139,7 @@ describe('diff_file_header', () => { ...@@ -140,7 +139,7 @@ describe('diff_file_header', () => {
}); });
it('returns a span tag if fileHash is not set', () => { it('returns a span tag if fileHash is not set', () => {
props.diffFile.fileHash = null; props.diffFile.file_hash = null;
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
...@@ -151,8 +150,8 @@ describe('diff_file_header', () => { ...@@ -151,8 +150,8 @@ describe('diff_file_header', () => {
describe('isUsingLfs', () => { describe('isUsingLfs', () => {
beforeEach(() => { beforeEach(() => {
Object.assign(props.diffFile, { Object.assign(props.diffFile, {
storedExternally: true, stored_externally: true,
externalStorage: 'lfs', external_storage: 'lfs',
}); });
}); });
...@@ -163,7 +162,7 @@ describe('diff_file_header', () => { ...@@ -163,7 +162,7 @@ describe('diff_file_header', () => {
}); });
it('returns false if file is not stored externally', () => { it('returns false if file is not stored externally', () => {
props.diffFile.storedExternally = false; props.diffFile.stored_externally = false;
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
...@@ -171,7 +170,7 @@ describe('diff_file_header', () => { ...@@ -171,7 +170,7 @@ describe('diff_file_header', () => {
}); });
it('returns false if file is not stored in LFS', () => { 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 }); vm = mountComponentWithStore(Component, { props, store });
...@@ -200,7 +199,7 @@ describe('diff_file_header', () => { ...@@ -200,7 +199,7 @@ describe('diff_file_header', () => {
describe('viewFileButtonText', () => { describe('viewFileButtonText', () => {
it('contains the truncated content SHA', () => { it('contains the truncated content SHA', () => {
const dummySha = 'deebd00f is no SHA'; const dummySha = 'deebd00f is no SHA';
props.diffFile.contentSha = dummySha; props.diffFile.content_sha = dummySha;
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
...@@ -212,7 +211,7 @@ describe('diff_file_header', () => { ...@@ -212,7 +211,7 @@ describe('diff_file_header', () => {
describe('viewReplacedFileButtonText', () => { describe('viewReplacedFileButtonText', () => {
it('contains the truncated base SHA', () => { it('contains the truncated base SHA', () => {
const dummySha = 'deadabba sings no more'; const dummySha = 'deadabba sings no more';
props.diffFile.diffRefs.baseSha = dummySha; props.diffFile.diff_refs.base_sha = dummySha;
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
...@@ -281,32 +280,32 @@ describe('diff_file_header', () => { ...@@ -281,32 +280,32 @@ describe('diff_file_header', () => {
const filePaths = () => vm.$el.querySelectorAll('.file-title-name'); const filePaths = () => vm.$el.querySelectorAll('.file-title-name');
it('displays the path of a added file', () => { it('displays the path of a added file', () => {
props.diffFile.renamedFile = false; props.diffFile.renamed_file = false;
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
expect(filePaths()).toHaveLength(1); 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', () => { it('displays path for deleted file', () => {
props.diffFile.renamedFile = false; props.diffFile.renamed_file = false;
props.diffFile.deletedFile = true; props.diffFile.deleted_file = true;
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
expect(filePaths()).toHaveLength(1); 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', () => { 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 }); vm = mountComponentWithStore(Component, { props, store });
expect(filePaths()).toHaveLength(2); expect(filePaths()).toHaveLength(2);
expect(filePaths()[0]).toHaveText(props.diffFile.oldPath); expect(filePaths()[0]).toHaveText(props.diffFile.old_path);
expect(filePaths()[1]).toHaveText(props.diffFile.newPath); expect(filePaths()[1]).toHaveText(props.diffFile.new_path);
}); });
}); });
...@@ -323,19 +322,19 @@ describe('diff_file_header', () => { ...@@ -323,19 +322,19 @@ describe('diff_file_header', () => {
describe('file mode', () => { describe('file mode', () => {
it('it displays old and new file mode if it changed', () => { 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 }); vm = mountComponentWithStore(Component, { props, store });
const { fileMode } = vm.$refs; const { fileMode } = vm.$refs;
expect(fileMode).not.toBe(undefined); expect(fileMode).not.toBe(undefined);
expect(fileMode).toContainText(props.diffFile.aMode); expect(fileMode).toContainText(props.diffFile.a_mode);
expect(fileMode).toContainText(props.diffFile.bMode); expect(fileMode).toContainText(props.diffFile.b_mode);
}); });
it('does not display the file mode if it has not changed', () => { 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 }); vm = mountComponentWithStore(Component, { props, store });
...@@ -350,8 +349,8 @@ describe('diff_file_header', () => { ...@@ -350,8 +349,8 @@ describe('diff_file_header', () => {
it('displays the LFS label for files stored in LFS', () => { it('displays the LFS label for files stored in LFS', () => {
Object.assign(props.diffFile, { Object.assign(props.diffFile, {
storedExternally: true, stored_externally: true,
externalStorage: 'lfs', external_storage: 'lfs',
}); });
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
...@@ -361,7 +360,7 @@ describe('diff_file_header', () => { ...@@ -361,7 +360,7 @@ describe('diff_file_header', () => {
}); });
it('does not display the LFS label for files stored in repository', () => { 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 }); vm = mountComponentWithStore(Component, { props, store });
...@@ -378,7 +377,7 @@ describe('diff_file_header', () => { ...@@ -378,7 +377,7 @@ describe('diff_file_header', () => {
it('should show edit button when file is editable', () => { it('should show edit button when file is editable', () => {
props.addMergeRequestButtons = true; props.addMergeRequestButtons = true;
props.diffFile.editPath = '/'; props.diffFile.edit_path = '/';
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
expect(vm.$el.querySelector('.js-edit-blob')).toContainText('Edit'); expect(vm.$el.querySelector('.js-edit-blob')).toContainText('Edit');
...@@ -386,8 +385,8 @@ describe('diff_file_header', () => { ...@@ -386,8 +385,8 @@ describe('diff_file_header', () => {
it('should not show edit button when file is deleted', () => { it('should not show edit button when file is deleted', () => {
props.addMergeRequestButtons = true; props.addMergeRequestButtons = true;
props.diffFile.deletedFile = true; props.diffFile.deleted_file = true;
props.diffFile.editPath = '/'; props.diffFile.edit_path = '/';
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
expect(vm.$el.querySelector('.js-edit-blob')).toEqual(null); expect(vm.$el.querySelector('.js-edit-blob')).toEqual(null);
...@@ -397,7 +396,7 @@ describe('diff_file_header', () => { ...@@ -397,7 +396,7 @@ describe('diff_file_header', () => {
describe('addMergeRequestButtons', () => { describe('addMergeRequestButtons', () => {
beforeEach(() => { beforeEach(() => {
props.addMergeRequestButtons = true; props.addMergeRequestButtons = true;
props.diffFile.editPath = ''; props.diffFile.edit_path = '';
}); });
describe('view on environment button', () => { describe('view on environment button', () => {
...@@ -405,8 +404,8 @@ describe('diff_file_header', () => { ...@@ -405,8 +404,8 @@ describe('diff_file_header', () => {
const title = 'url.title'; const title = 'url.title';
it('displays link to external url', () => { it('displays link to external url', () => {
props.diffFile.externalUrl = url; props.diffFile.external_url = url;
props.diffFile.formattedExternalUrl = title; props.diffFile.formatted_external_url = title;
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
...@@ -415,8 +414,8 @@ describe('diff_file_header', () => { ...@@ -415,8 +414,8 @@ describe('diff_file_header', () => {
}); });
it('hides link if no external url', () => { it('hides link if no external url', () => {
props.diffFile.externalUrl = ''; props.diffFile.external_url = '';
props.diffFile.formattedExternalUrl = title; props.diffFile.formattedExternal_url = title;
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
...@@ -434,11 +433,11 @@ describe('diff_file_header', () => { ...@@ -434,11 +433,11 @@ describe('diff_file_header', () => {
path: 'lib/base.js', path: 'lib/base.js',
name: 'base.js', name: 'base.js',
mode: '100644', mode: '100644',
readableText: true, readable_text: true,
icon: 'file-text-o', icon: 'file-text-o',
}; };
propsCopy.addMergeRequestButtons = true; propsCopy.addMergeRequestButtons = true;
propsCopy.diffFile.deletedFile = true; propsCopy.diffFile.deleted_file = true;
vm = mountComponentWithStore(Component, { vm = mountComponentWithStore(Component, {
props: propsCopy, props: propsCopy,
...@@ -459,11 +458,11 @@ describe('diff_file_header', () => { ...@@ -459,11 +458,11 @@ describe('diff_file_header', () => {
path: 'lib/base.js', path: 'lib/base.js',
name: 'base.js', name: 'base.js',
mode: '100644', mode: '100644',
readableText: true, readable_text: true,
icon: 'file-text-o', icon: 'file-text-o',
}; };
propsCopy.addMergeRequestButtons = true; propsCopy.addMergeRequestButtons = true;
propsCopy.diffFile.deletedFile = true; propsCopy.diffFile.deleted_file = true;
const discussionGetter = () => [diffDiscussionMock]; const discussionGetter = () => [diffDiscussionMock];
const notesModuleMock = notesModule(); const notesModuleMock = notesModule();
......
...@@ -17,14 +17,14 @@ describe('DiffFile', () => { ...@@ -17,14 +17,14 @@ describe('DiffFile', () => {
describe('template', () => { describe('template', () => {
it('should render component with file header, file content components', () => { it('should render component with file header, file content components', () => {
const el = vm.$el; 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.classList.contains('diff-file')).toEqual(true);
expect(el.querySelectorAll('.diff-content.hidden').length).toEqual(0); expect(el.querySelectorAll('.diff-content.hidden').length).toEqual(0);
expect(el.querySelector('.js-file-title')).toBeDefined(); 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(el.querySelector('.js-syntax-highlight')).toBeDefined();
expect(vm.file.renderIt).toEqual(false); expect(vm.file.renderIt).toEqual(false);
...@@ -52,7 +52,7 @@ describe('DiffFile', () => { ...@@ -52,7 +52,7 @@ describe('DiffFile', () => {
it('should have collapsed text and link', done => { it('should have collapsed text and link', done => {
vm.file.renderIt = true; vm.file.renderIt = true;
vm.file.collapsed = false; vm.file.collapsed = false;
vm.file.highlightedDiffLines = null; vm.file.highlighted_diff_lines = null;
vm.$nextTick(() => { vm.$nextTick(() => {
expect(vm.$el.innerText).toContain('This diff is collapsed'); expect(vm.$el.innerText).toContain('This diff is collapsed');
...@@ -90,8 +90,8 @@ describe('DiffFile', () => { ...@@ -90,8 +90,8 @@ describe('DiffFile', () => {
describe('too large diff', () => { describe('too large diff', () => {
it('should have too large warning and blob link', done => { it('should have too large warning and blob link', done => {
const BLOB_LINK = '/file/view/path'; const BLOB_LINK = '/file/view/path';
vm.file.tooLarge = true; vm.file.too_large = true;
vm.file.viewPath = BLOB_LINK; vm.file.view_path = BLOB_LINK;
vm.$nextTick(() => { vm.$nextTick(() => {
expect(vm.$el.innerText).toContain( expect(vm.$el.innerText).toContain(
...@@ -112,8 +112,8 @@ describe('DiffFile', () => { ...@@ -112,8 +112,8 @@ describe('DiffFile', () => {
it('calls handleLoadCollapsedDiff if collapsed changed & file has no lines', done => { it('calls handleLoadCollapsedDiff if collapsed changed & file has no lines', done => {
spyOn(vm, 'handleLoadCollapsedDiff'); spyOn(vm, 'handleLoadCollapsedDiff');
vm.file.highlightedDiffLines = undefined; vm.file.highlighted_diff_lines = undefined;
vm.file.parallelDiffLines = []; vm.file.parallel_diff_lines = [];
vm.file.collapsed = true; vm.file.collapsed = true;
vm.$nextTick() vm.$nextTick()
......
...@@ -11,16 +11,16 @@ describe('DiffLineGutterContent', () => { ...@@ -11,16 +11,16 @@ describe('DiffLineGutterContent', () => {
const cmp = Vue.extend(DiffLineGutterContent); const cmp = Vue.extend(DiffLineGutterContent);
const props = Object.assign({}, options); const props = Object.assign({}, options);
props.line = { props.line = {
lineCode: 'LC_42', line_code: 'LC_42',
type: 'new', type: 'new',
oldLine: null, old_line: null,
newLine: 1, new_line: 1,
discussions: [], discussions: [{ ...discussionsMockData }],
text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n',
richText: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', rich_text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n',
metaData: null, meta_data: null,
}; };
props.fileHash = getDiffFileMock().fileHash; props.fileHash = getDiffFileMock().file_hash;
props.contextLinesPath = '/context/lines/path'; props.contextLinesPath = '/context/lines/path';
return createComponentWithStore(cmp, store, props).$mount(); return createComponentWithStore(cmp, store, props).$mount();
...@@ -37,7 +37,7 @@ describe('DiffLineGutterContent', () => { ...@@ -37,7 +37,7 @@ describe('DiffLineGutterContent', () => {
it('should return # if there is no lineCode', () => { it('should return # if there is no lineCode', () => {
const component = createComponent(); const component = createComponent();
component.line.lineCode = ''; component.line.line_code = '';
expect(component.lineHref).toEqual('#'); expect(component.lineHref).toEqual('#');
}); });
...@@ -46,6 +46,7 @@ describe('DiffLineGutterContent', () => { ...@@ -46,6 +46,7 @@ describe('DiffLineGutterContent', () => {
describe('discussions, hasDiscussions, shouldShowAvatarsOnGutter', () => { describe('discussions, hasDiscussions, shouldShowAvatarsOnGutter', () => {
it('should return empty array when there is no discussion', () => { it('should return empty array when there is no discussion', () => {
const component = createComponent(); const component = createComponent();
component.line.discussions = [];
expect(component.hasDiscussions).toEqual(false); expect(component.hasDiscussions).toEqual(false);
expect(component.shouldShowAvatarsOnGutter).toEqual(false); expect(component.shouldShowAvatarsOnGutter).toEqual(false);
...@@ -54,8 +55,8 @@ describe('DiffLineGutterContent', () => { ...@@ -54,8 +55,8 @@ describe('DiffLineGutterContent', () => {
it('should return discussions for the given lineCode', () => { it('should return discussions for the given lineCode', () => {
const cmp = Vue.extend(DiffLineGutterContent); const cmp = Vue.extend(DiffLineGutterContent);
const props = { const props = {
line: getDiffFileMock().highlightedDiffLines[1], line: getDiffFileMock().highlighted_diff_lines[1],
fileHash: getDiffFileMock().fileHash, fileHash: getDiffFileMock().file_hash,
showCommentButton: true, showCommentButton: true,
contextLinesPath: '/context/lines/path', contextLinesPath: '/context/lines/path',
}; };
...@@ -104,10 +105,10 @@ describe('DiffLineGutterContent', () => { ...@@ -104,10 +105,10 @@ describe('DiffLineGutterContent', () => {
it('should render user avatars', () => { it('should render user avatars', () => {
const component = createComponent({ const component = createComponent({
showCommentButton: true, 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);
}); });
}); });
}); });
...@@ -13,10 +13,10 @@ describe('DiffLineNoteForm', () => { ...@@ -13,10 +13,10 @@ describe('DiffLineNoteForm', () => {
beforeEach(() => { beforeEach(() => {
diffFile = getDiffFileMock(); diffFile = getDiffFileMock();
diffLines = diffFile.highlightedDiffLines; diffLines = diffFile.highlighted_diff_lines;
component = createComponentWithStore(Vue.extend(DiffLineNoteForm), store, { component = createComponentWithStore(Vue.extend(DiffLineNoteForm), store, {
diffFileHash: diffFile.fileHash, diffFileHash: diffFile.file_hash,
diffLines, diffLines,
line: diffLines[0], line: diffLines[0],
noteTargetLine: diffLines[0], noteTargetLine: diffLines[0],
...@@ -61,7 +61,7 @@ describe('DiffLineNoteForm', () => { ...@@ -61,7 +61,7 @@ describe('DiffLineNoteForm', () => {
expect(window.confirm).not.toHaveBeenCalled(); expect(window.confirm).not.toHaveBeenCalled();
component.$nextTick(() => { component.$nextTick(() => {
expect(component.cancelCommentForm).toHaveBeenCalledWith({ expect(component.cancelCommentForm).toHaveBeenCalledWith({
lineCode: diffLines[0].lineCode, lineCode: diffLines[0].line_code,
}); });
expect(component.resetAutoSave).toHaveBeenCalled(); expect(component.resetAutoSave).toHaveBeenCalled();
......
import Vue from 'vue'; import Vue from 'vue';
import '~/behaviors/markdown/render_gfm';
import InlineDiffView from '~/diffs/components/inline_diff_view.vue'; import InlineDiffView from '~/diffs/components/inline_diff_view.vue';
import store from '~/mr_notes/stores'; import store from '~/mr_notes/stores';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
...@@ -10,14 +11,16 @@ describe('InlineDiffView', () => { ...@@ -10,14 +11,16 @@ describe('InlineDiffView', () => {
const getDiffFileMock = () => Object.assign({}, diffFileMockData); const getDiffFileMock = () => Object.assign({}, diffFileMockData);
const getDiscussionsMockData = () => [Object.assign({}, discussionsMockData)]; const getDiscussionsMockData = () => [Object.assign({}, discussionsMockData)];
beforeEach(() => { beforeEach(done => {
const diffFile = getDiffFileMock(); const diffFile = getDiffFileMock();
store.dispatch('diffs/setInlineDiffViewType'); store.dispatch('diffs/setInlineDiffViewType');
component = createComponentWithStore(Vue.extend(InlineDiffView), store, { component = createComponentWithStore(Vue.extend(InlineDiffView), store, {
diffFile, diffFile,
diffLines: diffFile.highlightedDiffLines, diffLines: diffFile.highlighted_diff_lines,
}).$mount(); }).$mount();
Vue.nextTick(done);
}); });
describe('template', () => { describe('template', () => {
...@@ -32,7 +35,7 @@ describe('InlineDiffView', () => { ...@@ -32,7 +35,7 @@ describe('InlineDiffView', () => {
it('should render discussions', done => { it('should render discussions', done => {
const el = component.$el; const el = component.$el;
component.$store.dispatch('setInitialNotes', getDiscussionsMockData()); component.diffLines[1].discussions = getDiscussionsMockData();
Vue.nextTick(() => { Vue.nextTick(() => {
expect(el.querySelectorAll('.notes_holder').length).toEqual(1); expect(el.querySelectorAll('.notes_holder').length).toEqual(1);
......
...@@ -14,7 +14,7 @@ describe('ParallelDiffView', () => { ...@@ -14,7 +14,7 @@ describe('ParallelDiffView', () => {
component = createComponentWithStore(Vue.extend(ParallelDiffView), store, { component = createComponentWithStore(Vue.extend(ParallelDiffView), store, {
diffFile, diffFile,
diffLines: diffFile.parallelDiffLines, diffLines: diffFile.parallel_diff_lines,
}).$mount(); }).$mount();
}); });
......
export default { export default {
submodule: false, submodule: false,
submoduleLink: null, submodule_link: null,
blob: { blob: {
id: '9e10516ca50788acf18c518a231914a21e5f16f7', id: '9e10516ca50788acf18c518a231914a21e5f16f7',
path: 'CHANGELOG', path: 'CHANGELOG',
name: 'CHANGELOG', name: 'CHANGELOG',
mode: '100644', mode: '100644',
readableText: true, readable_text: true,
icon: 'file-text-o', icon: 'file-text-o',
}, },
blobPath: 'CHANGELOG', blob_path: 'CHANGELOG',
blobName: 'CHANGELOG', blob_name: 'CHANGELOG',
blobIcon: '<i aria-hidden="true" data-hidden="true" class="fa fa-file-text-o fa-fw"></i>', blob_icon: '<i aria-hidden="true" data-hidden="true" class="fa fa-file-text-o fa-fw"></i>',
fileHash: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a', file_hash: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a',
filePath: 'CHANGELOG', file_path: 'CHANGELOG',
newFile: false, new_file: false,
deletedFile: false, deleted_file: false,
renamedFile: false, renamed_file: false,
oldPath: 'CHANGELOG', old_path: 'CHANGELOG',
newPath: 'CHANGELOG', new_path: 'CHANGELOG',
modeChanged: false, mode_changed: false,
aMode: '100644', a_mode: '100644',
bMode: '100644', b_mode: '100644',
text: true, text: true,
viewer: { viewer: {
name: 'text', name: 'text',
}, },
addedLines: 2, added_lines: 2,
removedLines: 0, removed_lines: 0,
diffRefs: { diff_refs: {
baseSha: 'e63f41fe459e62e1228fcef60d7189127aeba95a', base_sha: 'e63f41fe459e62e1228fcef60d7189127aeba95a',
startSha: 'd9eaefe5a676b820c57ff18cf5b68316025f7962', start_sha: 'd9eaefe5a676b820c57ff18cf5b68316025f7962',
headSha: 'c48ee0d1bf3b30453f5b32250ce03134beaa6d13', head_sha: 'c48ee0d1bf3b30453f5b32250ce03134beaa6d13',
}, },
contentSha: 'c48ee0d1bf3b30453f5b32250ce03134beaa6d13', content_sha: 'c48ee0d1bf3b30453f5b32250ce03134beaa6d13',
storedExternally: null, stored_externally: null,
externalStorage: null, external_storage: null,
oldPathHtml: 'CHANGELOG', old_path_html: 'CHANGELOG',
newPathHtml: 'CHANGELOG', new_path_html: 'CHANGELOG',
editPath: '/gitlab-org/gitlab-test/edit/spooky-stuff/CHANGELOG', edit_path: '/gitlab-org/gitlab-test/edit/spooky-stuff/CHANGELOG',
viewPath: '/gitlab-org/gitlab-test/blob/spooky-stuff/CHANGELOG', view_path: '/gitlab-org/gitlab-test/blob/spooky-stuff/CHANGELOG',
replacedViewPath: null, replaced_view_path: null,
collapsed: false, collapsed: false,
renderIt: false, renderIt: false,
tooLarge: false, too_large: false,
contextLinesPath: context_lines_path:
'/gitlab-org/gitlab-test/blob/c48ee0d1bf3b30453f5b32250ce03134beaa6d13/CHANGELOG/diff', '/gitlab-org/gitlab-test/blob/c48ee0d1bf3b30453f5b32250ce03134beaa6d13/CHANGELOG/diff',
highlightedDiffLines: [ highlighted_diff_lines: [
{ {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1',
type: 'new', type: 'new',
oldLine: null, old_line: null,
newLine: 1, new_line: 1,
discussions: [], discussions: [],
text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n',
richText: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', rich_text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n',
metaData: null, meta_data: null,
}, },
{ {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2',
type: 'new', type: 'new',
oldLine: null, old_line: null,
newLine: 2, new_line: 2,
discussions: [], discussions: [],
text: '+<span id="LC2" class="line" lang="plaintext"></span>\n', text: '+<span id="LC2" class="line" lang="plaintext"></span>\n',
richText: '+<span id="LC2" class="line" lang="plaintext"></span>\n', rich_text: '+<span id="LC2" class="line" lang="plaintext"></span>\n',
metaData: null, meta_data: null,
}, },
{ {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3',
type: null, type: null,
oldLine: 1, old_line: 1,
newLine: 3, new_line: 3,
discussions: [], discussions: [],
text: ' <span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n', 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', rich_text: ' <span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n',
metaData: null, meta_data: null,
}, },
{ {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4',
type: null, type: null,
oldLine: 2, old_line: 2,
newLine: 4, new_line: 4,
discussions: [], discussions: [],
text: ' <span id="LC4" class="line" lang="plaintext"></span>\n', text: ' <span id="LC4" class="line" lang="plaintext"></span>\n',
richText: ' <span id="LC4" class="line" lang="plaintext"></span>\n', rich_text: ' <span id="LC4" class="line" lang="plaintext"></span>\n',
metaData: null, meta_data: null,
}, },
{ {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5',
type: null, type: null,
oldLine: 3, old_line: 3,
newLine: 5, new_line: 5,
discussions: [], discussions: [],
text: ' <span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n', 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', rich_text: ' <span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n',
metaData: null, meta_data: null,
}, },
{ {
lineCode: null, line_code: null,
type: 'match', type: 'match',
oldLine: null, old_line: null,
newLine: null, new_line: null,
discussions: [], discussions: [],
text: '', text: '',
richText: '', rich_text: '',
metaData: { meta_data: {
oldPos: 3, old_pos: 3,
newPos: 5, new_pos: 5,
}, },
}, },
], ],
parallelDiffLines: [ parallel_diff_lines: [
{ {
left: { left: {
type: 'empty-cell', type: 'empty-cell',
}, },
right: { right: {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1',
type: 'new', type: 'new',
oldLine: null, old_line: null,
newLine: 1, new_line: 1,
discussions: [], discussions: [],
text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n',
richText: '<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n', rich_text: '<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n',
metaData: null, meta_data: null,
}, },
}, },
{ {
...@@ -132,107 +132,107 @@ export default { ...@@ -132,107 +132,107 @@ export default {
type: 'empty-cell', type: 'empty-cell',
}, },
right: { right: {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2',
type: 'new', type: 'new',
oldLine: null, old_line: null,
newLine: 2, new_line: 2,
discussions: [], discussions: [],
text: '+<span id="LC2" class="line" lang="plaintext"></span>\n', text: '+<span id="LC2" class="line" lang="plaintext"></span>\n',
richText: '<span id="LC2" class="line" lang="plaintext"></span>\n', rich_text: '<span id="LC2" class="line" lang="plaintext"></span>\n',
metaData: null, meta_data: null,
}, },
}, },
{ {
left: { left: {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', line_Code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3',
type: null, type: null,
oldLine: 1, old_line: 1,
newLine: 3, new_line: 3,
discussions: [], discussions: [],
text: ' <span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n', 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', rich_text: '<span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n',
metaData: null, meta_data: null,
}, },
right: { right: {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3',
type: null, type: null,
oldLine: 1, old_line: 1,
newLine: 3, new_line: 3,
discussions: [], discussions: [],
text: ' <span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n', 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', rich_text: '<span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n',
metaData: null, meta_data: null,
}, },
}, },
{ {
left: { left: {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4',
type: null, type: null,
oldLine: 2, old_line: 2,
newLine: 4, new_line: 4,
discussions: [], discussions: [],
text: ' <span id="LC4" class="line" lang="plaintext"></span>\n', text: ' <span id="LC4" class="line" lang="plaintext"></span>\n',
richText: '<span id="LC4" class="line" lang="plaintext"></span>\n', rich_text: '<span id="LC4" class="line" lang="plaintext"></span>\n',
metaData: null, meta_data: null,
}, },
right: { right: {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4',
type: null, type: null,
oldLine: 2, old_line: 2,
newLine: 4, new_line: 4,
discussions: [], discussions: [],
text: ' <span id="LC4" class="line" lang="plaintext"></span>\n', text: ' <span id="LC4" class="line" lang="plaintext"></span>\n',
richText: '<span id="LC4" class="line" lang="plaintext"></span>\n', rich_text: '<span id="LC4" class="line" lang="plaintext"></span>\n',
metaData: null, meta_data: null,
}, },
}, },
{ {
left: { left: {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5',
type: null, type: null,
oldLine: 3, old_line: 3,
newLine: 5, new_line: 5,
discussions: [], discussions: [],
text: ' <span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n', 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', rich_text: '<span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n',
metaData: null, meta_data: null,
}, },
right: { right: {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5',
type: null, type: null,
oldLine: 3, old_line: 3,
newLine: 5, new_line: 5,
discussions: [], discussions: [],
text: ' <span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n', 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', rich_text: '<span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n',
metaData: null, meta_data: null,
}, },
}, },
{ {
left: { left: {
lineCode: null, line_code: null,
type: 'match', type: 'match',
oldLine: null, old_line: null,
newLine: null, new_line: null,
discussions: [], discussions: [],
text: '', text: '',
richText: '', rich_text: '',
metaData: { meta_data: {
oldPos: 3, old_pos: 3,
newPos: 5, new_pos: 5,
}, },
}, },
right: { right: {
lineCode: null, line_code: null,
type: 'match', type: 'match',
oldLine: null, old_line: null,
newLine: null, new_line: null,
discussions: [], discussions: [],
text: '', text: '',
richText: '', rich_text: '',
metaData: { meta_data: {
oldPos: 3, old_pos: 3,
newPos: 5, new_pos: 5,
}, },
}, },
}, },
......
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
const FIXTURE = 'merge_request_diffs/with_commit.json'; const FIXTURE = 'merge_request_diffs/with_commit.json';
preloadFixtures(FIXTURE); preloadFixtures(FIXTURE);
export default function getDiffWithCommit() { export default function getDiffWithCommit() {
return convertObjectPropsToCamelCase(getJSONFixture(FIXTURE), { deep: true }); return getJSONFixture(FIXTURE);
} }
...@@ -97,46 +97,46 @@ describe('DiffsStoreActions', () => { ...@@ -97,46 +97,46 @@ describe('DiffsStoreActions', () => {
const state = { const state = {
diffFiles: [ diffFiles: [
{ {
fileHash: 'ABC', file_hash: 'ABC',
parallelDiffLines: [ parallel_diff_lines: [
{ {
left: { left: {
lineCode: 'ABC_1_1', line_code: 'ABC_1_1',
discussions: [], discussions: [],
}, },
right: { right: {
lineCode: 'ABC_1_1', line_code: 'ABC_1_1',
discussions: [], discussions: [],
}, },
}, },
], ],
highlightedDiffLines: [ highlighted_diff_lines: [
{ {
lineCode: 'ABC_1_1', line_code: 'ABC_1_1',
discussions: [], discussions: [],
oldLine: 5, old_line: 5,
newLine: null, new_line: null,
}, },
], ],
diffRefs: { diff_refs: {
baseSha: 'abc', base_sha: 'abc',
headSha: 'def', head_sha: 'def',
startSha: 'ghi', start_sha: 'ghi',
}, },
newPath: 'file1', new_path: 'file1',
oldPath: 'file2', old_path: 'file2',
}, },
], ],
}; };
const diffPosition = { const diffPosition = {
baseSha: 'abc', base_sha: 'abc',
headSha: 'def', head_sha: 'def',
startSha: 'ghi', start_sha: 'ghi',
newLine: null, new_line: null,
newPath: 'file1', new_path: 'file1',
oldLine: 5, old_line: 5,
oldPath: 'file2', old_path: 'file2',
}; };
const singleDiscussion = { const singleDiscussion = {
...@@ -145,7 +145,7 @@ describe('DiffsStoreActions', () => { ...@@ -145,7 +145,7 @@ describe('DiffsStoreActions', () => {
diff_file: { diff_file: {
file_hash: 'ABC', file_hash: 'ABC',
}, },
fileHash: 'ABC', file_hash: 'ABC',
resolvable: true, resolvable: true,
position: diffPosition, position: diffPosition,
original_position: diffPosition, original_position: diffPosition,
...@@ -164,24 +164,22 @@ describe('DiffsStoreActions', () => { ...@@ -164,24 +164,22 @@ describe('DiffsStoreActions', () => {
discussion: singleDiscussion, discussion: singleDiscussion,
diffPositionByLineCode: { diffPositionByLineCode: {
ABC_1_1: { ABC_1_1: {
baseSha: 'abc', base_sha: 'abc',
headSha: 'def', head_sha: 'def',
startSha: 'ghi', start_sha: 'ghi',
newLine: null, new_line: null,
newPath: 'file1', new_path: 'file1',
oldLine: 5, old_line: 5,
oldPath: 'file2', old_path: 'file2',
lineCode: 'ABC_1_1', line_code: 'ABC_1_1',
positionType: 'text', position_type: 'text',
}, },
}, },
}, },
}, },
], ],
[], [],
() => { done,
done();
},
); );
}); });
}); });
...@@ -191,11 +189,11 @@ describe('DiffsStoreActions', () => { ...@@ -191,11 +189,11 @@ describe('DiffsStoreActions', () => {
const state = { const state = {
diffFiles: [ diffFiles: [
{ {
fileHash: 'ABC', file_hash: 'ABC',
parallelDiffLines: [ parallel_diff_lines: [
{ {
left: { left: {
lineCode: 'ABC_1_1', line_code: 'ABC_1_1',
discussions: [ discussions: [
{ {
id: 1, id: 1,
...@@ -203,14 +201,14 @@ describe('DiffsStoreActions', () => { ...@@ -203,14 +201,14 @@ describe('DiffsStoreActions', () => {
], ],
}, },
right: { right: {
lineCode: 'ABC_1_1', line_code: 'ABC_1_1',
discussions: [], discussions: [],
}, },
}, },
], ],
highlightedDiffLines: [ highlighted_diff_lines: [
{ {
lineCode: 'ABC_1_1', line_code: 'ABC_1_1',
discussions: [], discussions: [],
}, },
], ],
...@@ -219,7 +217,7 @@ describe('DiffsStoreActions', () => { ...@@ -219,7 +217,7 @@ describe('DiffsStoreActions', () => {
}; };
const singleDiscussion = { const singleDiscussion = {
id: '1', id: '1',
fileHash: 'ABC', file_hash: 'ABC',
line_code: 'ABC_1_1', line_code: 'ABC_1_1',
}; };
...@@ -238,9 +236,7 @@ describe('DiffsStoreActions', () => { ...@@ -238,9 +236,7 @@ describe('DiffsStoreActions', () => {
}, },
], ],
[], [],
() => { done,
done();
},
); );
}); });
}); });
......
...@@ -195,12 +195,12 @@ describe('Diffs Module Getters', () => { ...@@ -195,12 +195,12 @@ describe('Diffs Module Getters', () => {
discussionMock.expanded = true; discussionMock.expanded = true;
line.left = { line.left = {
lineCode: 'ABC', line_code: 'ABC',
discussions: [discussionMock], discussions: [discussionMock],
}; };
line.right = { line.right = {
lineCode: 'DEF', line_code: 'DEF',
discussions: [discussionMock1], discussions: [discussionMock1],
}; };
}); });
...@@ -259,7 +259,7 @@ describe('Diffs Module Getters', () => { ...@@ -259,7 +259,7 @@ describe('Diffs Module Getters', () => {
describe('getDiffFileDiscussions', () => { describe('getDiffFileDiscussions', () => {
it('returns an array with discussions when fileHash matches and the discussion belongs to a diff', () => { 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( expect(
getters.getDiffFileDiscussions(localState, {}, {}, { discussions: [discussionMock] })( getters.getDiffFileDiscussions(localState, {}, {}, { discussions: [discussionMock] })(
...@@ -279,10 +279,10 @@ describe('Diffs Module Getters', () => { ...@@ -279,10 +279,10 @@ describe('Diffs Module Getters', () => {
describe('getDiffFileByHash', () => { describe('getDiffFileByHash', () => {
it('returns file by hash', () => { it('returns file by hash', () => {
const fileA = { const fileA = {
fileHash: '123', file_hash: '123',
}; };
const fileB = { const fileB = {
fileHash: '456', file_hash: '456',
}; };
localState.diffFiles = [fileA, fileB]; localState.diffFiles = [fileA, fileB];
......
...@@ -37,7 +37,7 @@ describe('DiffsStoreMutations', () => { ...@@ -37,7 +37,7 @@ describe('DiffsStoreMutations', () => {
mutations[types.SET_DIFF_DATA](state, diffMock); 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(firstLine.right.text).toBeUndefined();
expect(state.diffFiles[0].renderIt).toEqual(true); expect(state.diffFiles[0].renderIt).toEqual(true);
...@@ -98,19 +98,19 @@ describe('DiffsStoreMutations', () => { ...@@ -98,19 +98,19 @@ describe('DiffsStoreMutations', () => {
it('should call utils.addContextLines with proper params', () => { it('should call utils.addContextLines with proper params', () => {
const options = { const options = {
lineNumbers: { oldLineNumber: 1, newLineNumber: 2 }, 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', fileHash: 'ff9200',
params: { params: {
bottom: true, bottom: true,
}, },
}; };
const diffFile = { const diffFile = {
fileHash: options.fileHash, file_hash: options.fileHash,
highlightedDiffLines: [], highlighted_diff_lines: [],
parallelDiffLines: [], parallel_diff_lines: [],
}; };
const state = { diffFiles: [diffFile] }; 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 findDiffFileSpy = spyOnDependency(mutations, 'findDiffFile').and.returnValue(diffFile);
const removeMatchLineSpy = spyOnDependency(mutations, 'removeMatchLine'); const removeMatchLineSpy = spyOnDependency(mutations, 'removeMatchLine');
...@@ -133,8 +133,8 @@ describe('DiffsStoreMutations', () => { ...@@ -133,8 +133,8 @@ describe('DiffsStoreMutations', () => {
); );
expect(addContextLinesSpy).toHaveBeenCalledWith({ expect(addContextLinesSpy).toHaveBeenCalledWith({
inlineLines: diffFile.highlightedDiffLines, inlineLines: diffFile.highlighted_diff_lines,
parallelLines: diffFile.parallelDiffLines, parallelLines: diffFile.parallel_diff_lines,
contextLines: options.contextLines, contextLines: options.contextLines,
bottom: options.params.bottom, bottom: options.params.bottom,
lineNumbers: options.lineNumbers, lineNumbers: options.lineNumbers,
...@@ -144,54 +144,50 @@ describe('DiffsStoreMutations', () => { ...@@ -144,54 +144,50 @@ describe('DiffsStoreMutations', () => {
describe('ADD_COLLAPSED_DIFFS', () => { describe('ADD_COLLAPSED_DIFFS', () => {
it('should update the state with the given data for the given file hash', () => { 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 fileHash = 123;
const state = { diffFiles: [{}, { fileHash, existingField: 0 }] }; const state = { diffFiles: [{}, { file_hash: fileHash, existing_field: 0 }] };
const data = { diff_files: [{ file_hash: fileHash, extra_field: 1, existingField: 1 }] }; const data = { diff_files: [{ file_hash: fileHash, extra_field: 1, existing_field: 1 }] };
mutations[types.ADD_COLLAPSED_DIFFS](state, { file: state.diffFiles[1], data }); mutations[types.ADD_COLLAPSED_DIFFS](state, { file: state.diffFiles[1], data });
expect(spy).toHaveBeenCalledWith(data, { deep: true }); expect(state.diffFiles[1].file_hash).toEqual(fileHash);
expect(state.diffFiles[1].existing_field).toEqual(1);
expect(state.diffFiles[1].fileHash).toEqual(fileHash); expect(state.diffFiles[1].extra_field).toEqual(1);
expect(state.diffFiles[1].existingField).toEqual(1);
expect(state.diffFiles[1].extraField).toEqual(1);
}); });
}); });
describe('SET_LINE_DISCUSSIONS_FOR_FILE', () => { describe('SET_LINE_DISCUSSIONS_FOR_FILE', () => {
it('should add discussions to the given line', () => { it('should add discussions to the given line', () => {
const diffPosition = { const diffPosition = {
baseSha: 'ed13df29948c41ba367caa757ab3ec4892509910', base_sha: 'ed13df29948c41ba367caa757ab3ec4892509910',
headSha: 'b921914f9a834ac47e6fd9420f78db0f83559130', head_sha: 'b921914f9a834ac47e6fd9420f78db0f83559130',
newLine: null, new_line: null,
newPath: '500-lines-4.txt', new_path: '500-lines-4.txt',
oldLine: 5, old_line: 5,
oldPath: '500-lines-4.txt', old_path: '500-lines-4.txt',
startSha: 'ed13df29948c41ba367caa757ab3ec4892509910', start_sha: 'ed13df29948c41ba367caa757ab3ec4892509910',
}; };
const state = { const state = {
latestDiff: true, latestDiff: true,
diffFiles: [ diffFiles: [
{ {
fileHash: 'ABC', file_hash: 'ABC',
parallelDiffLines: [ parallel_diff_lines: [
{ {
left: { left: {
lineCode: 'ABC_1', line_code: 'ABC_1',
discussions: [], discussions: [],
}, },
right: { right: {
lineCode: 'ABC_1', line_code: 'ABC_1',
discussions: [], discussions: [],
}, },
}, },
], ],
highlightedDiffLines: [ highlighted_diff_lines: [
{ {
lineCode: 'ABC_1', line_code: 'ABC_1',
discussions: [], discussions: [],
}, },
], ],
...@@ -206,7 +202,7 @@ describe('DiffsStoreMutations', () => { ...@@ -206,7 +202,7 @@ describe('DiffsStoreMutations', () => {
original_position: diffPosition, original_position: diffPosition,
position: diffPosition, position: diffPosition,
diff_file: { diff_file: {
file_hash: state.diffFiles[0].fileHash, file_hash: state.diffFiles[0].file_hash,
}, },
}; };
...@@ -219,46 +215,46 @@ describe('DiffsStoreMutations', () => { ...@@ -219,46 +215,46 @@ describe('DiffsStoreMutations', () => {
diffPositionByLineCode, diffPositionByLineCode,
}); });
expect(state.diffFiles[0].parallelDiffLines[0].left.discussions.length).toEqual(1); expect(state.diffFiles[0].parallel_diff_lines[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[0].id).toEqual(1);
expect(state.diffFiles[0].parallelDiffLines[0].right.discussions).toEqual([]); 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].highlighted_diff_lines[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[0].id).toEqual(1);
}); });
it('should add legacy discussions to the given line', () => { it('should add legacy discussions to the given line', () => {
const diffPosition = { const diffPosition = {
baseSha: 'ed13df29948c41ba367caa757ab3ec4892509910', base_sha: 'ed13df29948c41ba367caa757ab3ec4892509910',
headSha: 'b921914f9a834ac47e6fd9420f78db0f83559130', head_sha: 'b921914f9a834ac47e6fd9420f78db0f83559130',
newLine: null, new_line: null,
newPath: '500-lines-4.txt', new_path: '500-lines-4.txt',
oldLine: 5, old_line: 5,
oldPath: '500-lines-4.txt', old_path: '500-lines-4.txt',
startSha: 'ed13df29948c41ba367caa757ab3ec4892509910', start_sha: 'ed13df29948c41ba367caa757ab3ec4892509910',
lineCode: 'ABC_1', line_code: 'ABC_1',
}; };
const state = { const state = {
latestDiff: true, latestDiff: true,
diffFiles: [ diffFiles: [
{ {
fileHash: 'ABC', file_hash: 'ABC',
parallelDiffLines: [ parallel_diff_lines: [
{ {
left: { left: {
lineCode: 'ABC_1', line_code: 'ABC_1',
discussions: [], discussions: [],
}, },
right: { right: {
lineCode: 'ABC_1', line_code: 'ABC_1',
discussions: [], discussions: [],
}, },
}, },
], ],
highlightedDiffLines: [ highlighted_diff_lines: [
{ {
lineCode: 'ABC_1', line_code: 'ABC_1',
discussions: [], discussions: [],
}, },
], ],
...@@ -271,7 +267,7 @@ describe('DiffsStoreMutations', () => { ...@@ -271,7 +267,7 @@ describe('DiffsStoreMutations', () => {
diff_discussion: true, diff_discussion: true,
active: true, active: true,
diff_file: { diff_file: {
file_hash: state.diffFiles[0].fileHash, file_hash: state.diffFiles[0].file_hash,
}, },
}; };
...@@ -284,11 +280,11 @@ describe('DiffsStoreMutations', () => { ...@@ -284,11 +280,11 @@ describe('DiffsStoreMutations', () => {
diffPositionByLineCode, diffPositionByLineCode,
}); });
expect(state.diffFiles[0].parallelDiffLines[0].left.discussions.length).toEqual(1); expect(state.diffFiles[0].parallel_diff_lines[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[0].id).toEqual(1);
expect(state.diffFiles[0].highlightedDiffLines[0].discussions.length).toEqual(1); expect(state.diffFiles[0].highlighted_diff_lines[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[0].id).toEqual(1);
}); });
}); });
...@@ -297,11 +293,11 @@ describe('DiffsStoreMutations', () => { ...@@ -297,11 +293,11 @@ describe('DiffsStoreMutations', () => {
const state = { const state = {
diffFiles: [ diffFiles: [
{ {
fileHash: 'ABC', file_hash: 'ABC',
parallelDiffLines: [ parallel_diff_lines: [
{ {
left: { left: {
lineCode: 'ABC_1', line_code: 'ABC_1',
discussions: [ discussions: [
{ {
id: 1, id: 1,
...@@ -314,14 +310,14 @@ describe('DiffsStoreMutations', () => { ...@@ -314,14 +310,14 @@ describe('DiffsStoreMutations', () => {
], ],
}, },
right: { right: {
lineCode: 'ABC_1', line_code: 'ABC_1',
discussions: [], discussions: [],
}, },
}, },
], ],
highlightedDiffLines: [ highlighted_diff_lines: [
{ {
lineCode: 'ABC_1', line_code: 'ABC_1',
discussions: [ discussions: [
{ {
id: 1, id: 1,
...@@ -343,8 +339,8 @@ describe('DiffsStoreMutations', () => { ...@@ -343,8 +339,8 @@ describe('DiffsStoreMutations', () => {
lineCode: 'ABC_1', lineCode: 'ABC_1',
}); });
expect(state.diffFiles[0].parallelDiffLines[0].left.discussions.length).toEqual(0); expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions.length).toEqual(0);
expect(state.diffFiles[0].highlightedDiffLines[0].discussions.length).toEqual(0); expect(state.diffFiles[0].highlighted_diff_lines[0].discussions.length).toEqual(0);
}); });
}); });
......
...@@ -18,7 +18,7 @@ const getDiffFileMock = () => Object.assign({}, diffFileMockData); ...@@ -18,7 +18,7 @@ const getDiffFileMock = () => Object.assign({}, diffFileMockData);
describe('DiffsStoreUtils', () => { describe('DiffsStoreUtils', () => {
describe('findDiffFile', () => { describe('findDiffFile', () => {
const files = [{ fileHash: 1, name: 'one' }]; const files = [{ file_hash: 1, name: 'one' }];
it('should return correct file', () => { it('should return correct file', () => {
expect(utils.findDiffFile(files, 1).name).toEqual('one'); expect(utils.findDiffFile(files, 1).name).toEqual('one');
...@@ -41,13 +41,13 @@ describe('DiffsStoreUtils', () => { ...@@ -41,13 +41,13 @@ describe('DiffsStoreUtils', () => {
describe('findIndexInInlineLines', () => { describe('findIndexInInlineLines', () => {
it('should return correct index for given line numbers', () => { it('should return correct index for given line numbers', () => {
expectSet(utils.findIndexInInlineLines, getDiffFileMock().highlightedDiffLines); expectSet(utils.findIndexInInlineLines, getDiffFileMock().highlighted_diff_lines);
}); });
}); });
describe('findIndexInParallelLines', () => { describe('findIndexInParallelLines', () => {
it('should return correct index for given line numbers', () => { 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', () => { ...@@ -56,33 +56,39 @@ describe('DiffsStoreUtils', () => {
it('should remove match line properly by regarding the bottom parameter', () => { it('should remove match line properly by regarding the bottom parameter', () => {
const diffFile = getDiffFileMock(); const diffFile = getDiffFileMock();
const lineNumbers = { oldLineNumber: 3, newLineNumber: 5 }; const lineNumbers = { oldLineNumber: 3, newLineNumber: 5 };
const inlineIndex = utils.findIndexInInlineLines(diffFile.highlightedDiffLines, lineNumbers); const inlineIndex = utils.findIndexInInlineLines(
const parallelIndex = utils.findIndexInParallelLines(diffFile.parallelDiffLines, lineNumbers); diffFile.highlighted_diff_lines,
const atInlineIndex = diffFile.highlightedDiffLines[inlineIndex]; lineNumbers,
const atParallelIndex = diffFile.parallelDiffLines[parallelIndex]; );
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); utils.removeMatchLine(diffFile, lineNumbers, false);
expect(diffFile.highlightedDiffLines[inlineIndex]).not.toEqual(atInlineIndex); expect(diffFile.highlighted_diff_lines[inlineIndex]).not.toEqual(atInlineIndex);
expect(diffFile.parallelDiffLines[parallelIndex]).not.toEqual(atParallelIndex); expect(diffFile.parallel_diff_lines[parallelIndex]).not.toEqual(atParallelIndex);
utils.removeMatchLine(diffFile, lineNumbers, true); utils.removeMatchLine(diffFile, lineNumbers, true);
expect(diffFile.highlightedDiffLines[inlineIndex + 1]).not.toEqual(atInlineIndex); expect(diffFile.highlighted_diff_lines[inlineIndex + 1]).not.toEqual(atInlineIndex);
expect(diffFile.parallelDiffLines[parallelIndex + 1]).not.toEqual(atParallelIndex); expect(diffFile.parallel_diff_lines[parallelIndex + 1]).not.toEqual(atParallelIndex);
}); });
}); });
describe('addContextLines', () => { describe('addContextLines', () => {
it('should add context lines properly with bottom parameter', () => { it('should add context lines properly with bottom parameter', () => {
const diffFile = getDiffFileMock(); const diffFile = getDiffFileMock();
const inlineLines = diffFile.highlightedDiffLines; const inlineLines = diffFile.highlighted_diff_lines;
const parallelLines = diffFile.parallelDiffLines; const parallelLines = diffFile.parallel_diff_lines;
const lineNumbers = { oldLineNumber: 3, newLineNumber: 5 }; const lineNumbers = { oldLineNumber: 3, newLineNumber: 5 };
const contextLines = [{ lineNumber: 42 }]; const contextLines = [{ lineNumber: 42 }];
const options = { inlineLines, parallelLines, contextLines, lineNumbers, bottom: true }; const options = { inlineLines, parallelLines, contextLines, lineNumbers, bottom: true };
const inlineIndex = utils.findIndexInInlineLines(diffFile.highlightedDiffLines, lineNumbers); const inlineIndex = utils.findIndexInInlineLines(inlineLines, lineNumbers);
const parallelIndex = utils.findIndexInParallelLines(diffFile.parallelDiffLines, lineNumbers); const parallelIndex = utils.findIndexInParallelLines(parallelLines, lineNumbers);
const normalizedParallelLine = { const normalizedParallelLine = {
left: options.contextLines[0], left: options.contextLines[0],
right: options.contextLines[0], right: options.contextLines[0],
...@@ -112,30 +118,30 @@ describe('DiffsStoreUtils', () => { ...@@ -112,30 +118,30 @@ describe('DiffsStoreUtils', () => {
noteableType: MERGE_REQUEST_NOTEABLE_TYPE, noteableType: MERGE_REQUEST_NOTEABLE_TYPE,
diffFile, diffFile,
noteTargetLine: { noteTargetLine: {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3',
metaData: null, meta_data: null,
newLine: 3, new_line: 3,
oldLine: 1, old_line: 1,
}, },
diffViewType: PARALLEL_DIFF_VIEW_TYPE, diffViewType: PARALLEL_DIFF_VIEW_TYPE,
linePosition: LINE_POSITION_LEFT, linePosition: LINE_POSITION_LEFT,
}; };
const position = JSON.stringify({ const position = JSON.stringify({
base_sha: diffFile.diffRefs.baseSha, base_sha: diffFile.diff_refs.base_sha,
start_sha: diffFile.diffRefs.startSha, start_sha: diffFile.diff_refs.start_sha,
head_sha: diffFile.diffRefs.headSha, head_sha: diffFile.diff_refs.head_sha,
old_path: diffFile.oldPath, old_path: diffFile.old_path,
new_path: diffFile.newPath, new_path: diffFile.new_path,
position_type: TEXT_DIFF_POSITION_TYPE, position_type: TEXT_DIFF_POSITION_TYPE,
old_line: options.noteTargetLine.oldLine, old_line: options.noteTargetLine.old_line,
new_line: options.noteTargetLine.newLine, new_line: options.noteTargetLine.new_line,
}); });
const postData = { const postData = {
view: options.diffViewType, view: options.diffViewType,
line_type: options.linePosition === LINE_POSITION_RIGHT ? NEW_LINE_TYPE : OLD_LINE_TYPE, 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: '', in_reply_to_discussion_id: '',
note_project_id: '', note_project_id: '',
target_type: options.noteableType, target_type: options.noteableType,
...@@ -146,7 +152,7 @@ describe('DiffsStoreUtils', () => { ...@@ -146,7 +152,7 @@ describe('DiffsStoreUtils', () => {
noteable_id: options.noteableData.id, noteable_id: options.noteableData.id,
commit_id: '', commit_id: '',
type: DIFF_NOTE_TYPE, type: DIFF_NOTE_TYPE,
line_code: options.noteTargetLine.lineCode, line_code: options.noteTargetLine.line_code,
note: options.note, note: options.note,
position, position,
}, },
...@@ -160,8 +166,8 @@ describe('DiffsStoreUtils', () => { ...@@ -160,8 +166,8 @@ describe('DiffsStoreUtils', () => {
it('should create legacy note form data', () => { it('should create legacy note form data', () => {
const diffFile = getDiffFileMock(); const diffFile = getDiffFileMock();
delete diffFile.diffRefs.startSha; delete diffFile.diff_refs.start_sha;
delete diffFile.diffRefs.headSha; delete diffFile.diff_refs.head_sha;
noteableDataMock.targetType = MERGE_REQUEST_NOTEABLE_TYPE; noteableDataMock.targetType = MERGE_REQUEST_NOTEABLE_TYPE;
...@@ -171,24 +177,24 @@ describe('DiffsStoreUtils', () => { ...@@ -171,24 +177,24 @@ describe('DiffsStoreUtils', () => {
noteableType: MERGE_REQUEST_NOTEABLE_TYPE, noteableType: MERGE_REQUEST_NOTEABLE_TYPE,
diffFile, diffFile,
noteTargetLine: { noteTargetLine: {
lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3', line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3',
metaData: null, meta_data: null,
newLine: 3, new_line: 3,
oldLine: 1, old_line: 1,
}, },
diffViewType: PARALLEL_DIFF_VIEW_TYPE, diffViewType: PARALLEL_DIFF_VIEW_TYPE,
linePosition: LINE_POSITION_LEFT, linePosition: LINE_POSITION_LEFT,
}; };
const position = JSON.stringify({ const position = JSON.stringify({
base_sha: diffFile.diffRefs.baseSha, base_sha: diffFile.diff_refs.base_sha,
start_sha: undefined, start_sha: undefined,
head_sha: undefined, head_sha: undefined,
old_path: diffFile.oldPath, old_path: diffFile.old_path,
new_path: diffFile.newPath, new_path: diffFile.new_path,
position_type: TEXT_DIFF_POSITION_TYPE, position_type: TEXT_DIFF_POSITION_TYPE,
old_line: options.noteTargetLine.oldLine, old_line: options.noteTargetLine.old_line,
new_line: options.noteTargetLine.newLine, new_line: options.noteTargetLine.new_line,
}); });
const postData = { const postData = {
...@@ -205,7 +211,7 @@ describe('DiffsStoreUtils', () => { ...@@ -205,7 +211,7 @@ describe('DiffsStoreUtils', () => {
noteable_id: options.noteableData.id, noteable_id: options.noteableData.id,
commit_id: '', commit_id: '',
type: LEGACY_DIFF_NOTE_TYPE, type: LEGACY_DIFF_NOTE_TYPE,
line_code: options.noteTargetLine.lineCode, line_code: options.noteTargetLine.line_code,
note: options.note, note: options.note,
position, position,
}, },
...@@ -225,61 +231,61 @@ describe('DiffsStoreUtils', () => { ...@@ -225,61 +231,61 @@ describe('DiffsStoreUtils', () => {
const lines = [{ type: null }, { type: MATCH_LINE_TYPE }]; const lines = [{ type: null }, { type: MATCH_LINE_TYPE }];
const linesWithReferences = utils.addLineReferences(lines, lineNumbers, true); const linesWithReferences = utils.addLineReferences(lines, lineNumbers, true);
expect(linesWithReferences[0].oldLine).toEqual(lineNumbers.oldLineNumber + 1); expect(linesWithReferences[0].old_line).toEqual(lineNumbers.oldLineNumber + 1);
expect(linesWithReferences[0].newLine).toEqual(lineNumbers.newLineNumber + 1); expect(linesWithReferences[0].new_line).toEqual(lineNumbers.newLineNumber + 1);
expect(linesWithReferences[1].metaData.oldPos).toEqual(4); expect(linesWithReferences[1].meta_data.old_pos).toEqual(4);
expect(linesWithReferences[1].metaData.newPos).toEqual(5); expect(linesWithReferences[1].meta_data.new_pos).toEqual(5);
}); });
it('should add correct line references when bottom falsy', () => { it('should add correct line references when bottom falsy', () => {
const lines = [{ type: null }, { type: MATCH_LINE_TYPE }, { type: null }]; const lines = [{ type: null }, { type: MATCH_LINE_TYPE }, { type: null }];
const linesWithReferences = utils.addLineReferences(lines, lineNumbers); const linesWithReferences = utils.addLineReferences(lines, lineNumbers);
expect(linesWithReferences[0].oldLine).toEqual(0); expect(linesWithReferences[0].old_line).toEqual(0);
expect(linesWithReferences[0].newLine).toEqual(1); expect(linesWithReferences[0].new_line).toEqual(1);
expect(linesWithReferences[1].metaData.oldPos).toEqual(2); expect(linesWithReferences[1].meta_data.old_pos).toEqual(2);
expect(linesWithReferences[1].metaData.newPos).toEqual(3); expect(linesWithReferences[1].meta_data.new_pos).toEqual(3);
}); });
}); });
describe('trimFirstCharOfLineContent', () => { describe('trimFirstCharOfLineContent', () => {
it('trims the line when it starts with a space', () => { it('trims the line when it starts with a space', () => {
expect(utils.trimFirstCharOfLineContent({ richText: ' diff' })).toEqual({ expect(utils.trimFirstCharOfLineContent({ rich_text: ' diff' })).toEqual({
discussions: [], discussions: [],
richText: 'diff', rich_text: 'diff',
}); });
}); });
it('trims the line when it starts with a +', () => { it('trims the line when it starts with a +', () => {
expect(utils.trimFirstCharOfLineContent({ richText: '+diff' })).toEqual({ expect(utils.trimFirstCharOfLineContent({ rich_text: '+diff' })).toEqual({
discussions: [], discussions: [],
richText: 'diff', rich_text: 'diff',
}); });
}); });
it('trims the line when it starts with a -', () => { it('trims the line when it starts with a -', () => {
expect(utils.trimFirstCharOfLineContent({ richText: '-diff' })).toEqual({ expect(utils.trimFirstCharOfLineContent({ rich_text: '-diff' })).toEqual({
discussions: [], discussions: [],
richText: 'diff', rich_text: 'diff',
}); });
}); });
it('does not trims the line when it starts with a letter', () => { 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: [], discussions: [],
richText: 'diff', rich_text: 'diff',
}); });
}); });
it('does not modify the provided object', () => { it('does not modify the provided object', () => {
const lineObj = { const lineObj = {
discussions: [], discussions: [],
richText: ' diff', rich_text: ' diff',
}; };
utils.trimFirstCharOfLineContent(lineObj); utils.trimFirstCharOfLineContent(lineObj);
expect(lineObj).toEqual({ discussions: [], richText: ' diff' }); expect(lineObj).toEqual({ discussions: [], rich_text: ' diff' });
}); });
it('handles a undefined or null parameter', () => { it('handles a undefined or null parameter', () => {
...@@ -289,33 +295,33 @@ describe('DiffsStoreUtils', () => { ...@@ -289,33 +295,33 @@ describe('DiffsStoreUtils', () => {
describe('prepareDiffData', () => { describe('prepareDiffData', () => {
it('sets the renderIt and collapsed attribute on files', () => { it('sets the renderIt and collapsed attribute on files', () => {
const preparedDiff = { diffFiles: [getDiffFileMock()] }; const preparedDiff = { diff_files: [getDiffFileMock()] };
utils.prepareDiffData(preparedDiff); 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.discussions.length).toBe(0);
expect(firstParallelDiffLine.left).not.toHaveAttr('text'); expect(firstParallelDiffLine.left).not.toHaveAttr('text');
expect(firstParallelDiffLine.right.discussions.length).toBe(0); expect(firstParallelDiffLine.right.discussions.length).toBe(0);
expect(firstParallelDiffLine.right).not.toHaveAttr('text'); 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('+'); 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.discussions.length).toBe(0);
expect(checkLine).not.toHaveAttr('text'); 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(firstChar).not.toBe('+');
expect(firstChar).not.toBe('-'); expect(firstChar).not.toBe('-');
expect(preparedDiff.diffFiles[0].renderIt).toBeTruthy(); expect(preparedDiff.diff_files[0].renderIt).toBeTruthy();
expect(preparedDiff.diffFiles[0].collapsed).toBeFalsy(); expect(preparedDiff.diff_files[0].collapsed).toBeFalsy();
}); });
}); });
...@@ -398,7 +404,7 @@ describe('DiffsStoreUtils', () => { ...@@ -398,7 +404,7 @@ describe('DiffsStoreUtils', () => {
discussion, discussion,
diffPosition: { diffPosition: {
...diffPosition, ...diffPosition,
lineCode: 'ABC_1', line_code: 'ABC_1',
}, },
latestDiff: true, latestDiff: true,
}), }),
...@@ -429,36 +435,36 @@ describe('DiffsStoreUtils', () => { ...@@ -429,36 +435,36 @@ describe('DiffsStoreUtils', () => {
beforeAll(() => { beforeAll(() => {
files = [ files = [
{ {
newPath: 'app/index.js', new_path: 'app/index.js',
deletedFile: false, deleted_file: false,
newFile: false, new_file: false,
removedLines: 10, removed_lines: 10,
addedLines: 0, added_lines: 0,
fileHash: 'test', file_hash: 'test',
}, },
{ {
newPath: 'app/test/index.js', new_path: 'app/test/index.js',
deletedFile: false, deleted_file: false,
newFile: true, new_file: true,
removedLines: 0, removed_lines: 0,
addedLines: 0, added_lines: 0,
fileHash: 'test', file_hash: 'test',
}, },
{ {
newPath: 'app/test/filepathneedstruncating.js', new_path: 'app/test/filepathneedstruncating.js',
deletedFile: false, deleted_file: false,
newFile: true, new_file: true,
removedLines: 0, removed_lines: 0,
addedLines: 0, added_lines: 0,
fileHash: 'test', file_hash: 'test',
}, },
{ {
newPath: 'package.json', new_path: 'package.json',
deletedFile: true, deleted_file: true,
newFile: false, new_file: false,
removedLines: 0, removed_lines: 0,
addedLines: 0, added_lines: 0,
fileHash: 'test', file_hash: 'test',
}, },
]; ];
}); });
......
import Vue from 'vue'; import Vue from 'vue';
import DiffWithNote from '~/notes/components/diff_with_note.vue'; import DiffWithNote from '~/notes/components/diff_with_note.vue';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { createStore } from '~/mr_notes/stores'; import { createStore } from '~/mr_notes/stores';
import { mountComponentWithStore } from 'spec/helpers'; import { mountComponentWithStore } from 'spec/helpers';
...@@ -11,7 +10,7 @@ describe('diff_with_note', () => { ...@@ -11,7 +10,7 @@ describe('diff_with_note', () => {
let store; let store;
let vm; let vm;
const diffDiscussionMock = getJSONFixture(discussionFixture)[0]; const diffDiscussionMock = getJSONFixture(discussionFixture)[0];
const diffDiscussion = convertObjectPropsToCamelCase(diffDiscussionMock); const diffDiscussion = diffDiscussionMock;
const Component = Vue.extend(DiffWithNote); const Component = Vue.extend(DiffWithNote);
const props = { const props = {
discussion: diffDiscussion, discussion: diffDiscussion,
...@@ -65,7 +64,7 @@ describe('diff_with_note', () => { ...@@ -65,7 +64,7 @@ describe('diff_with_note', () => {
describe('image diff', () => { describe('image diff', () => {
beforeEach(() => { beforeEach(() => {
const imageDiffDiscussionMock = getJSONFixture(imageDiscussionFixture)[0]; const imageDiffDiscussionMock = getJSONFixture(imageDiscussionFixture)[0];
props.discussion = convertObjectPropsToCamelCase(imageDiffDiscussionMock); props.discussion = imageDiffDiscussionMock;
}); });
it('shows image diff', () => { it('shows image diff', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment