Sha256: 2c72b7986a7fc95e5c7e789455913ae7e777bf42cdcd865a0eae1dc041f6a818

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

require 'test_helper'

class Thinreports::Core::Shape::TextBlock::Formatter::TestDatetime < Minitest::Test
  include Thinreports::TestHelper

  # Aliases
  TextBlock = Thinreports::Core::Shape::TextBlock
  Formatter = TextBlock::Formatter::Datetime

  def setup
    @datetime_format = '%Y/%m/%d %H:%M:%S'
    @time = Time.now
  end

  def text_block_format(format = {})
    default = {'base' => '', 'datetime' => {'format' => '%Y/%m/%d %H:%M:%S'}}
    TextBlock::Format.new('format' => default.merge(format))
  end

  def test_apply_datetime_format_without_basic_format
    formatter = Formatter.new(text_block_format)

    assert_equal @time.strftime(@datetime_format),
                 formatter.apply(@time)
  end

  def test_apply_datetime_format_with_basic_format
    formatter = Formatter.new(text_block_format('base' => 'Now: {value}'))

    assert_equal "Now: #{@time.strftime(@datetime_format)}",
                 formatter.apply(@time)

  end

  def test_not_apply_datetime_format_and_return_raw_value
    # When value is invalid
    formatter = Formatter.new(text_block_format)

    assert_same formatter.apply(val = 'invalid value'), val
    assert_same formatter.apply(val = 123456), val

    # When format is empty
    formatter = Formatter.new(text_block_format('datetime' => {'format' => ''}))

    assert_same formatter.apply(@time), @time
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
thinreports-0.10.3 test/units/core/shape/text_block/formatter/test_datetime.rb
thinreports-0.10.2 test/unit/core/shape/text_block/formatter/test_datetime.rb
thinreports-0.10.1 test/unit/core/shape/text_block/formatter/test_datetime.rb
thinreports-0.10.0 test/unit/core/shape/text_block/formatter/test_datetime.rb