summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Nichols <git@seanich.com>2018-12-13 01:49:32 -0500
committerSean Nichols <git@seanich.com>2018-12-13 01:49:32 -0500
commit4d2448e03a4f73edc785bd89620fa8c5efdf3def (patch)
tree031b43fa794ecfb072c1d0b91f8c279fa8592c4c
parent4ae1591b9768f8f727048ff83f675fe99a10eb90 (diff)
downloadgitlab-ce-4d2448e03a4f73edc785bd89620fa8c5efdf3def.tar.gz
Add tests and move empty file message into own component
-rw-r--r--app/assets/javascripts/diffs/components/diff_content.vue6
-rw-r--r--app/assets/javascripts/vue_shared/components/diff_viewer/viewers/empty_file.vue3
-rw-r--r--spec/javascripts/diffs/components/diff_content_spec.js31
-rw-r--r--spec/lib/gitlab/diff/file_spec.rb89
-rw-r--r--spec/support/shared_examples/serializers/diff_file_entity_examples.rb2
5 files changed, 128 insertions, 3 deletions
diff --git a/app/assets/javascripts/diffs/components/diff_content.vue b/app/assets/javascripts/diffs/components/diff_content.vue
index e9e9c8a5ec9..452938a2200 100644
--- a/app/assets/javascripts/diffs/components/diff_content.vue
+++ b/app/assets/javascripts/diffs/components/diff_content.vue
@@ -1,6 +1,7 @@
<script>
import { mapActions, mapGetters, mapState } from 'vuex';
import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue';
+import EmptyFileViewer from '~/vue_shared/components/diff_viewer/viewers/empty_file.vue';
import InlineDiffView from './inline_diff_view.vue';
import ParallelDiffView from './parallel_diff_view.vue';
import NoteForm from '../../notes/components/note_form.vue';
@@ -17,6 +18,7 @@ export default {
NoteForm,
DiffDiscussions,
ImageDiffOverlay,
+ EmptyFileViewer,
},
props: {
diffFile: {
@@ -69,8 +71,8 @@ export default {
<template>
<div class="diff-content">
<div class="diff-viewer">
- <div v-if="diffFile.empty" class="nothing-here-block">{{ __('Empty file') }}</div>
- <template v-else-if="isTextFile">
+ <template v-if="isTextFile">
+ <empty-file-viewer v-if="diffFile.empty" />
<inline-diff-view
v-if="isInlineView"
:diff-file="diffFile"
diff --git a/app/assets/javascripts/vue_shared/components/diff_viewer/viewers/empty_file.vue b/app/assets/javascripts/vue_shared/components/diff_viewer/viewers/empty_file.vue
new file mode 100644
index 00000000000..53210cbcc93
--- /dev/null
+++ b/app/assets/javascripts/vue_shared/components/diff_viewer/viewers/empty_file.vue
@@ -0,0 +1,3 @@
+<template>
+ <div class="nothing-here-block">{{ __('Empty file') }}</div>
+</template>
diff --git a/spec/javascripts/diffs/components/diff_content_spec.js b/spec/javascripts/diffs/components/diff_content_spec.js
index c25f6167163..a63960b3567 100644
--- a/spec/javascripts/diffs/components/diff_content_spec.js
+++ b/spec/javascripts/diffs/components/diff_content_spec.js
@@ -49,6 +49,37 @@ describe('DiffContent', () => {
});
});
+ describe('empty files', () => {
+ beforeEach(() => {
+ vm.diffFile.empty = true;
+ vm.diffFile.highlighted_diff_lines = [];
+ vm.diffFile.parallel_diff_lines = [];
+ });
+
+ it('should render a message', done => {
+ vm.$nextTick(() => {
+ expect(vm.$el.querySelector('.diff-viewer .nothing-here-block')).not.toBe(null);
+ expect(
+ vm.$el.querySelector('.diff-viewer .nothing-here-block').textContent.trim(),
+ ).toContain('Empty file');
+
+ done();
+ });
+ });
+
+ it('should not display multiple messages', done => {
+ vm.diffFile.mode_changed = true;
+ vm.diffFile.b_mode = '100755';
+ vm.diffFile.viewer.name = 'mode_changed';
+
+ vm.$nextTick(() => {
+ expect(vm.$el.querySelectorAll('.nothing-here-block').length).toBe(1);
+
+ done();
+ });
+ });
+ });
+
describe('Non-Text diffs', () => {
beforeEach(() => {
vm.diffFile.viewer.name = 'image';
diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb
index 3417896e259..f0ca47d8d41 100644
--- a/spec/lib/gitlab/diff/file_spec.rb
+++ b/spec/lib/gitlab/diff/file_spec.rb
@@ -583,6 +583,12 @@ describe Gitlab::Diff::File do
end
end
+ describe '#empty?' do
+ it 'returns true' do
+ expect(diff_file.empty?).to be_truthy
+ end
+ end
+
describe '#different_type?' do
it 'returns false' do
expect(diff_file).not_to be_different_type
@@ -662,4 +668,87 @@ describe Gitlab::Diff::File do
end
end
end
+
+ describe '#empty?' do
+ let(:project) do
+ create(:project, :custom_repo, files: {})
+ end
+ let(:branch_name) { 'master' }
+
+ def create_file(file_name, content)
+ Files::CreateService.new(
+ project,
+ project.owner,
+ commit_message: 'Update',
+ start_branch: branch_name,
+ branch_name: branch_name,
+ file_path: file_name,
+ file_content: content
+ ).execute
+
+ return project.commit(branch_name).diffs.diff_files.first
+ end
+
+ def update_file(file_name, content)
+ Files::UpdateService.new(
+ project,
+ project.owner,
+ commit_message: 'Update',
+ start_branch: branch_name,
+ branch_name: branch_name,
+ file_path: file_name,
+ file_content: content
+ ).execute
+
+ return project.commit(branch_name).diffs.diff_files.first
+ end
+
+ def delete_file(file_name)
+ Files::DeleteService.new(
+ project,
+ project.owner,
+ commit_message: 'Update',
+ start_branch: branch_name,
+ branch_name: branch_name,
+ file_path: file_name
+ ).execute
+
+ return project.commit(branch_name).diffs.diff_files.first
+ end
+
+ context 'when empty file is created' do
+ it 'returns true' do
+ diff_file = create_file('empty.md', '')
+
+ expect(diff_file.empty?).to be_truthy
+ end
+ end
+
+ context 'when empty file is deleted' do
+ it 'returns true' do
+ create_file('empty.md', '')
+ diff_file = delete_file('empty.md')
+
+ expect(diff_file.empty?).to be_truthy
+ end
+ end
+
+ context 'when file with content is truncated' do
+ it 'returns false' do
+ create_file('with-content.md', 'file content')
+ diff_file = update_file('with-content.md', '')
+
+ expect(diff_file.empty?).to be_falsey
+ end
+ end
+
+ context 'when empty file has content added' do
+ it 'returns false' do
+ create_file('empty.md', '')
+ diff_file = update_file('empty.md', 'new content')
+
+ expect(diff_file.empty?).to be_falsey
+ end
+ end
+ end
end
diff --git a/spec/support/shared_examples/serializers/diff_file_entity_examples.rb b/spec/support/shared_examples/serializers/diff_file_entity_examples.rb
index b8065886c42..1770308f789 100644
--- a/spec/support/shared_examples/serializers/diff_file_entity_examples.rb
+++ b/spec/support/shared_examples/serializers/diff_file_entity_examples.rb
@@ -32,7 +32,7 @@ shared_examples 'diff file entity' do
it 'exposes correct attributes' do
expect(subject).to include(:too_large, :added_lines, :removed_lines,
:context_lines_path, :highlighted_diff_lines,
- :parallel_diff_lines)
+ :parallel_diff_lines, :empty)
end
it 'includes viewer' do