Commit bbdad735 authored by Illya Klymov's avatar Illya Klymov Committed by Mike Greiling

Refactor DiffFileHeader tests

* Switched from Karma to Jest
* Reorganized tests to have correct semantics
* Removed unused computed properties from component
parent 42ce83bd
...@@ -57,26 +57,12 @@ export default { ...@@ -57,26 +57,12 @@ export default {
required: true, required: true,
}, },
}, },
data() {
return {
blobForkSuggestion: null,
};
},
computed: { computed: {
...mapGetters('diffs', ['diffHasExpandedDiscussions', 'diffHasDiscussions']), ...mapGetters('diffs', ['diffHasExpandedDiscussions', 'diffHasDiscussions']),
hasExpandedDiscussions() {
return this.diffHasExpandedDiscussions(this.diffFile);
},
diffContentIDSelector() { diffContentIDSelector() {
return `#diff-content-${this.diffFile.file_hash}`; return `#diff-content-${this.diffFile.file_hash}`;
}, },
icon() {
if (this.diffFile.submodule) {
return 'archive';
}
return this.diffFile.blob.icon;
},
titleLink() { titleLink() {
if (this.diffFile.submodule) { if (this.diffFile.submodule) {
return this.diffFile.submodule_tree_url || this.diffFile.submodule_link; return this.diffFile.submodule_tree_url || this.diffFile.submodule_link;
...@@ -99,9 +85,6 @@ export default { ...@@ -99,9 +85,6 @@ export default {
return this.diffFile.file_path; return this.diffFile.file_path;
}, },
titleTag() {
return this.diffFile.file_hash ? 'a' : 'span';
},
isUsingLfs() { isUsingLfs() {
return this.diffFile.stored_externally && this.diffFile.external_storage === 'lfs'; return this.diffFile.stored_externally && this.diffFile.external_storage === 'lfs';
}, },
...@@ -135,9 +118,6 @@ export default { ...@@ -135,9 +118,6 @@ export default {
isModeChanged() { isModeChanged() {
return this.diffFile.viewer.name === diffViewerModes.mode_changed; return this.diffFile.viewer.name === diffViewerModes.mode_changed;
}, },
showExpandDiffToFullFileEnabled() {
return gon.features.expandDiffFullFile && !this.diffFile.is_fully_expanded;
},
expandDiffToFullFileTitle() { expandDiffToFullFileTitle() {
if (this.diffFile.isShowingFullFile) { if (this.diffFile.isShowingFullFile) {
return s__('MRDiff|Show changes only'); return s__('MRDiff|Show changes only');
...@@ -156,21 +136,12 @@ export default { ...@@ -156,21 +136,12 @@ export default {
'toggleFileDiscussionWrappers', 'toggleFileDiscussionWrappers',
'toggleFullDiff', 'toggleFullDiff',
]), ]),
handleToggleFile(e, checkTarget) { handleToggleFile() {
if ( this.$emit('toggleFile');
!checkTarget ||
e.target === this.$refs.header ||
(e.target.classList && e.target.classList.contains('diff-toggle-caret'))
) {
this.$emit('toggleFile');
}
}, },
showForkMessage() { showForkMessage() {
this.$emit('showForkMessage'); this.$emit('showForkMessage');
}, },
handleToggleDiscussions() {
this.toggleFileDiscussionWrappers(this.diffFile);
},
handleFileNameClick(e) { handleFileNameClick(e) {
const isLinkToOtherPage = const isLinkToOtherPage =
this.diffFile.submodule_tree_url || this.diffFile.submodule_link || this.discussionPath; this.diffFile.submodule_tree_url || this.diffFile.submodule_link || this.discussionPath;
...@@ -178,7 +149,6 @@ export default { ...@@ -178,7 +149,6 @@ export default {
if (!isLinkToOtherPage) { if (!isLinkToOtherPage) {
e.preventDefault(); e.preventDefault();
const selector = this.diffContentIDSelector; const selector = this.diffContentIDSelector;
scrollToElement(document.querySelector(selector)); scrollToElement(document.querySelector(selector));
window.location.hash = selector; window.location.hash = selector;
} }
...@@ -191,22 +161,23 @@ export default { ...@@ -191,22 +161,23 @@ export default {
<div <div
ref="header" ref="header"
class="js-file-title file-title file-title-flex-parent" class="js-file-title file-title file-title-flex-parent"
@click="handleToggleFile($event, true)" @click.self="handleToggleFile"
> >
<div class="file-header-content"> <div class="file-header-content">
<icon <icon
v-if="collapsible" v-if="collapsible"
ref="collapseIcon"
:name="collapseIcon" :name="collapseIcon"
:size="16" :size="16"
aria-hidden="true" aria-hidden="true"
class="diff-toggle-caret append-right-5" class="diff-toggle-caret append-right-5"
@click.stop="handleToggle" @click.stop="handleToggleFile"
/> />
<a <a
v-once v-once
id="diffFile.file_path" id="diffFile.file_path"
ref="titleWrapper" ref="titleWrapper"
class="append-right-4 js-title-wrapper" class="append-right-4"
:href="titleLink" :href="titleLink"
@click="handleFileNameClick" @click="handleFileNameClick"
> >
...@@ -214,7 +185,7 @@ export default { ...@@ -214,7 +185,7 @@ export default {
:file-name="filePath" :file-name="filePath"
:size="18" :size="18"
aria-hidden="true" aria-hidden="true"
css-classes="js-file-icon append-right-5" css-classes="append-right-5"
/> />
<span v-if="isFileRenamed"> <span v-if="isFileRenamed">
<strong <strong
...@@ -260,12 +231,13 @@ export default { ...@@ -260,12 +231,13 @@ export default {
<template v-if="diffFile.blob && diffFile.blob.readable_text"> <template v-if="diffFile.blob && diffFile.blob.readable_text">
<span v-gl-tooltip.hover :title="s__('MergeRequests|Toggle comments for this file')"> <span v-gl-tooltip.hover :title="s__('MergeRequests|Toggle comments for this file')">
<gl-button <gl-button
ref="toggleDiscussionsButton"
:disabled="!diffHasDiscussions(diffFile)" :disabled="!diffHasDiscussions(diffFile)"
:class="{ active: hasExpandedDiscussions }" :class="{ active: diffHasExpandedDiscussions(diffFile) }"
class="js-btn-vue-toggle-comments btn" class="js-btn-vue-toggle-comments btn"
data-qa-selector="toggle_comments_button" data-qa-selector="toggle_comments_button"
type="button" type="button"
@click="handleToggleDiscussions" @click="toggleFileDiscussionWrappers(diffFile)"
> >
<icon name="comment" /> <icon name="comment" />
</gl-button> </gl-button>
...@@ -282,8 +254,9 @@ export default { ...@@ -282,8 +254,9 @@ export default {
<a <a
v-if="diffFile.replaced_view_path" v-if="diffFile.replaced_view_path"
ref="replacedFileButton"
:href="diffFile.replaced_view_path" :href="diffFile.replaced_view_path"
class="btn view-file js-view-replaced-file" class="btn view-file"
v-html="viewReplacedFileButtonText" v-html="viewReplacedFileButtonText"
> >
</a> </a>
...@@ -292,7 +265,7 @@ export default { ...@@ -292,7 +265,7 @@ export default {
ref="expandDiffToFullFileButton" ref="expandDiffToFullFileButton"
v-gl-tooltip.hover v-gl-tooltip.hover
:title="expandDiffToFullFileTitle" :title="expandDiffToFullFileTitle"
class="expand-file js-expand-file" class="expand-file"
@click="toggleFullDiff(diffFile.file_path)" @click="toggleFullDiff(diffFile.file_path)"
> >
<gl-loading-icon v-if="diffFile.isLoadingFullFile" color="dark" inline /> <gl-loading-icon v-if="diffFile.isLoadingFullFile" color="dark" inline />
...@@ -304,7 +277,7 @@ export default { ...@@ -304,7 +277,7 @@ export default {
v-gl-tooltip.hover v-gl-tooltip.hover
:href="diffFile.view_path" :href="diffFile.view_path"
target="blank" target="blank"
class="view-file js-view-file-button" class="view-file"
:title="viewFileButtonText" :title="viewFileButtonText"
> >
<icon name="doc-text" /> <icon name="doc-text" />
...@@ -312,12 +285,13 @@ export default { ...@@ -312,12 +285,13 @@ export default {
<a <a
v-if="diffFile.external_url" v-if="diffFile.external_url"
ref="externalLink"
v-gl-tooltip.hover v-gl-tooltip.hover
:href="diffFile.external_url" :href="diffFile.external_url"
:title="`View on ${diffFile.formatted_external_url}`" :title="`View on ${diffFile.formatted_external_url}`"
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
class="btn btn-file-option js-external-url" class="btn btn-file-option"
> >
<icon name="external-link" /> <icon name="external-link" />
</a> </a>
......
This diff is collapsed.
...@@ -206,7 +206,7 @@ describe('DiffsStoreActions', () => { ...@@ -206,7 +206,7 @@ describe('DiffsStoreActions', () => {
position_type: 'text', position_type: 'text',
}, },
}, },
hash: 'diff-content-1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a', hash: 'ABC_123',
}, },
}, },
], ],
......
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