diff options
Diffstat (limited to 'spec/lib/banzai')
7 files changed, 69 insertions, 10 deletions
diff --git a/spec/lib/banzai/cross_project_reference_spec.rb b/spec/lib/banzai/cross_project_reference_spec.rb index e703bbc4927..8748a910003 100644 --- a/spec/lib/banzai/cross_project_reference_spec.rb +++ b/spec/lib/banzai/cross_project_reference_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe Banzai::CrossProjectReference do let(:including_class) { Class.new.include(described_class).new } - let(:reference_cache) { Banzai::Filter::References::ReferenceCache.new(including_class, {}, {})} + let(:reference_cache) { Banzai::Filter::References::ReferenceCache.new(including_class, {}, {}) } before do allow(including_class).to receive(:context).and_return({}) diff --git a/spec/lib/banzai/filter/broadcast_message_placeholders_filter_spec.rb b/spec/lib/banzai/filter/broadcast_message_placeholders_filter_spec.rb index a2d35eaa6b6..c581750d2a9 100644 --- a/spec/lib/banzai/filter/broadcast_message_placeholders_filter_spec.rb +++ b/spec/lib/banzai/filter/broadcast_message_placeholders_filter_spec.rb @@ -29,7 +29,7 @@ RSpec.describe Banzai::Filter::BroadcastMessagePlaceholdersFilter do end context 'works with empty text' do - let(:text) {" "} + let(:text) { " " } it { expect(subject).to eq(" ") } end @@ -42,13 +42,13 @@ RSpec.describe Banzai::Filter::BroadcastMessagePlaceholdersFilter do context 'available placeholders' do context 'replaces the email of the user' do - let(:text) { "{{email}}"} + let(:text) { "{{email}}" } it { expect(subject).to eq(user.email) } end context 'replaces the name of the user' do - let(:text) { "{{name}}"} + let(:text) { "{{name}}" } it { expect(subject).to eq(user.name) } end diff --git a/spec/lib/banzai/filter/commit_trailers_filter_spec.rb b/spec/lib/banzai/filter/commit_trailers_filter_spec.rb index f7cb6b92b48..38f9bda57e6 100644 --- a/spec/lib/banzai/filter/commit_trailers_filter_spec.rb +++ b/spec/lib/banzai/filter/commit_trailers_filter_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Banzai::Filter::CommitTrailersFilter do let(:secondary_email) { create(:email, :confirmed) } let(:user) { create(:user) } - let(:trailer) { "#{FFaker::Lorem.word}-by:"} + let(:trailer) { "#{FFaker::Lorem.word}-by:" } let(:commit_message) { trailer_line(trailer, user.name, user.email) } let(:commit_message_html) { commit_html(commit_message) } diff --git a/spec/lib/banzai/filter/task_list_filter_spec.rb b/spec/lib/banzai/filter/task_list_filter_spec.rb index c89acd1a643..920904b0f29 100644 --- a/spec/lib/banzai/filter/task_list_filter_spec.rb +++ b/spec/lib/banzai/filter/task_list_filter_spec.rb @@ -10,4 +10,38 @@ RSpec.describe Banzai::Filter::TaskListFilter do expect(doc.xpath('.//li//task-button').count).to eq(2) end + + describe 'inapplicable list items' do + shared_examples 'a valid inapplicable task list item' do |html| + it "behaves correctly for `#{html}`" do + doc = filter("<ul><li>#{html}</li></ul>") + + expect(doc.css('li.inapplicable input[data-inapplicable]').count).to eq(1) + expect(doc.css('li.inapplicable > s').count).to eq(1) + end + end + + shared_examples 'an invalid inapplicable task list item' do |html| + it "does nothing for `#{html}`" do + doc = filter("<ul><li>#{html}</li></ul>") + + expect(doc.css('li.inapplicable input[data-inapplicable]').count).to eq(0) + end + end + + it_behaves_like 'a valid inapplicable task list item', '[~] foobar' + it_behaves_like 'a valid inapplicable task list item', '[~] foo <em>bar</em>' + it_behaves_like 'an invalid inapplicable task list item', '[ ] foobar' + it_behaves_like 'an invalid inapplicable task list item', '[x] foobar' + it_behaves_like 'an invalid inapplicable task list item', 'foo [~] bar' + + it 'does not wrap a sublist with <s>' do + html = '[~] foo <em>bar</em>\n<ol><li>sublist</li></ol>' + doc = filter("<ul><li>#{html}</li></ul>") + + expect(doc.to_html).to include('<s>foo <em>bar</em>\n</s>') + expect(doc.css('li.inapplicable input[data-inapplicable]').count).to eq(1) + expect(doc.css('li.inapplicable > s').count).to eq(1) + end + end end diff --git a/spec/lib/banzai/pipeline/incident_management/timeline_event_pipeline_spec.rb b/spec/lib/banzai/pipeline/incident_management/timeline_event_pipeline_spec.rb index 09d2919c6c4..4bccae04fda 100644 --- a/spec/lib/banzai/pipeline/incident_management/timeline_event_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/incident_management/timeline_event_pipeline_spec.rb @@ -10,9 +10,9 @@ RSpec.describe Banzai::Pipeline::IncidentManagement::TimelineEventPipeline do expect(described_class.filters).to eq( [ *Banzai::Pipeline::PlainMarkdownPipeline.filters, + Banzai::Filter::SanitizationFilter, *Banzai::Pipeline::GfmPipeline.reference_filters, Banzai::Filter::EmojiFilter, - Banzai::Filter::SanitizationFilter, Banzai::Filter::ExternalLinkFilter, Banzai::Filter::ImageLinkFilter ] @@ -62,7 +62,32 @@ RSpec.describe Banzai::Pipeline::IncidentManagement::TimelineEventPipeline do context 'when markdown contains emojis' do let(:markdown) { ':+1:👍' } - it { is_expected.to eq('<p>👍👍</p>') } + it 'renders emojis wrapped in <gl-emoji> tag' do + # rubocop:disable Layout/LineLength + is_expected.to eq( + %q(<p><gl-emoji title="thumbs up sign" data-name="thumbsup" data-unicode-version="6.0">👍</gl-emoji><gl-emoji title="thumbs up sign" data-name="thumbsup" data-unicode-version="6.0">👍</gl-emoji></p>) + ) + # rubocop:enable Layout/LineLength + end + end + + context 'when markdown contains labels' do + let(:label) { create(:label, project: project, title: 'backend') } + let(:markdown) { %Q(~"#{label.name}" ~unknown) } + + it 'replaces existing label to a link' do + # rubocop:disable Layout/LineLength + is_expected.to match( + %r(<p>.+<a href=\"[\w/]+-/issues\?label_name=#{label.name}\".+style=\"background-color: #\d{6}\".*>#{label.name}</span></a></span> ~unknown</p>) + ) + # rubocop:enable Layout/LineLength + end + end + + context 'when markdown contains table' do + let(:markdown) { '<table><tr><th>table head</th><tr><tr><td>table content</td></tr></table>' } + + it { is_expected.to eq('table headtable content') } end context 'when markdown contains a reference to an issue' do diff --git a/spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb b/spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb index 80392fe264f..536f2a67415 100644 --- a/spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb @@ -11,9 +11,9 @@ RSpec.describe Banzai::Pipeline::PlainMarkdownPipeline do it 'converts all reference punctuation to literals' do reference_chars = Banzai::Filter::MarkdownPreEscapeFilter::REFERENCE_CHARACTERS - markdown = reference_chars.split('').map {|char| char.prepend("\\") }.join + markdown = reference_chars.split('').map { |char| char.prepend("\\") }.join punctuation = Banzai::Filter::MarkdownPreEscapeFilter::REFERENCE_CHARACTERS.split('') - punctuation = punctuation.delete_if {|char| char == '&' } + punctuation = punctuation.delete_if { |char| char == '&' } punctuation << '&' result = described_class.call(markdown, project: project) diff --git a/spec/lib/banzai/renderer_spec.rb b/spec/lib/banzai/renderer_spec.rb index d487268da78..ae9cf4c5068 100644 --- a/spec/lib/banzai/renderer_spec.rb +++ b/spec/lib/banzai/renderer_spec.rb @@ -104,7 +104,7 @@ RSpec.describe Banzai::Renderer do describe '#post_process' do let(:context_options) { {} } - let(:html) { 'Consequatur aperiam et nesciunt modi aut assumenda quo id. '} + let(:html) { 'Consequatur aperiam et nesciunt modi aut assumenda quo id. ' } let(:post_processed_html) { double(html_safe: 'safe doc') } let(:doc) { double(to_html: post_processed_html) } |