thinreports 0.10.3 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +39 -0
- data/CHANGELOG.md +20 -0
- data/Dockerfile +12 -0
- data/Gemfile +5 -0
- data/README.md +37 -13
- data/Rakefile +1 -0
- data/lib/thinreports/core/shape/image_block.rb +1 -1
- data/lib/thinreports/core/shape/list.rb +1 -1
- data/lib/thinreports/core/shape/page_number.rb +1 -1
- data/lib/thinreports/core/shape/text.rb +1 -1
- data/lib/thinreports/core/shape/text_block.rb +1 -1
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +6 -1
- data/lib/thinreports/core/shape/text_block/internal.rb +0 -2
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +6 -0
- data/lib/thinreports/layout/base.rb +1 -1
- data/lib/thinreports/layout/version.rb +1 -1
- data/lib/thinreports/report/internal.rb +2 -0
- data/lib/thinreports/version.rb +1 -1
- data/thinreports.gemspec +5 -9
- metadata +6 -204
- data/.travis.yml +0 -32
- data/test/data/font.ttf +0 -0
- data/test/data/image_normal.jpg +0 -0
- data/test/data/image_normal.png +0 -0
- data/test/data/image_normal_jpg_noext +0 -0
- data/test/data/image_normal_png_noext +0 -0
- data/test/data/image_pallete_based.png +0 -0
- data/test/data/legacy_layout/all-items.tlf +0 -1
- data/test/features/dynamic_style/expect.pdf +0 -3714
- data/test/features/dynamic_style/image.png +0 -0
- data/test/features/dynamic_style/templates/styles.tlf +0 -1835
- data/test/features/dynamic_style/templates/styles_in_list.tlf +0 -344
- data/test/features/dynamic_style/test_dynamic_style.rb +0 -152
- data/test/features/eudc/eudc.ttf +0 -0
- data/test/features/eudc/expect.pdf +0 -0
- data/test/features/eudc/template.tlf +0 -180
- data/test/features/eudc/test_eudc.rb +0 -27
- data/test/features/feature_test.rb +0 -58
- data/test/features/graphics/expect.pdf +0 -475
- data/test/features/graphics/template.tlf +0 -309
- data/test/features/graphics/test_graphics.rb +0 -12
- data/test/features/hidden_item/expect.pdf +0 -0
- data/test/features/hidden_item/template.tlf +0 -449
- data/test/features/hidden_item/test_hidden_item.rb +0 -12
- data/test/features/image_block/expect.pdf +0 -0
- data/test/features/image_block/img200x100.png +0 -0
- data/test/features/image_block/img50x50.png +0 -0
- data/test/features/image_block/template.tlf +0 -661
- data/test/features/image_block/test_image_block.rb +0 -35
- data/test/features/list_events/expect.pdf +0 -659
- data/test/features/list_events/template.tlf +0 -361
- data/test/features/list_events/test_list_events.rb +0 -36
- data/test/features/list_manually/expect.pdf +0 -599
- data/test/features/list_manually/template.tlf +0 -132
- data/test/features/list_manually/test_list_manually.rb +0 -25
- data/test/features/page_number/expect.pdf +0 -400
- data/test/features/page_number/template.tlf +0 -215
- data/test/features/page_number/test_page_number.rb +0 -24
- data/test/features/page_number_with_list/expect.pdf +0 -721
- data/test/features/page_number_with_list/template.tlf +0 -254
- data/test/features/page_number_with_list/test_page_number_with_list.rb +0 -21
- data/test/features/palleted_png/expect.pdf +0 -0
- data/test/features/palleted_png/palleted_png.png +0 -0
- data/test/features/palleted_png/template.tlf +0 -47
- data/test/features/palleted_png/test_palleted_png.rb +0 -14
- data/test/features/report_callbacks/expect.pdf +0 -169
- data/test/features/report_callbacks/template.tlf +0 -147
- data/test/features/report_callbacks/test_report_callbacks.rb +0 -18
- data/test/features/text_align/expect.pdf +0 -0
- data/test/features/text_align/template.tlf +0 -241
- data/test/features/text_align/test_text_align.rb +0 -12
- data/test/features/text_block_overflow/expect.pdf +0 -0
- data/test/features/text_block_overflow/template.tlf +0 -538
- data/test/features/text_block_overflow/test_text_block_overflow.rb +0 -25
- data/test/features/text_block_singleline/expect.pdf +0 -0
- data/test/features/text_block_singleline/template.tlf +0 -170
- data/test/features/text_block_singleline/test_text_block_singleline.rb +0 -15
- data/test/features/text_block_style/expect.pdf +0 -1391
- data/test/features/text_block_style/templates/basic_styles.tlf +0 -889
- data/test/features/text_block_style/templates/font_size.tlf +0 -383
- data/test/features/text_block_style/test_text_block_style.rb +0 -47
- data/test/features/text_character_spacing/expect.pdf +0 -0
- data/test/features/text_character_spacing/template.tlf +0 -293
- data/test/features/text_character_spacing/test_text_character_spacing.rb +0 -12
- data/test/features/text_word_wrap/expect.pdf +0 -0
- data/test/features/text_word_wrap/template.tlf +0 -297
- data/test/features/text_word_wrap/test_text_word_wrap.rb +0 -30
- data/test/schema_helper.rb +0 -122
- data/test/test_helper.rb +0 -39
- data/test/units/core/format/test_base.rb +0 -152
- data/test/units/core/shape/base/test_internal.rb +0 -87
- data/test/units/core/shape/basic/test_block_format.rb +0 -23
- data/test/units/core/shape/basic/test_block_interface.rb +0 -29
- data/test/units/core/shape/basic/test_block_internal.rb +0 -55
- data/test/units/core/shape/basic/test_format.rb +0 -37
- data/test/units/core/shape/basic/test_interface.rb +0 -108
- data/test/units/core/shape/basic/test_internal.rb +0 -55
- data/test/units/core/shape/image_block/test_interface.rb +0 -24
- data/test/units/core/shape/image_block/test_internal.rb +0 -31
- data/test/units/core/shape/list/test_format.rb +0 -111
- data/test/units/core/shape/list/test_manager.rb +0 -67
- data/test/units/core/shape/list/test_page.rb +0 -156
- data/test/units/core/shape/list/test_page_state.rb +0 -31
- data/test/units/core/shape/list/test_section_format.rb +0 -36
- data/test/units/core/shape/list/test_section_interface.rb +0 -75
- data/test/units/core/shape/list/test_section_internal.rb +0 -50
- data/test/units/core/shape/manager/test_format.rb +0 -38
- data/test/units/core/shape/manager/test_internal.rb +0 -132
- data/test/units/core/shape/manager/test_target.rb +0 -140
- data/test/units/core/shape/page_number/test_format.rb +0 -55
- data/test/units/core/shape/page_number/test_interface.rb +0 -33
- data/test/units/core/shape/page_number/test_internal.rb +0 -81
- data/test/units/core/shape/styles/test_base.rb +0 -191
- data/test/units/core/shape/styles/test_basic.rb +0 -24
- data/test/units/core/shape/styles/test_graphic.rb +0 -50
- data/test/units/core/shape/styles/test_text.rb +0 -97
- data/test/units/core/shape/text/test_format.rb +0 -44
- data/test/units/core/shape/text/test_internal.rb +0 -20
- data/test/units/core/shape/text_block/formatter/test_basic.rb +0 -24
- data/test/units/core/shape/text_block/formatter/test_datetime.rb +0 -49
- data/test/units/core/shape/text_block/formatter/test_number.rb +0 -76
- data/test/units/core/shape/text_block/formatter/test_padding.rb +0 -77
- data/test/units/core/shape/text_block/test_format.rb +0 -169
- data/test/units/core/shape/text_block/test_formatter.rb +0 -28
- data/test/units/core/shape/text_block/test_interface.rb +0 -63
- data/test/units/core/shape/text_block/test_internal.rb +0 -128
- data/test/units/core/test_shape.rb +0 -52
- data/test/units/core/test_utils.rb +0 -68
- data/test/units/generator/pdf/document/graphics/test_attributes.rb +0 -135
- data/test/units/generator/pdf/document/graphics/test_basic.rb +0 -46
- data/test/units/generator/pdf/document/graphics/test_image.rb +0 -46
- data/test/units/generator/pdf/document/graphics/test_text.rb +0 -171
- data/test/units/generator/pdf/document/test_font.rb +0 -110
- data/test/units/generator/pdf/document/test_graphics.rb +0 -42
- data/test/units/generator/pdf/document/test_page.rb +0 -122
- data/test/units/generator/pdf/document/test_parse_color.rb +0 -30
- data/test/units/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +0 -41
- data/test/units/generator/pdf/prawn_ext/test_width_of.rb +0 -22
- data/test/units/generator/pdf/test_document.rb +0 -22
- data/test/units/generator/test_pdf.rb +0 -26
- data/test/units/layout/test_base.rb +0 -41
- data/test/units/layout/test_format.rb +0 -100
- data/test/units/layout/test_legacy_schema.rb +0 -576
- data/test/units/layout/test_version.rb +0 -26
- data/test/units/report/test_base.rb +0 -248
- data/test/units/report/test_internal.rb +0 -206
- data/test/units/test_config.rb +0 -36
- data/test/units/test_layout.rb +0 -12
- data/test/units/test_report.rb +0 -18
data/test/test_helper.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
require 'minitest/spec'
|
5
|
-
require 'minitest/unit'
|
6
|
-
require 'mocha/minitest'
|
7
|
-
require 'pdf/inspector'
|
8
|
-
|
9
|
-
require 'digest/sha1'
|
10
|
-
require 'pathname'
|
11
|
-
require 'thinreports'
|
12
|
-
|
13
|
-
require 'schema_helper'
|
14
|
-
|
15
|
-
module Thinreports::TestHelper
|
16
|
-
ROOT = Pathname.new(File.expand_path('..', __FILE__))
|
17
|
-
|
18
|
-
include Thinreports::SchemaHelper
|
19
|
-
|
20
|
-
def assert_deprecated(&block)
|
21
|
-
_out, err = capture_io { block.call }
|
22
|
-
assert err.to_s.include?('[DEPRECATION]')
|
23
|
-
end
|
24
|
-
|
25
|
-
def data_file(*paths)
|
26
|
-
ROOT.join('data', *paths).to_s
|
27
|
-
end
|
28
|
-
|
29
|
-
def read_data_file(*paths)
|
30
|
-
File.read(data_file(*paths))
|
31
|
-
end
|
32
|
-
|
33
|
-
def analyze_pdf_images(pdf_data)
|
34
|
-
analyzer = PDF::Inspector::XObject.analyze(pdf_data)
|
35
|
-
analyzer.page_xobjects
|
36
|
-
.reduce(:merge).values
|
37
|
-
.select { |o| o.hash[:Subtype] == :Image }
|
38
|
-
end
|
39
|
-
end
|
@@ -1,152 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Format::BaseTest < Minitest::Test
|
6
|
-
TEST_FORMAT_CONFIG = {
|
7
|
-
'c1' => 'c1',
|
8
|
-
'c2' => {
|
9
|
-
'c2_1' => 'c2_1'
|
10
|
-
},
|
11
|
-
'c3' => {
|
12
|
-
'c3_1' => {
|
13
|
-
'c3_1_1' => 'c3_1_1',
|
14
|
-
'c3_1_2' => 'c3_1_2'
|
15
|
-
}
|
16
|
-
},
|
17
|
-
'c4' => 'c4',
|
18
|
-
'c5' => 'c5',
|
19
|
-
'c6' => 9999,
|
20
|
-
'c7' => true,
|
21
|
-
'c8' => false,
|
22
|
-
'c9' => {
|
23
|
-
'c9_1' => true,
|
24
|
-
'c9_2' => false
|
25
|
-
},
|
26
|
-
'c10' => 'c10',
|
27
|
-
'c11' => {
|
28
|
-
'c11_1' => 'c11_1'
|
29
|
-
},
|
30
|
-
'c20' => 'c20',
|
31
|
-
'c21' => 'c21'
|
32
|
-
}
|
33
|
-
|
34
|
-
class TestFormat < Thinreports::Core::Format::Base
|
35
|
-
# For testing
|
36
|
-
attr_reader :config
|
37
|
-
|
38
|
-
# Basic methods
|
39
|
-
config_reader :c1
|
40
|
-
config_reader c2_1: %w( c2 c2_1 ),
|
41
|
-
c3_1_1: %w( c3 c3_1 c3_1_1 )
|
42
|
-
config_reader :c4, :c5
|
43
|
-
config_reader 'c6'
|
44
|
-
|
45
|
-
# Alias methods
|
46
|
-
config_reader c1_alias: %w( c1 ),
|
47
|
-
c2_1_alias: %w( c2 c2_1 )
|
48
|
-
|
49
|
-
# Invalid methods
|
50
|
-
config_reader c3_invalid: %w( c3 c3_1 not_exist_key )
|
51
|
-
|
52
|
-
# Customized methods
|
53
|
-
config_reader c2_1_customized: %w( c2 c2_1 ) do |val|
|
54
|
-
"Customized #{val}"
|
55
|
-
end
|
56
|
-
|
57
|
-
# Checker methods
|
58
|
-
config_checker true, :c7, :c8
|
59
|
-
config_checker true, c9_1: %w( c9 c9_1 ),
|
60
|
-
c9_2: %w( c9 c9_2 )
|
61
|
-
|
62
|
-
# Writer methods
|
63
|
-
config_writer :c10
|
64
|
-
config_writer c10_alias: %w( c10 )
|
65
|
-
config_writer c11_1: %w( c11 c11_1 )
|
66
|
-
# Writer for not exist config on default
|
67
|
-
config_writer c11_2: %w( c11 c11_2 )
|
68
|
-
|
69
|
-
# Accessor methods
|
70
|
-
config_accessor :c20
|
71
|
-
config_accessor :c21 do |val|
|
72
|
-
"Customized #{val}"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def setup
|
77
|
-
@format = TestFormat.new(TEST_FORMAT_CONFIG)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_definition_of_all_config_methods
|
81
|
-
methods = [:c1, :c2_1, :c3_1_1, :c4, :c5, :c6,
|
82
|
-
:c1_alias, :c2_1_alias,
|
83
|
-
:c3_invalid,
|
84
|
-
:c2_1_customized,
|
85
|
-
:c7?, :c8?, :c9_1?, :c9_2?,
|
86
|
-
:c10=, :c10_alias=, :c11_1=, :c11_2=,
|
87
|
-
:c20, :c20=, :c21, :c21=]
|
88
|
-
assert methods.all? {|m| TestFormat.method_defined?(m) }
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_readers
|
92
|
-
# Basic
|
93
|
-
assert_equal @format.c1, 'c1'
|
94
|
-
assert_equal @format.c2_1, 'c2_1'
|
95
|
-
assert_equal @format.c3_1_1, 'c3_1_1'
|
96
|
-
assert_equal @format.c4, 'c4'
|
97
|
-
assert_equal @format.c5, 'c5'
|
98
|
-
assert_equal @format.c6, 9999
|
99
|
-
# Alias
|
100
|
-
assert_equal @format.c1_alias, @format.c1
|
101
|
-
assert_equal @format.c2_1_alias, @format.c2_1
|
102
|
-
# Invalid location
|
103
|
-
assert_nil @format.c3_invalid
|
104
|
-
# Customized
|
105
|
-
assert_equal @format.c2_1_customized, 'Customized c2_1'
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_checkers
|
109
|
-
assert_equal @format.c7?, true
|
110
|
-
assert_equal @format.c8?, false
|
111
|
-
assert_equal @format.c9_1?, true
|
112
|
-
assert_equal @format.c9_2?, false
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_reader_cannot_write_value
|
116
|
-
assert_raises NoMethodError do
|
117
|
-
@format.c1 = 'write'
|
118
|
-
end
|
119
|
-
# Alias method
|
120
|
-
assert_raises NoMethodError do
|
121
|
-
@format.c1_alias = 'write'
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_writers
|
126
|
-
config = @format.config
|
127
|
-
|
128
|
-
@format.c10 = 'c1_changed'
|
129
|
-
assert_equal config['c10'], 'c1_changed'
|
130
|
-
|
131
|
-
@format.c10_alias = 'c10_changed_by_alias'
|
132
|
-
assert_equal config['c10'], 'c10_changed_by_alias'
|
133
|
-
|
134
|
-
@format.c11_1 = 'c11_1_changed'
|
135
|
-
assert_equal config['c11']['c11_1'], 'c11_1_changed'
|
136
|
-
|
137
|
-
@format.c11_2 = 'c11_2_created'
|
138
|
-
assert_equal config['c11']['c11_2'], 'c11_2_created'
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_accessors
|
142
|
-
@format.c20 = 'c20_changed'
|
143
|
-
assert_equal @format.c20, 'c20_changed'
|
144
|
-
|
145
|
-
@format.c21 = 'c21_changed'
|
146
|
-
assert_equal @format.c21, 'Customized c21_changed'
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_attributes
|
150
|
-
assert_same @format.config, @format.attributes
|
151
|
-
end
|
152
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::Base::TestInternal < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
def setup
|
9
|
-
@report = Thinreports::Report.new layout: layout_file.path
|
10
|
-
@report.start_new_page
|
11
|
-
end
|
12
|
-
|
13
|
-
def create_internal(format_config = {}, &block)
|
14
|
-
format =
|
15
|
-
unless format_config.empty?
|
16
|
-
format_klass = Class.new(Thinreports::Core::Shape::Basic::Format) {
|
17
|
-
config_reader(*format_config.keys.map {|k| k.to_sym })
|
18
|
-
}
|
19
|
-
format_klass.new(format_config)
|
20
|
-
else
|
21
|
-
Thinreports::Core::Shape::Basic::Format.new({})
|
22
|
-
end
|
23
|
-
|
24
|
-
klass = Class.new(Thinreports::Core::Shape::Base::Internal, &block)
|
25
|
-
klass.new(@report.page, format)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_self_format_delegators_should_defines_method_delegated_from_format
|
29
|
-
internal = create_internal('m1' => 'm1_value') {
|
30
|
-
format_delegators :m1
|
31
|
-
}
|
32
|
-
assert_respond_to internal, :m1
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_method_delegated_from_format_should_return_same_value_as_an_format
|
36
|
-
internal = create_internal('m1' => 'm1 value') {
|
37
|
-
format_delegators :m1
|
38
|
-
}
|
39
|
-
assert_same internal.m1, internal.format.m1
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_copied_internal_should_have_the_new_value_specified_as_a_parent_property
|
43
|
-
new_page = @report.start_new_page
|
44
|
-
internal = create_internal {
|
45
|
-
def style
|
46
|
-
@style ||= Thinreports::Core::Shape::Style::Base.new(format)
|
47
|
-
end
|
48
|
-
}
|
49
|
-
|
50
|
-
assert_same internal.copy(new_page).parent, new_page
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_copied_internal_should_have_style_copied_from_original
|
54
|
-
internal = create_internal {
|
55
|
-
def style
|
56
|
-
@style ||= Thinreports::Core::Shape::Style::Base.new(format)
|
57
|
-
end
|
58
|
-
}
|
59
|
-
internal.style.write_internal_style(:foo, 'bar')
|
60
|
-
new_internal = internal.copy(@report.start_new_page)
|
61
|
-
|
62
|
-
assert_equal new_internal.style.read_internal_style(:foo), 'bar'
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_copied_internal_should_have_states_property_copied_from_original
|
66
|
-
internal = create_internal {
|
67
|
-
def style
|
68
|
-
@style ||= Thinreports::Core::Shape::Style::Base.new(format)
|
69
|
-
end
|
70
|
-
}
|
71
|
-
internal.states[:foo] = 'bar'
|
72
|
-
new_internal = internal.copy(@report.start_new_page)
|
73
|
-
|
74
|
-
assert_equal new_internal.states[:foo], 'bar'
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_copy_should_execute_block_with_new_internal_as_argument
|
78
|
-
internal = create_internal {
|
79
|
-
def style
|
80
|
-
@style ||= Thinreports::Core::Shape::Style::Base.new(format)
|
81
|
-
end
|
82
|
-
}
|
83
|
-
internal.copy(@report.start_new_page) do |new_internal|
|
84
|
-
assert_equal new_internal.is_a?(Thinreports::Core::Shape::Base::Internal), true
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::Basic::TestBlockFormat < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
BLOCK_FORMAT = {
|
9
|
-
'value' => 'default value',
|
10
|
-
'x' => 100.0,
|
11
|
-
'y' => 200.0,
|
12
|
-
'width' => 300.0,
|
13
|
-
'height' => 400.0
|
14
|
-
}
|
15
|
-
|
16
|
-
Basic = Thinreports::Core::Shape::Basic
|
17
|
-
|
18
|
-
def test_attribute_readers
|
19
|
-
format = Basic::BlockFormat.new(BLOCK_FORMAT)
|
20
|
-
|
21
|
-
assert_equal 'default value', format.value
|
22
|
-
end
|
23
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::Basic::TestBlockInterface < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
Basic = Thinreports::Core::Shape::Basic
|
9
|
-
|
10
|
-
def setup
|
11
|
-
report = Thinreports::Report.new layout: layout_file.path
|
12
|
-
parent = report.start_new_page
|
13
|
-
|
14
|
-
format = Basic::BlockFormat.new({})
|
15
|
-
internal = Basic::BlockInternal.new parent, format
|
16
|
-
|
17
|
-
@interface = Basic::BlockInterface.new parent, format, internal
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_value_should_work_as_reader_with_no_arguments
|
21
|
-
@interface.internal.write_value('new value')
|
22
|
-
assert_equal @interface.value, 'new value'
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_value_should_work_as_writer_with_arguments
|
26
|
-
@interface.value('new value')
|
27
|
-
assert_equal @interface.internal.read_value, 'new value'
|
28
|
-
end
|
29
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::Basic::TestBlockInternal < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
Basic = Thinreports::Core::Shape::Basic
|
9
|
-
|
10
|
-
def test_read_value_should_return_value_from_format
|
11
|
-
internal = init_internal('value' => 'default value')
|
12
|
-
assert_equal internal.read_value, 'default value'
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_read_value_should_return_value_from_state_with_value_key
|
16
|
-
internal = init_internal
|
17
|
-
internal.states[:value] = 'new value'
|
18
|
-
assert_equal internal.read_value, 'new value'
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_real_value_should_return_the_same_value_as_a_read_value_method
|
22
|
-
internal = init_internal
|
23
|
-
internal.states[:value] = 'foo'
|
24
|
-
assert_same internal.real_value, internal.read_value
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_write_value_should_save_value_to_states_store_as_value
|
28
|
-
internal = init_internal
|
29
|
-
internal.write_value('new value')
|
30
|
-
assert_equal internal.states[:value], 'new value'
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_type_of_asker_should_return_true_when_given_the_block_value
|
34
|
-
assert_equal init_internal.type_of?(:block), true
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_value_should_works_the_same_as_read_value_method
|
38
|
-
internal = init_internal
|
39
|
-
internal.write_value('new value')
|
40
|
-
assert_same internal.read_value, internal.value
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_type_of_asker_should_return_false_otherwise
|
44
|
-
assert_equal %w( image-block text-block text list ).all? {|t| !init_internal.type_of?(t)}, true
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def init_internal(format = {})
|
50
|
-
report = Thinreports::Report.new layout: layout_file.path
|
51
|
-
parent = report.start_new_page
|
52
|
-
|
53
|
-
Basic::BlockInternal.new(parent, Basic::BlockFormat.new(format))
|
54
|
-
end
|
55
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::Basic::TestFormat < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
RECT_FORMAT = {
|
9
|
-
"id" => "",
|
10
|
-
"type" => "rect",
|
11
|
-
"x" => 100.0,
|
12
|
-
"y" => 200.0,
|
13
|
-
"width" => 300.0,
|
14
|
-
"height" => 400.0,
|
15
|
-
"description" => "Description for rect",
|
16
|
-
"display" => true,
|
17
|
-
"rx" => 1.0,
|
18
|
-
"ry" => 1.0,
|
19
|
-
"style" => {
|
20
|
-
"border-width" => 1,
|
21
|
-
"border-color" => "#000000",
|
22
|
-
"border-style" => "dashed",
|
23
|
-
"fill-color" => "#ff0000"
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
Basic = Thinreports::Core::Shape::Basic
|
28
|
-
|
29
|
-
def test_attribute_readers
|
30
|
-
format = Basic::Format.new(RECT_FORMAT)
|
31
|
-
|
32
|
-
assert_equal '', format.id
|
33
|
-
assert_equal 'rect', format.type
|
34
|
-
assert_equal RECT_FORMAT['style'], format.style
|
35
|
-
assert_equal true, format.display?
|
36
|
-
end
|
37
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::Basic::TestInterface < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
# Alias
|
9
|
-
Basic = Thinreports::Core::Shape::Basic
|
10
|
-
|
11
|
-
def create_interface(format_config = {})
|
12
|
-
report = Thinreports::Report.new layout: layout_file.path
|
13
|
-
parent = report.start_new_page
|
14
|
-
|
15
|
-
Basic::Interface.new parent, Basic::Format.new(format_config)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_id_should_return_id_with_reference_to_internal
|
19
|
-
basic = create_interface('id' => 'foo')
|
20
|
-
assert_equal basic.id, basic.internal.id
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_id_should_return_cloned_id
|
24
|
-
basic = create_interface('id' => 'basic-id')
|
25
|
-
refute_same basic.id, basic.internal.id
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_type_should_operate_as_delegator_of_internal
|
29
|
-
basic = create_interface('type' => 'rect')
|
30
|
-
assert_same basic.type, basic.internal.type
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_visible_asker_should_return_result_with_reference_to_style_of_internal
|
34
|
-
basic = create_interface('display' => false)
|
35
|
-
assert_equal basic.visible?, basic.internal.style.visible
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_visible_should_properly_set_visibility_to_style_of_internal
|
39
|
-
basic = create_interface('display' => false)
|
40
|
-
basic.visible(true)
|
41
|
-
|
42
|
-
assert_equal basic.internal.style.visible, true
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_style_should_operate_as_reader_when_one_argument_is_given
|
46
|
-
basic = create_interface('style' => { 'fill-color' => '#ff0000' })
|
47
|
-
|
48
|
-
assert_equal basic.style(:fill_color), '#ff0000'
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_style_should_operate_as_writer_when_two_arguments_are_given
|
52
|
-
basic = create_interface
|
53
|
-
basic.style(:border_color, '#000000')
|
54
|
-
|
55
|
-
assert_equal basic.style(:border_color), '#000000'
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_style_should_operate_as_writer_for_border_style_when_three_arguments_are_given
|
59
|
-
basic = create_interface
|
60
|
-
basic.style(:border, 1, '#ffffff')
|
61
|
-
|
62
|
-
assert_equal basic.style(:border), [1, '#ffffff']
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_style_should_return_self_when_two_arguments_are_given
|
66
|
-
assert_instance_of Basic::Interface, create_interface.style(:border_width, 1)
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_style_should_return_self_when_three_arguments_are_given
|
70
|
-
assert_instance_of Basic::Interface, create_interface.style(:border, 1, '#000000')
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_styles_should_properly_set_the_specified_styles_as_Hash
|
74
|
-
basic = create_interface
|
75
|
-
basic.styles(fill_color: '#ff0000',
|
76
|
-
border_color: '#000000',
|
77
|
-
border_width: 5,
|
78
|
-
visible: false)
|
79
|
-
|
80
|
-
assert_equal [basic.style(:fill_color),
|
81
|
-
basic.style(:border_color),
|
82
|
-
basic.style(:border_width),
|
83
|
-
basic.style(:visible)],
|
84
|
-
['#ff0000', '#000000', 5, false]
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_hide_should_properly_set_false_to_visibility
|
88
|
-
basic = create_interface
|
89
|
-
basic.hide
|
90
|
-
|
91
|
-
assert_equal basic.visible?, false
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_hide_should_return_self
|
95
|
-
assert_instance_of Basic::Interface, create_interface.hide
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_show_should_properly_set_true_to_visibility
|
99
|
-
basic = create_interface
|
100
|
-
basic.show
|
101
|
-
|
102
|
-
assert_equal basic.visible?, true
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_show_should_return_self
|
106
|
-
assert_instance_of Basic::Interface, create_interface.show
|
107
|
-
end
|
108
|
-
end
|