Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Walker <bwalker@gitlab.com>2019-01-17 06:13:44 +0300
committerBrett Walker <bwalker@gitlab.com>2019-01-17 18:33:18 +0300
commit7e900ed8569aff9fc549e95b6271c3d578acbd51 (patch)
tree981b3f58a4820628a0a4b2cd6f3c80bc67ad6b7b /spec/lib/banzai
parentcc036417278111efc7e8e686339ab0191a324364 (diff)
Refactoring and addressing review comments
and additional spec
Diffstat (limited to 'spec/lib/banzai')
-rw-r--r--spec/lib/banzai/filter/footnote_filter_spec.rb52
-rw-r--r--spec/lib/banzai/filter/sanitization_filter_spec.rb8
-rw-r--r--spec/lib/banzai/pipeline/full_pipeline_spec.rb32
3 files changed, 62 insertions, 30 deletions
diff --git a/spec/lib/banzai/filter/footnote_filter_spec.rb b/spec/lib/banzai/filter/footnote_filter_spec.rb
index 0b7807b2c4c..2e50e4e2351 100644
--- a/spec/lib/banzai/filter/footnote_filter_spec.rb
+++ b/spec/lib/banzai/filter/footnote_filter_spec.rb
@@ -9,16 +9,30 @@ describe Banzai::Filter::FootnoteFilter do
# [^1]: one
# [^second]: two
let(:footnote) do
- <<-EOF.strip_heredoc
- <p>first<sup><a href="#fn1" id="fnref1">1</a></sup> and second<sup><a href="#fn2" id="fnref2">2</a></sup></p>
- <ol>
- <li id="fn1">
- <p>one <a href="#fnref1">↩</a></p>
- </li>
- <li id="fn2">
- <p>two <a href="#fnref2">↩</a></p>
- </li>
- </ol>
+ <<~EOF
+ <p>first<sup><a href="#fn1" id="fnref1">1</a></sup> and second<sup><a href="#fn2" id="fnref2">2</a></sup></p>
+ <ol>
+ <li id="fn1">
+ <p>one <a href="#fnref1">↩</a></p>
+ </li>
+ <li id="fn2">
+ <p>two <a href="#fnref2">↩</a></p>
+ </li>
+ </ol>
+ EOF
+ end
+
+ let(:filtered_footnote) do
+ <<~EOF
+ <p>first<sup class="footnote-ref"><a href="#fn1-#{identifier}" id="fnref1-#{identifier}">1</a></sup> and second<sup class="footnote-ref"><a href="#fn2-#{identifier}" id="fnref2-#{identifier}">2</a></sup></p>
+ <section class="footnotes"><ol>
+ <li id="fn1-#{identifier}">
+ <p>one <a href="#fnref1-#{identifier}" class="footnote-backref">↩</a></p>
+ </li>
+ <li id="fn2-#{identifier}">
+ <p>two <a href="#fnref2-#{identifier}" class="footnote-backref">↩</a></p>
+ </li>
+ </ol></section>
EOF
end
@@ -27,22 +41,8 @@ describe Banzai::Filter::FootnoteFilter do
let(:link_node) { doc.css('sup > a').first }
let(:identifier) { link_node[:id].delete_prefix('fnref1-') }
- it 'adds identifier to footnotes' do
- expect(link_node[:id]).to eq "fnref1-#{identifier}"
- expect(link_node[:href]).to eq "#fn1-#{identifier}"
- expect(doc.css("li[id=fn1-#{identifier}]")).not_to be_empty
- expect(doc.css("li[id=fn1-#{identifier}] a[href=\"#fnref1-#{identifier}\"]")).not_to be_empty
- end
-
- it 'uses the same identifier for all footnotes' do
- expect(doc.css("li[id=fn2-#{identifier}]")).not_to be_empty
- expect(doc.css("li[id=fn2-#{identifier}] a[href=\"#fnref2-#{identifier}\"]")).not_to be_empty
- end
-
- it 'adds section and classes' do
- expect(doc.css("section[class=footnotes]")).not_to be_empty
- expect(doc.css("sup[class=footnote-ref]").count).to eq 2
- expect(doc.css("a[class=footnote-backref]").count).to eq 2
+ it 'properly adds the necessary ids and classes' do
+ expect(doc.to_html).to eq filtered_footnote
end
end
end
diff --git a/spec/lib/banzai/filter/sanitization_filter_spec.rb b/spec/lib/banzai/filter/sanitization_filter_spec.rb
index 0f9011cb655..836af18e0b6 100644
--- a/spec/lib/banzai/filter/sanitization_filter_spec.rb
+++ b/spec/lib/banzai/filter/sanitization_filter_spec.rb
@@ -302,21 +302,21 @@ describe Banzai::Filter::SanitizationFilter do
end
describe 'footnotes' do
- it 'allows id property on links' do
+ it 'allows correct footnote id property on links' do
exp = %q{<a href="#fn1" id="fnref1">foo/bar.md</a>}
act = filter(exp)
expect(act.to_html).to eq exp
end
- it 'allows id property on li element' do
+ it 'allows correct footnote id property on li element' do
exp = %q{<ol><li id="fn1">footnote</li></ol>}
act = filter(exp)
expect(act.to_html).to eq exp
end
- it 'only allows valid footnote formats for links' do
+ it 'removes invalid id for footnote links' do
exp = %q{<a href="#fn1">link</a>}
%w[fnrefx test xfnref1].each do |id|
@@ -326,7 +326,7 @@ describe Banzai::Filter::SanitizationFilter do
end
end
- it 'only allows valid footnote formats for li' do
+ it 'removes invalid id for footnote li' do
exp = %q{<ol><li>footnote</li></ol>}
%w[fnx test xfn1].each do |id|
diff --git a/spec/lib/banzai/pipeline/full_pipeline_spec.rb b/spec/lib/banzai/pipeline/full_pipeline_spec.rb
index e9c7a2f352e..3634655c6a5 100644
--- a/spec/lib/banzai/pipeline/full_pipeline_spec.rb
+++ b/spec/lib/banzai/pipeline/full_pipeline_spec.rb
@@ -25,4 +25,36 @@ describe Banzai::Pipeline::FullPipeline do
expect(result).to include(%{data-original='\"&gt;bad things'})
end
end
+
+ describe 'footnotes' do
+ let(:project) { create(:project, :public) }
+ let(:html) { described_class.to_html(footnote_markdown, project: project) }
+ let(:identifier) { html[/.*fnref1-(\d+).*/, 1] }
+ let(:footnote_markdown) do
+ <<~EOF
+ first[^1] and second[^second]
+ [^1]: one
+ [^second]: two
+ EOF
+ end
+
+ let(:filtered_footnote) do
+ <<~EOF
+ <p dir="auto">first<sup class="footnote-ref"><a href="#fn1-#{identifier}" id="fnref1-#{identifier}">1</a></sup> and second<sup class="footnote-ref"><a href="#fn2-#{identifier}" id="fnref2-#{identifier}">2</a></sup></p>
+
+ <section class="footnotes"><ol>
+ <li id="fn1-#{identifier}">
+ <p>one <a href="#fnref1-#{identifier}" class="footnote-backref"><gl-emoji title="leftwards arrow with hook" data-name="leftwards_arrow_with_hook" data-unicode-version="1.1">↩</gl-emoji></a></p>
+ </li>
+ <li id="fn2-#{identifier}">
+ <p>two <a href="#fnref2-#{identifier}" class="footnote-backref"><gl-emoji title="leftwards arrow with hook" data-name="leftwards_arrow_with_hook" data-unicode-version="1.1">↩</gl-emoji></a></p>
+ </li>
+ </ol></section>
+ EOF
+ end
+
+ it 'properly adds the necessary ids and classes' do
+ expect(html.lines.map(&:strip).join("\n")).to eq filtered_footnote
+ end
+ end
end