diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /spec/lib/gitlab/diff/file_spec.rb | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'spec/lib/gitlab/diff/file_spec.rb')
-rw-r--r-- | spec/lib/gitlab/diff/file_spec.rb | 98 |
1 files changed, 95 insertions, 3 deletions
diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb index f2212ec9b09..0d7a183bb11 100644 --- a/spec/lib/gitlab/diff/file_spec.rb +++ b/spec/lib/gitlab/diff/file_spec.rb @@ -51,6 +51,54 @@ RSpec.describe Gitlab::Diff::File do project.commit(branch_name).diffs.diff_files.first end + describe '#initialize' do + let(:commit) { project.commit("532c837") } + + context 'when file is ipynb' do + let(:ipynb_semantic_diff) { false } + let(:rendered_diffs_viewer) { false } + + before do + stub_feature_flags(ipynb_semantic_diff: ipynb_semantic_diff, rendered_diffs_viewer: rendered_diffs_viewer) + end + + context 'when ipynb_semantic_diff is off, and rendered_viewer is off' do + it 'does not generate notebook diffs' do + expect(Gitlab::Diff::CustomDiff).not_to receive(:preprocess_before_diff) + expect(diff_file.rendered).to be_nil + end + end + + context 'when ipynb_semantic_diff is off, and rendered_viewer is on' do + let(:rendered_diffs_viewer) { true } + + it 'does not generate rendered diff' do + expect(Gitlab::Diff::CustomDiff).not_to receive(:preprocess_before_diff) + expect(diff_file.rendered).to be_nil + end + end + + context 'when ipynb_semantic_diff is on, and rendered_viewer is off' do + let(:ipynb_semantic_diff) { true } + + it 'transforms using custom diff CustomDiff' do + expect(Gitlab::Diff::CustomDiff).to receive(:preprocess_before_diff).and_call_original + expect(diff_file.rendered).to be_nil + end + end + + context 'when ipynb_semantic_diff is on, and rendered_viewer is on' do + let(:ipynb_semantic_diff) { true } + let(:rendered_diffs_viewer) { true } + + it 'transforms diff using NotebookDiffFile' do + expect(Gitlab::Diff::CustomDiff).not_to receive(:preprocess_before_diff) + expect(diff_file.rendered).not_to be_nil + end + end + end + end + describe '#has_renderable?' do context 'file is ipynb' do let(:commit) { project.commit("532c837") } @@ -66,14 +114,58 @@ RSpec.describe Gitlab::Diff::File do it 'does not have renderable viewer' do expect(diff_file.has_renderable?).to be_falsey end + + it 'does not create a Notebook DiffFile' do + expect(diff_file.rendered).to be_nil + + expect(::Gitlab::Diff::Rendered::Notebook::DiffFile).not_to receive(:new) + end end end describe '#rendered' do - let(:commit) { project.commit("532c837") } + context 'when not ipynb' do + it 'is nil' do + expect(diff_file.rendered).to be_nil + end + end + + context 'when ipynb' do + let(:commit) { project.commit("532c837") } + + it 'creates a NotebookDiffFile for rendering' do + expect(diff_file.rendered).to be_kind_of(Gitlab::Diff::Rendered::Notebook::DiffFile) + end + + context 'when too large' do + it 'is nil' do + expect(diff).to receive(:too_large?).and_return(true) + + expect(diff_file.rendered).to be_nil + end + end + + context 'when not modified' do + it 'is nil' do + expect(diff_file).to receive(:modified_file?).and_return(false) + + expect(diff_file.rendered).to be_nil + end + end + + context 'when semantic ipynb is off' do + before do + stub_feature_flags(ipynb_semantic_diff: false) + end + + it 'returns nil' do + expect(diff_file).not_to receive(:modified_file?) + expect(diff_file).not_to receive(:ipynb?) + expect(diff).not_to receive(:too_large?) - it 'creates a NotebookDiffFile for rendering' do - expect(diff_file.rendered).to be_kind_of(Gitlab::Diff::Rendered::Notebook::DiffFile) + expect(diff_file.rendered).to be_nil + end + end end end |