thinreports 0.10.2 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +2 -2
  3. data/.github/dependabot.yml +11 -0
  4. data/.github/workflows/test.yml +50 -0
  5. data/.gitignore +1 -0
  6. data/CHANGELOG.md +43 -0
  7. data/Gemfile +2 -1
  8. data/{MIT-LICENSE → LICENSE.txt} +2 -0
  9. data/README.md +70 -56
  10. data/Rakefile +12 -25
  11. data/gemfiles/prawn-2.2.gemfile +5 -0
  12. data/gemfiles/prawn-2.3.gemfile +5 -0
  13. data/gemfiles/prawn-2.4.gemfile +5 -0
  14. data/lib/thinreports/core/shape/basic/format.rb +5 -0
  15. data/lib/thinreports/core/shape/image_block.rb +1 -1
  16. data/lib/thinreports/core/shape/list.rb +1 -1
  17. data/lib/thinreports/core/shape/page_number.rb +1 -1
  18. data/lib/thinreports/core/shape/stack_view/format.rb +27 -0
  19. data/lib/thinreports/core/shape/stack_view/interface.rb +17 -0
  20. data/lib/thinreports/core/shape/stack_view/internal.rb +22 -0
  21. data/lib/thinreports/core/shape/stack_view/row_format.rb +39 -0
  22. data/lib/thinreports/core/shape/stack_view.rb +17 -0
  23. data/lib/thinreports/core/shape/style/basic.rb +4 -1
  24. data/lib/thinreports/core/shape/text.rb +1 -1
  25. data/lib/thinreports/core/shape/text_block/formatter/number.rb +6 -1
  26. data/lib/thinreports/core/shape/text_block/internal.rb +0 -2
  27. data/lib/thinreports/core/shape/text_block.rb +1 -1
  28. data/lib/thinreports/core/shape.rb +2 -0
  29. data/lib/thinreports/generate.rb +11 -0
  30. data/lib/thinreports/generator/pdf/document/draw_shape.rb +31 -10
  31. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +1 -1
  32. data/lib/thinreports/generator/pdf/document/graphics/image.rb +19 -1
  33. data/lib/thinreports/generator/pdf/document/graphics/text.rb +10 -5
  34. data/lib/thinreports/generator/pdf/document/page.rb +12 -0
  35. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +7 -7
  36. data/lib/thinreports/layout/base.rb +1 -1
  37. data/lib/thinreports/layout/legacy_schema.rb +1 -0
  38. data/lib/thinreports/layout/version.rb +1 -1
  39. data/lib/thinreports/report/internal.rb +2 -0
  40. data/lib/thinreports/report.rb +2 -2
  41. data/lib/thinreports/section_report/build.rb +32 -0
  42. data/lib/thinreports/section_report/builder/item_builder.rb +49 -0
  43. data/lib/thinreports/section_report/builder/report_builder.rb +82 -0
  44. data/lib/thinreports/section_report/builder/report_data.rb +13 -0
  45. data/lib/thinreports/section_report/builder/stack_view_builder.rb +53 -0
  46. data/lib/thinreports/section_report/builder/stack_view_data.rb +11 -0
  47. data/lib/thinreports/section_report/generate.rb +26 -0
  48. data/lib/thinreports/section_report/pdf/render.rb +23 -0
  49. data/lib/thinreports/section_report/pdf/renderer/draw_item.rb +68 -0
  50. data/lib/thinreports/section_report/pdf/renderer/group_renderer.rb +57 -0
  51. data/lib/thinreports/section_report/pdf/renderer/section_height.rb +100 -0
  52. data/lib/thinreports/section_report/pdf/renderer/section_renderer.rb +39 -0
  53. data/lib/thinreports/section_report/pdf/renderer/stack_view_renderer.rb +55 -0
  54. data/lib/thinreports/section_report/pdf/renderer/stack_view_row_renderer.rb +38 -0
  55. data/lib/thinreports/section_report/schema/loader.rb +28 -0
  56. data/lib/thinreports/section_report/schema/parser.rb +52 -0
  57. data/lib/thinreports/section_report/schema/report.rb +30 -0
  58. data/lib/thinreports/section_report/schema/section.rb +47 -0
  59. data/lib/thinreports/version.rb +1 -1
  60. data/lib/thinreports.rb +5 -0
  61. data/thinreports.gemspec +11 -10
  62. metadata +48 -150
  63. data/.travis.yml +0 -16
  64. data/examples/character_spacing/character_spacing.rb +0 -8
  65. data/examples/character_spacing/character_spacing.tlf +0 -293
  66. data/examples/dynamic_image/dynamic_image.rb +0 -31
  67. data/examples/dynamic_image/dynamic_image.tlf +0 -661
  68. data/examples/dynamic_image/img200x100.png +0 -0
  69. data/examples/dynamic_image/img50x50.png +0 -0
  70. data/examples/dynamic_style/dynamic_style.rb +0 -150
  71. data/examples/dynamic_style/dynamic_style.tlf +0 -1835
  72. data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
  73. data/examples/dynamic_style/image.png +0 -0
  74. data/examples/eudc/eudc.rb +0 -20
  75. data/examples/eudc/eudc.tlf +0 -180
  76. data/examples/eudc/eudc.ttf +0 -0
  77. data/examples/helper.rb +0 -50
  78. data/examples/hidden_shapes/hidden_shapes.rb +0 -9
  79. data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
  80. data/examples/list_events/list_events.rb +0 -32
  81. data/examples/list_events/list_events.tlf +0 -361
  82. data/examples/list_manual_generation/list_manual_generation.rb +0 -22
  83. data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
  84. data/examples/list_page_number/list_page_number.rb +0 -17
  85. data/examples/list_page_number/list_page_number.tlf +0 -254
  86. data/examples/page_number/page_number.rb +0 -33
  87. data/examples/page_number/page_number.tlf +0 -215
  88. data/examples/palleted_png/palleted_png.png +0 -0
  89. data/examples/palleted_png/palleted_png.rb +0 -9
  90. data/examples/palleted_png/palleted_png.tlf +0 -47
  91. data/examples/password_setting/password_setting.rb +0 -10
  92. data/examples/password_setting/password_setting.tlf +0 -45
  93. data/examples/report_callbacks/report_callbacks.rb +0 -14
  94. data/examples/report_callbacks/report_callbacks.tlf +0 -147
  95. data/examples/single_line_tblock/single_line_tblock.rb +0 -13
  96. data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
  97. data/examples/tblock_overflow/tblock_overflow.rb +0 -20
  98. data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
  99. data/examples/tblock_styles/font_size.tlf +0 -383
  100. data/examples/tblock_styles/tblock_styles.rb +0 -43
  101. data/examples/tblock_styles/tblock_styles.tlf +0 -889
  102. data/examples/text_align/text_align.rb +0 -8
  103. data/examples/text_align/text_align.tlf +0 -241
  104. data/examples/typeB_page_size/B4_ISO.tlf +0 -45
  105. data/examples/typeB_page_size/B4_JIS.tlf +0 -45
  106. data/examples/typeB_page_size/typeB_page_size.rb +0 -17
  107. data/examples/word_wrap/word_wrap.rb +0 -26
  108. data/examples/word_wrap/word_wrap.tlf +0 -297
  109. data/test/data/font.ttf +0 -0
  110. data/test/data/image_normal.jpg +0 -0
  111. data/test/data/image_normal.png +0 -0
  112. data/test/data/image_normal_jpg_noext +0 -0
  113. data/test/data/image_normal_png_noext +0 -0
  114. data/test/data/image_pallete_based.png +0 -0
  115. data/test/data/legacy_layout/all-items.tlf +0 -1
  116. data/test/schema_helper.rb +0 -122
  117. data/test/test_helper.rb +0 -48
  118. data/test/tmp/.gitkeep +0 -0
  119. data/test/unit/core/format/test_base.rb +0 -152
  120. data/test/unit/core/shape/base/test_internal.rb +0 -87
  121. data/test/unit/core/shape/basic/test_block_format.rb +0 -23
  122. data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
  123. data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
  124. data/test/unit/core/shape/basic/test_format.rb +0 -37
  125. data/test/unit/core/shape/basic/test_interface.rb +0 -108
  126. data/test/unit/core/shape/basic/test_internal.rb +0 -55
  127. data/test/unit/core/shape/image_block/test_interface.rb +0 -24
  128. data/test/unit/core/shape/image_block/test_internal.rb +0 -31
  129. data/test/unit/core/shape/list/test_format.rb +0 -111
  130. data/test/unit/core/shape/list/test_manager.rb +0 -67
  131. data/test/unit/core/shape/list/test_page.rb +0 -156
  132. data/test/unit/core/shape/list/test_page_state.rb +0 -31
  133. data/test/unit/core/shape/list/test_section_format.rb +0 -36
  134. data/test/unit/core/shape/list/test_section_interface.rb +0 -75
  135. data/test/unit/core/shape/list/test_section_internal.rb +0 -50
  136. data/test/unit/core/shape/manager/test_format.rb +0 -38
  137. data/test/unit/core/shape/manager/test_internal.rb +0 -132
  138. data/test/unit/core/shape/manager/test_target.rb +0 -140
  139. data/test/unit/core/shape/page_number/test_format.rb +0 -55
  140. data/test/unit/core/shape/page_number/test_interface.rb +0 -33
  141. data/test/unit/core/shape/page_number/test_internal.rb +0 -81
  142. data/test/unit/core/shape/styles/test_base.rb +0 -191
  143. data/test/unit/core/shape/styles/test_basic.rb +0 -24
  144. data/test/unit/core/shape/styles/test_graphic.rb +0 -50
  145. data/test/unit/core/shape/styles/test_text.rb +0 -97
  146. data/test/unit/core/shape/text/test_format.rb +0 -44
  147. data/test/unit/core/shape/text/test_internal.rb +0 -20
  148. data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
  149. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
  150. data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
  151. data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
  152. data/test/unit/core/shape/text_block/test_format.rb +0 -169
  153. data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
  154. data/test/unit/core/shape/text_block/test_interface.rb +0 -63
  155. data/test/unit/core/shape/text_block/test_internal.rb +0 -128
  156. data/test/unit/core/test_shape.rb +0 -52
  157. data/test/unit/core/test_utils.rb +0 -68
  158. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
  159. data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -46
  160. data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -46
  161. data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
  162. data/test/unit/generator/pdf/document/test_font.rb +0 -110
  163. data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
  164. data/test/unit/generator/pdf/document/test_page.rb +0 -122
  165. data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
  166. data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +0 -41
  167. data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +0 -22
  168. data/test/unit/generator/pdf/test_document.rb +0 -22
  169. data/test/unit/generator/test_pdf.rb +0 -26
  170. data/test/unit/layout/test_base.rb +0 -41
  171. data/test/unit/layout/test_format.rb +0 -100
  172. data/test/unit/layout/test_legacy_schema.rb +0 -574
  173. data/test/unit/layout/test_version.rb +0 -26
  174. data/test/unit/report/test_base.rb +0 -248
  175. data/test/unit/report/test_internal.rb +0 -206
  176. data/test/unit/test_config.rb +0 -36
  177. data/test/unit/test_layout.rb +0 -12
  178. data/test/unit/test_report.rb +0 -18
