Sha256: 41fd130d2f762d4e7995f34c9525023b0a7552407c5c518f9ef507579263cea3

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

# coding: utf-8

require 'test_helper'

class Thinreports::Core::Shape::PageNumber::TestInternal < Minitest::Test
  include Thinreports::TestHelper

  PageNumber = Thinreports::Core::Shape::PageNumber

  def setup
    @report = Thinreports::Report.new layout: layout_file.path
    @report.start_new_page
  end

  def init_pageno(format = {})
    PageNumber::Internal.new(@report.page, PageNumber::Format.new(format))
  end

  def test_read_format
    pageno = init_pageno('format' => 'Page {page}')

    assert_equal pageno.read_format, 'Page {page}'
  end

  def test_write_format
    pageno = init_pageno('format' => 'Page {page}')
    pageno.write_format('{page}')

    assert_equal pageno.read_format, '{page}'
  end

  def test_reset_format
    pageno = init_pageno('format' => '{page}')
    pageno.write_format('Page {page}')
    pageno.reset_format

    assert_equal pageno.read_format, '{page}'
  end

  def test_build_format
    pageno = init_pageno('format' => '{page} / {total}')
    assert_equal pageno.build_format(1, 100), '1 / 100'

    pageno.write_format('{page}')
    assert_equal pageno.build_format(1, 100), '1'

    @report.start_page_number_from 5
    pageno = init_pageno('format' => '{page} / {total}')
    assert_equal pageno.build_format(1, 100), '5 / 104'

    # if counted target is a List shape
    pageno = init_pageno('format' => '{page} / {total}',
                         'target' => 'list-id')
    assert_equal pageno.build_format(1, 100), '1 / 100'
  end

  def test_type_of
    pageno = init_pageno
    assert pageno.type_of?('page-number')
  end

  def test_style
    pageno = init_pageno
    style = pageno.style

    assert_instance_of PageNumber::Style, style
    assert_same pageno.style, style
  end

  def test_for_report
    pageno = init_pageno('target' => '')
    assert_equal pageno.for_report?, true

    pageno = init_pageno('target' => 'list-id')
    assert_equal pageno.for_report?, false
  end

  def test_Style_class
    refute_includes PageNumber::Style.accessible_styles, :valign
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thinreports-0.9.1 test/unit/core/shape/page_number/test_internal.rb
thinreports-0.9.0 test/unit/core/shape/page_number/test_internal.rb