File: audio_spec.rb

package info (click to toggle)
ruby-asciidoctor-pdf 2.3.19-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,972 kB
  • sloc: ruby: 44,316; sh: 133; java: 45; makefile: 4
file content (58 lines) | stat: -rw-r--r-- 2,006 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

require_relative 'spec_helper'

describe 'Asciidoctor::PDF::Converter - Audio' do
  it 'should replace audio block with right pointer, path to audio file, and audio label' do
    expected_lines = [
      'before',
      %(\u25ba\u00a0path/to/images/podcast.mp3 (audio)),
      'after',
    ]

    pdf = to_pdf <<~'EOS', attributes: { 'imagesdir' => 'path/to/images' }, analyze: true
    before

    audio::podcast.mp3[]

    after
    EOS

    (expect pdf.lines).to eql expected_lines
    before_text = (pdf.find_text 'before')[0]
    audio_text = (pdf.find_text %r/\(audio\)/)[0]
    after_text = (pdf.find_text 'after')[0]
    (expect ((before_text[:y] - audio_text[:y]).round 2)).to eql ((audio_text[:y] - after_text[:y]).round 2)
  end

  it 'should wrap text for audio if it exceeds width of content area' do
    pdf = to_pdf <<~'EOS', analyze: true, attribute_overrides: { 'imagesdir' => '' }
    audio::a-podcast-with-an-excessively-long-and-descriptive-name-as-they-sometimes-are-that-causes-the-text-to-wrap.mp3[]
    EOS

    (expect pdf.pages).to have_size 1
    lines = pdf.lines pdf.find_text page_number: 1
    (expect lines).to eql [%(\u25ba\u00a0a-podcast-with-an-excessively-long-and-descriptive-name-as-they-sometimes-are-that-causes-the-), 'text-to-wrap.mp3 (audio)']
  end

  it 'should use font-based icon for play symbol if font icons are enabled' do
    pdf = to_pdf <<~'EOS', attribute_overrides: { 'icons' => 'font' }, analyze: true
    audio::podcast.mp3[]
    EOS

    icon_text = (pdf.find_text ?\uf04b)[0]
    (expect icon_text).not_to be_nil
    (expect icon_text[:font_name]).to eql 'FontAwesome5Free-Solid'
  end

  it 'should show caption for audio if title is specified' do
    pdf = to_pdf <<~'EOS', attributes: { 'imagesdir' => '' }, analyze: true
    :icons: font

    .Episode 1 of my podcast
    audio::podcast-e1.mp3[]
    EOS

    (expect pdf.lines).to eql [%(\uf04b\u00a0podcast-e1.mp3 (audio)), 'Episode 1 of my podcast']
  end
end