@@ -1,248 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Report::TestBase < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- Report = Thinreports::Report
9
-
10
- def setup
11
- @report = Report::Base.new
12
- @layout_file = layout_file
13
- end
14
-
15
- def test_on_page_create_callback
16
- report = Report::Base.new layout: @layout_file.path
17
-
18
- counter = 0
19
- callback = -> page {
20
- assert_instance_of Report::Page, page
21
- counter += 1
22
- }
23
-
24
- report.on_page_create(&callback)
25
-
26
- 2.times { report.start_new_page }
27
- assert_equal counter, 2
28
- end
29
-
30
- def test_initialize_should_register_layout_as_default_when_layout_is_specified_as_the_option
31
- report = Report::Base.new layout: @layout_file.path
32
- assert_equal report.default_layout.filename, @layout_file.path
33
- end
34
-
35
- def test_initialize_should_initialize_new_Report_without_default_layout
36
- assert_nil @report.default_layout
37
- end
38
-
39
- def test_use_layout_should_register_default_layout_when_default_property_is_omitted
40
- @report.use_layout(@layout_file.path)
41
-
42
- assert_equal @report.default_layout.filename, @layout_file.path
43
- end
44
-
45
- def test_use_layout_should_register_default_layout_when_default_property_is_true
46
- @report.use_layout(@layout_file.path, default: true)
47
-
48
- assert_equal @report.default_layout.filename, @layout_file.path
49
- end
50
-
51
- def test_start_new_page_should_properly_create_a_new_Page_and_return
52
- @report.use_layout(@layout_file.path)
53
-
54
- assert_instance_of Thinreports::Report::Page, @report.start_new_page
55
- end
56
-
57
- def test_start_new_page_should_raise_when_the_layout_has_not_been_registered_yet
58
- assert_raises Thinreports::Errors::NoRegisteredLayoutFound do
59
- @report.start_new_page(layout: :unknown)
60
- end
61
- end
62
-
63
- def test_start_new_page_should_create_a_new_page_using_a_default_layout
64
- @report.use_layout(@layout_file.path, default: true)
65
-
66
- assert_equal @report.start_new_page.layout.filename, @layout_file.path
67
- end
68
-
69
- def test_start_new_page_should_create_a_new_page_using_a_layout_with_specified_id
70
- @report.use_layout(@layout_file.path, id: :foo)
71
-
72
- assert_equal @report.start_new_page(layout: :foo).layout.filename,
73
- @layout_file.path
74
- end
75
-
76
- def test_start_new_page_should_create_a_new_page_using_a_specified_layoutfile
77
- new_page = @report.start_new_page(layout: @layout_file.path)
78
- assert_equal new_page.layout.filename, @layout_file.path
79
- end
80
-
81
- def test_start_new_page_with_count_option
82
- @report.use_layout @layout_file.path, default: true
83
-
84
- new_page = @report.start_new_page count: false
85
- assert_nil new_page.no
86
- assert_equal @report.page_count, 0
87
-
88
- new_page = @report.start_new_page count: true
89
- assert_equal new_page.no, 1
90
- assert_equal @report.page_count, 1
91
-
92
- new_page = @report.start_new_page
93
- assert_equal new_page.no, 2
94
- assert_equal @report.page_count, 2
95
- end
96
-
97
- def test_add_blank_page_should_properly_create_a_new_blank_page
98
- @report.use_layout(@layout_file.path)
99
-
100
- assert_instance_of Thinreports::Report::BlankPage, @report.add_blank_page
101
- end
102
-
103
- def test_layout_should_return_the_default_layout_with_no_arguments
104
- @report.use_layout(@layout_file.path, default: true)
105
-
106
- assert_equal @report.layout.filename, @layout_file.path
107
- end
108
-
109
- def test_layout_should_raise_when_the_specified_layout_is_not_found
110
- assert_raises Thinreports::Errors::UnknownLayoutId do
111
- @report.layout(:unknown_layout_id)
112
- end
113
- end
114
-
115
- def test_layout_should_return_the_layout_with_specified_id
116
- @report.use_layout(@layout_file.path, id: :foo)
117
-
118
- assert_equal @report.layout(:foo).filename, @layout_file.path
119
- end
120
-
121
- def test_generate
122
- report = Report::Base.new(layout: @layout_file.path)
123
-
124
- generator = mock('generator')
125
- generator.expects(:generate).with('result.pdf')
126
-
127
- Thinreports::Generator::PDF.expects(:new)
128
- .with(report, { security: { owner_password: 'pass' }})
129
- .returns(generator)
130
-
131
- report.generate(
132
- filename: 'result.pdf',
133
- security: { owner_password: 'pass' }
134
- )
135
- end
136
-
137
- def test_page_should_return_the_current_page
138
- @report.use_layout(@layout_file.path)
139
- @report.start_new_page
140
-
141
- assert_instance_of Thinreports::Report::Page, @report.page
142
- end
143
-
144
- def test_page_count_should_return_total_page_count
145
- @report.use_layout(@layout_file.path)
146
- 2.times { @report.start_new_page }
147
-
148
- assert_equal @report.page_count, 2
149
- end
150
-
151
- def test_finalize_should_finalize_report
152
- @report.finalize
153
- assert_equal @report.finalized?, true
154
- end
155
-
156
- def test_finalized_asker_should_return_false_when_report_has_not_been_finalized_yet
157
- assert_equal @report.finalized?, false
158
- end
159
-
160
- def test_finalized_asker_should_return_true_when_report_is_already_finalized
161
- @report.finalize
162
- assert_equal @report.finalized?, true
163
- end
164
-
165
- def test_list_should_create_new_page_when_page_is_not_created
166
- @report.use_layout(@layout_file.path)
167
- @report.list
168
-
169
- refute_nil @report.page
170
- end
171
-
172
- def test_list_should_create_new_page_when_page_is_finalized
173
- @report.tap do |r|
174
- r.use_layout(@layout_file.path)
175
- r.start_new_page
176
- r.page.finalize
177
- end
178
- @report.list
179
-
180
- assert_equal @report.page.finalized?, false
181
- end
182
-
183
- def test_list_should_properly_return_shape_with_the_specified_id
184
- @report.use_layout(@layout_file.path)
185
-
186
- assert_equal @report.list.id, 'default'
187
- end
188
-
189
- def test_start_page_number
190
- assert_equal @report.start_page_number, 1
191
- @report.start_page_number_from 10
192
- assert_equal @report.start_page_number, 10
193
- end
194
-
195
- def test_Base_create_should_finalize_report
196
- report = Report::Base.create do |r|
197
- assert_instance_of Report::Base, r
198
- end
199
- assert_equal report.finalized?, true
200
- end
201
-
202
- def test_Base_create_should_raise_when_no_block_given
203
- assert_raises ArgumentError do
204
- Report::Base.create
205
- end
206
- end
207
-
208
- def test_Base_generate_should_raise_when_no_block_given
209
- assert_raises ArgumentError do
210
- Report::Base.generate(:pdf)
211
- end
212
- end
213
-
214
- def test_Base_generate_with_deprecated_arguments
215
- Report::Base.expects(:create).with(layout: '/path/to/layout.tlf').returns(@report)
216
- @report.expects(:generate).with(
217
- filename: 'result.pdf',
218
- security: { owner_password: 'pass' }
219
- )
220
-
221
- Report::Base.generate(
222
- report: { layout: '/path/to/layout.tlf' },
223
- generator: {
224
- filename: 'result.pdf',
225
- security: { owner_password: 'pass' }
226
- }
227
- ) { |_| }
228
- end
229
-
230
- def test_Base_generate_argument_priority
231
- Report::Base.expects(:create).with(layout: '/path/to/layout.tlf').returns(@report)
232
- @report.expects(:generate).with(
233
- filename: 'result.pdf',
234
- security: { owner_password: 'pass' }
235
- )
236
-
237
- Report::Base.generate(
238
- layout: '/path/to/layout.tlf',
239
- filename: 'result.pdf',
240
- security: { owner_password: 'pass' },
241
- report: { layout: '/path/to/deprecated.tlf' },
242
- generator: {
243
- filename: 'deprecated.pdf',
244
- security: { owner_password: 'deprecated' }
245
- }
246
- ) { |_| }
247
- end
248
- end
@@ -1,206 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Report::TestInternal < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- Report = Thinreports::Report
9
-
10
- def setup
11
- @layout_file = layout_file
12
- end
13
-
14
- def report
15
- Report::Base.new
16
- end
17
-
18
- def test_layout_specified_in_new_method_should_be_defined_as_default_layout
19
- internal = Report::Internal.new(report, layout: @layout_file.path)
20
- assert_equal internal.default_layout.filename, @layout_file.path
21
- end
22
-
23
- def test_register_layout_should_be_set_as_default_layout_when_options_are_omitted
24
- internal = Report::Internal.new(report, {})
25
- internal.register_layout(@layout_file.path)
26
-
27
- assert_equal internal.default_layout.filename, @layout_file.path
28
- end
29
-
30
- def test_register_layout_should_be_set_as_default_layout_when_default_option_is_true
31
- internal = Report::Internal.new(report, {})
32
- internal.register_layout(@layout_file.path, default: true)
33
-
34
- assert_equal internal.default_layout.filename, @layout_file.path
35
- end
36
-
37
- def test_register_layout_should_be_able_to_change_the_default_layout
38
- internal = Report::Internal.new(report, layout: @layout_file.path)
39
- internal.register_layout(@layout_file.path, default: true)
40
-
41
- assert_equal internal.default_layout.filename, @layout_file.path
42
- end
43
-
44
- def test_register_layout_should_be_set_as_with_id_when_id_option_is_set
45
- internal = Report::Internal.new(report, {})
46
- internal.register_layout(@layout_file.path, id: :foo)
47
-
48
- assert_equal internal.layout_registry[:foo].filename, @layout_file.path
49
- end
50
-
51
- def test_register_layout_should_raise_an_error_when_id_is_already_registered
52
- internal = Report::Internal.new(report, {})
53
- internal.register_layout(@layout_file.path, id: :foo)
54
-
55
- assert_raises ArgumentError do
56
- internal.register_layout(@layout_file.path, id: :foo)
57
- end
58
- end
59
-
60
- def test_add_page_should_finalize_the_current_page
61
- layout = Thinreports::Layout.new(@layout_file.path)
62
-
63
- internal = Report::Internal.new(report, layout: @layout_file.path)
64
- page = internal.add_page(Thinreports::Report::Page.new(report, layout))
65
- internal.add_page(Thinreports::Report::Page.new(report, layout))
66
-
67
- assert_equal page.finalized?, true
68
- end
69
-
70
- def test_add_page_should_return_the_current_page
71
- layout = Thinreports::Layout.new(@layout_file.path)
72
- new_page = Thinreports::Report::Page.new(report, layout)
73
-
74
- internal = Report::Internal.new(report, layout: @layout_file.path)
75
-
76
- assert_same new_page, internal.add_page(new_page)
77
- end
78
-
79
- def test_add_page_should_add_the_initialized_page
80
- layout = Thinreports::Layout.new(@layout_file.path)
81
- new_page = Thinreports::Report::Page.new(report, layout)
82
-
83
- internal = Report::Internal.new(report, layout: @layout_file.path)
84
- internal.add_page(new_page)
85
-
86
- assert_same new_page, internal.pages.last
87
- end
88
-
89
- def test_add_page_should_count_up_the_total_page_count
90
- layout = Thinreports::Layout.new(@layout_file.path)
91
-
92
- internal = Report::Internal.new(report, layout: @layout_file.path)
93
- internal.add_page(Thinreports::Report::Page.new(report, layout))
94
-
95
- assert_equal internal.page_count, 1
96
- end
97
-
98
- def test_add_page_should_switch_to_a_reference_to_the_current_page
99
- layout = Thinreports::Layout.new(@layout_file.path)
100
- new_pages = (1..2).inject([]) do |pages|
101
- pages << Thinreports::Report::Page.new(report, layout)
102
- end
103
-
104
- internal = Report::Internal.new(report, layout: @layout_file.path)
105
- internal.add_page(new_pages[0])
106
-
107
- assert_same internal.page, new_pages[0]
108
-
109
- internal.add_page(new_pages[1])
110
-
111
- assert_same internal.page, new_pages[1]
112
- end
113
-
114
- def test_add_blank_page_should_not_count_up_the_total_page_count_when_count_is_disabled
115
- internal = Report::Internal.new(report, layout: @layout_file.path)
116
- internal.add_page(Thinreports::Report::BlankPage.new(false))
117
-
118
- assert_equal internal.page_count, 0
119
- end
120
-
121
- def test_add_blank_page_should_count_up_the_total_page_count_when_count_is_enabled
122
- internal = Report::Internal.new(report, layout: @layout_file.path)
123
- internal.add_page(Thinreports::Report::BlankPage.new)
124
-
125
- assert_equal internal.page_count, 1
126
- end
127
-
128
- def test_finalize_should_finalize_the_report
129
- internal = Report::Internal.new(report, layout: @layout_file.path)
130
- internal.finalize
131
-
132
- assert internal.finalized?
133
- end
134
-
135
- def test_finalize_should_not_work_when_report_is_already_finalized
136
- internal = Report::Internal.new(report, layout: @layout_file.path)
137
- internal.finalize
138
-
139
- # #finalize_current_page must never be called
140
- internal.expects(:finalize_current_page).never
141
- internal.finalize
142
- end
143
-
144
- def test_finalized_should_return_true_when_report_is_already_finalized
145
- internal = Report::Internal.new(report, layout: @layout_file.path)
146
- internal.finalize
147
-
148
- assert internal.finalized?
149
- end
150
-
151
- def test_load_layout_with_String
152
- internal = Report::Internal.new(report, layout: @layout_file.path)
153
-
154
- assert_equal internal.load_layout(@layout_file.path).filename,
155
- @layout_file.path
156
- end
157
-
158
- def test_load_layout_with_id
159
- internal = Report::Internal.new(report, {})
160
- internal.register_layout(@layout_file.path, id: :sample)
161
-
162
- assert_equal internal.load_layout(:sample).filename,
163
- @layout_file.path
164
- end
165
-
166
- def test_load_layout_with_unknown_id
167
- internal = Report::Internal.new(report, {})
168
- assert_nil internal.load_layout(:unknown)
169
- end
170
-
171
- def test_load_layout_should_set_default_layout_when_default_layout_is_nil
172
- internal = Report::Internal.new(report, {})
173
- internal.load_layout(@layout_file.path)
174
-
175
- assert_equal internal.default_layout.filename,
176
- @layout_file.path
177
- end
178
-
179
- def test_load_layout_should_raise_error_when_invalid_value_set
180
- internal = Report::Internal.new(report, {})
181
-
182
- assert_raises Thinreports::Errors::LayoutFileNotFound do
183
- internal.load_layout('/path/to/unkown.tlf')
184
- end
185
- end
186
-
187
- def test_copy_page_should_finalize_current_page
188
- layout = Thinreports::Layout.new(@layout_file.path)
189
-
190
- internal = Report::Internal.new(report, layout: @layout_file.path)
191
- internal.add_page(page = Thinreports::Report::Page.new(report, layout))
192
- internal.copy_page
193
-
194
- assert page.finalized?
195
- end
196
-
197
- def test_copy_page_should_add_the_copied_page
198
- layout = Thinreports::Layout.new(@layout_file.path)
199
-
200
- internal = Report::Internal.new(report, layout: @layout_file.path)
201
- internal.add_page(Thinreports::Report::Page.new(report, layout))
202
- internal.copy_page
203
-
204
- assert_equal internal.page_count, 2
205
- end
206
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::TestConfig < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- def test_config_should_return_configuration_of_thinreports
9
- assert_instance_of Thinreports::Configuration, Thinreports.config
10
- end
11
-
12
- def test_configure_should_exec_an_given_block_with_config_which_instance_of_Configuration
13
- Thinreports.configure do |config|
14
- assert_instance_of Thinreports::Configuration, config
15
- end
16
- end
17
-
18
- def test_fallback_fonts
19
- config = Thinreports::Configuration.new
20
-
21
- # should be empty by default
22
- assert_empty config.fallback_fonts
23
-
24
- config.fallback_fonts = 'Helvetica'
25
- assert_equal config.fallback_fonts, ['Helvetica']
26
-
27
- config.fallback_fonts = ['/path/to/font.ttf', 'Courier New']
28
- assert_equal config.fallback_fonts, ['/path/to/font.ttf', 'Courier New']
29
-
30
- config.fallback_fonts = []
31
- config.fallback_fonts << 'Helvetica'
32
- config.fallback_fonts << 'IPAMincho'
33
- config.fallback_fonts.unshift 'Times New Roman'
34
- assert_equal config.fallback_fonts, ['Times New Roman', 'Helvetica', 'IPAMincho']
35
- end
36
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::TestLayout < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- def test_new
9
- assert_instance_of Thinreports::Layout::Base,
10
- Thinreports::Layout.new(layout_file.path)
11
- end
12
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::TestReport < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- Report = Thinreports::Report
10
-
11
- def test_new
12
- assert_instance_of Report::Base, Report.new
13
- end
14
-
15
- def test_create
16
- assert_instance_of Report::Base, Report.create {}
17
- end
18
- end