diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/views/shared | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) | |
download | gitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/views/shared')
-rw-r--r-- | spec/views/shared/snippets/_snippet.html.haml_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/views/shared/snippets/_snippet.html.haml_spec.rb b/spec/views/shared/snippets/_snippet.html.haml_spec.rb new file mode 100644 index 00000000000..712021ec1e1 --- /dev/null +++ b/spec/views/shared/snippets/_snippet.html.haml_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'shared/snippets/_snippet.html.haml' do + let_it_be(:snippet) { create(:snippet) } + + before do + allow(view).to receive(:current_application_settings).and_return(Gitlab::CurrentSettings.current_application_settings) + allow(view).to receive(:can?) { true } + + @noteable_meta_data = Class.new { include Gitlab::NoteableMetadata }.new.noteable_meta_data([snippet], 'Snippet') + end + + context 'snippet with statistics' do + it 'renders correct file count and tooltip' do + snippet.statistics.file_count = 3 + + render 'shared/snippets/snippet', snippet: snippet + + expect(rendered).to have_selector("span.file_count", text: '3') + expect(rendered).to have_selector("span.file_count[title=\"3 files\"]") + end + + it 'renders correct file count and tooltip when file_count is 1' do + snippet.statistics.file_count = 1 + + render 'shared/snippets/snippet', snippet: snippet + + expect(rendered).to have_selector("span.file_count", text: '1') + expect(rendered).to have_selector("span.file_count[title=\"1 file\"]") + end + + it 'does not render file count when file count is 0' do + snippet.statistics.file_count = 0 + + render 'shared/snippets/snippet', snippet: snippet + + expect(rendered).not_to have_selector('span.file_count') + end + end + + context 'snippet without statistics' do + it 'does not render file count if statistics are not present' do + snippet.statistics = nil + + render 'shared/snippets/snippet', snippet: snippet + + expect(rendered).not_to have_selector('span.file_count') + end + end +end |