Sha256: 10d2905e5a492f1267dc4461c5e8ff3e6a68bde0cc0734a7106047cd1d3251e4

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'

describe Kitabu::Footnotes::HTML do
  let(:footnotes) {
    Kitabu::Markdown.render <<-MARKDOWN.strip_heredoc
      ohai[^1] and kthxbai[^2]

      ohai[^1] again.

      [^1]: Hello
      [^2]: OK, thanks. Bye!
    MARKDOWN
  }

  let(:content) {
    <<-HTML.strip_heredoc
      <div class="chapter">
        #{footnotes}
      </div>

      <div class="chapter">
        #{footnotes}
      </div>
    HTML
  }

  let(:html) {
    Kitabu::Footnotes::HTML.process(content).html
  }

  let(:chapter1) { html.css('.chapter:first-of-type').first }
  let(:chapter2) { html.css('.chapter:last-of-type').first }

  it 'sets starting index' do
    expect(chapter1).to have_tag('.footnotes ol[start="1"]')
    expect(chapter2).to have_tag('.footnotes ol[start="3"]')
  end

  it 'sets footnotes id' do
    html.css('.footnotes li').to_enum(:each).with_index(1) do |footnote, index|
      expect(footnote.get_attribute('id')).to eq("fn#{index}")
    end
  end

  it 'removes id from existing <sup>' do
    expect(chapter1).to have_tag('sup:not([id])', count: 1)
    expect(chapter2).to have_tag('sup:not([id])', count: 1)
  end

  it 'sets <sup> id' do
    expect(chapter1).to have_tag('sup', count: 3)
    expect(chapter1).to have_tag('sup[id=fnref1]', count: 1)
    expect(chapter1).to have_tag('sup[id=fnref2]', count: 1)

    expect(chapter2).to have_tag('sup', count: 3)
    expect(chapter2).to have_tag('sup[id=fnref3]', count: 1)
    expect(chapter2).to have_tag('sup[id=fnref4]', count: 1)
  end

  it 'sets footnote link-back' do
    expect(chapter1).to have_tag('.footnotes li:nth-child(1) a[rev=footnote][href="#fnref1"]')
    expect(chapter1).to have_tag('.footnotes li:nth-child(2) a[rev=footnote][href="#fnref2"]')

    expect(chapter2).to have_tag('.footnotes li:nth-child(1) a[rev=footnote][href="#fnref3"]')
    expect(chapter2).to have_tag('.footnotes li:nth-child(2) a[rev=footnote][href="#fnref4"]')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kitabu-2.0.2 spec/kitabu/footnotes/html_spec.rb
kitabu-2.0.1 spec/kitabu/footnotes/html_spec.rb