htmlgrid 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/test_grid.rb CHANGED
@@ -28,20 +28,10 @@ $: << File.expand_path("../ext", File.dirname(__FILE__))
28
28
  $: << File.dirname(__FILE__)
29
29
 
30
30
  require 'minitest/autorun'
31
- require 'rebuild'
32
31
  require 'stub/cgi'
33
32
  require 'htmlgrid/label'
34
33
  require 'htmlgrid/grid'
35
-
36
- module HtmlGrid
37
- class Grid
38
- class Row
39
- class Field
40
- attr_reader :attributes
41
- end
42
- end
43
- end
44
- end
34
+ require 'test_helper'
45
35
 
46
36
  class TestGrid < Minitest::Test
47
37
  class StubLabel
@@ -333,20 +323,24 @@ class TestGrid < Minitest::Test
333
323
  expected = '<TABLE cellspacing="0"><TR><TD>testreihe</TD></TR><TR><TD>&nbsp;</TD></TR><TR><TD>testfeld</TD></TR></TABLE>'
334
324
  assert_equal(expected, @grid.to_html(CGI.new))
335
325
  end
336
- def test_gc
337
- 100.times { |y|
338
- 200.times { |x|
339
- str = "[#{x}, #{y}]: test"
340
- @grid.add(str, x, y)
341
- @grid.add(str, x, y)
342
- @grid.add(str, x, y)
343
- @grid.add(str, x, y)
344
- }
345
- }
346
- assert_equal(100, @grid.height)
347
- assert_equal(200, @grid.width)
348
- result = @grid.to_html(CGI.new)
349
- end
326
+
327
+ # @todo
328
+ # What does this test? (gabage collection?)
329
+ def test_gc
330
+ 100.times { |y|
331
+ 200.times { |x|
332
+ str = "[#{x}, #{y}]: test"
333
+ @grid.add(str, x, y)
334
+ @grid.add(str, x, y)
335
+ @grid.add(str, x, y)
336
+ @grid.add(str, x, y)
337
+ }
338
+ }
339
+ assert_equal(100, @grid.height)
340
+ assert_equal(200, @grid.width)
341
+ @grid.to_html(CGI.new)
342
+ end
343
+
350
344
  def test_label
351
345
  label = StubLabel.new
352
346
  @grid.add(label, 0,0)
@@ -0,0 +1,9 @@
1
+ module HtmlGrid
2
+ class Grid
3
+ class Row
4
+ class Field
5
+ attr_reader :attributes
6
+ end
7
+ end
8
+ end
9
+ end
@@ -16,242 +16,269 @@ require 'htmlgrid/form'
16
16
  require 'htmlgrid/list'
17
17
  require 'htmlgrid/div'
18
18
 
19
- class StubComposite < HtmlGrid::Composite
20
- attr_writer :container
21
- COMPONENTS = {
22
- [0,0,0] => :baz,
23
- [0,0,1] => :foo,
24
- [0,0,2] => :baz,
25
- [0,1,0] => :baz,
26
- [0,1,1] => :baz,
27
- }
28
- LABELS = true
29
- SYMBOL_MAP = {
30
- :bar => HtmlGrid::InputText,
31
- }
32
- attr_reader :model, :session
33
- public :resolve_offset, :labels?
34
- def initialize(first, second, third = nil)
35
- super(first, second)
19
+ module InteractionTest
20
+ class StubComposite < HtmlGrid::Composite
21
+ attr_writer :container
22
+ COMPONENTS = {
23
+ [0, 0, 0] => :baz,
24
+ [0, 0, 1] => :foo,
25
+ [0, 0, 2] => :baz,
26
+ [0, 1, 0] => :baz,
27
+ [0, 1, 1] => :baz,
28
+ }
29
+ LABELS = true
30
+ SYMBOL_MAP = {
31
+ :bar => HtmlGrid::InputText,
32
+ }
33
+ attr_reader :model, :session
34
+ public :resolve_offset, :labels?
35
+ def initialize(first, second, third = nil)
36
+ super(first, second)
37
+ end
38
+ def init
39
+ @barcount=0
40
+ super
41
+ end
42
+ def foo(model, session=@session)
43
+ "Foo"
44
+ end
45
+ def baz(model, session=@session)
46
+ @barcount += 1
47
+ "Baz#{@barcount}"
48
+ end
36
49
  end
37
- def init
38
- @barcount=0
39
- super
50
+ class StubCompositeComponent < HtmlGrid::Component
51
+ def to_html(context)
52
+ context.a(@attributes) { 'brafoo' }
53
+ end
40
54
  end
41
- def foo(model, session=@session)
42
- "Foo"
55
+ class StubComposite2 < HtmlGrid::Composite
56
+ COMPONENTS = {
57
+ [0, 0] => StubCompositeComponent,
58
+ }
43
59
  end
44
- def baz(model, session=@session)
45
- @barcount += 1
46
- "Baz#{@barcount}"
60
+ class StubComposite3 < StubComposite2
61
+ COMPONENT_CSS_MAP = {[0, 0, 4, 4] => 'standard'}
47
62
  end
48
- end
49
- class StubCompositeComponent < HtmlGrid::Component
50
- def to_html(context)
51
- context.a(@attributes) { 'brafoo' }
63
+ class StubComposite4 < StubComposite3
64
+ CSS_MAP = {[0, 0] => 'dradnats'}
65
+ COMPONENT_CSS_MAP = {[0, 0, 4, 4] => 'standard'}
52
66
  end
53
- end
54
- class StubComposite2 < HtmlGrid::Composite
55
- COMPONENTS = {
56
- [0,0] => StubCompositeComponent,
57
- }
58
- end
59
- class StubComposite3 < StubComposite2
60
- COMPONENT_CSS_MAP = {[0,0,4,4]=>'standard'}
61
- end
62
- class StubComposite4 < StubComposite3
63
- CSS_MAP = {[0,0]=>'dradnats'}
64
- COMPONENT_CSS_MAP = {[0,0,4,4]=>'standard'}
65
- end
66
- class StubCompositeNoLabel < HtmlGrid::Composite
67
- LABELS = false
68
- COMPONENTS = {}
69
- public :labels?
70
- end
71
- class StubCompositeModel
72
- end
73
- class StubCompositeLookandfeel
74
- def attributes(key)
75
- {}
67
+ class StubCompositeNoLabel < HtmlGrid::Composite
68
+ LABELS = false
69
+ COMPONENTS = {}
70
+ public :labels?
76
71
  end
77
- def lookup(key)
72
+ class StubCompositeModel
78
73
  end
79
- def base_url
80
- 'http://www.oddb.org/de/gcc'
81
- end
82
- end
83
- class StubCompositeSession
84
- attr_accessor :event
85
- def lookandfeel
86
- StubCompositeLookandfeel.new
74
+ class StubCompositeLookandfeel
75
+ def attributes(key)
76
+ {}
77
+ end
78
+ def lookup(key)
79
+ end
80
+ def base_url
81
+ 'http://www.oddb.org/de/gcc'
82
+ end
87
83
  end
88
- def error(key)
84
+ class StubCompositeSession
85
+ attr_accessor :event
86
+ def lookandfeel
87
+ StubCompositeLookandfeel.new
88
+ end
89
+ def error(key)
90
+ end
89
91
  end
90
- end
91
- class StubCompositeForm < HtmlGrid::Form
92
- COMPONENTS = {
93
- [0,0] => StubComposite
94
- }
95
- EVENT = :foo
96
- end
97
- class StubCompositeColspan1 < HtmlGrid::Composite
98
- COMPONENTS = {}
99
- end
100
- class StubCompositeColspan2 < HtmlGrid::Composite
101
- COMPONENTS = {
102
- [0,0] => :foo,
103
- }
104
- end
105
- class StubCompositeColspan3 < HtmlGrid::Composite
106
- COMPONENTS = {
107
- [0,0] => :foo,
108
- [1,0] => :bar,
109
- }
110
- end
111
- class StubCompositeColspan4 < HtmlGrid::Composite
112
- COMPONENTS = {
113
- [0,0] => :foo,
114
- [2,0] => :bar,
115
- }
116
- end
117
-
118
- class StubInteractionChooserDrugList < HtmlGrid::List
119
- attr_reader :model, :value
120
- COMPONENTS = {
121
- [0,0] => :info_drug,
122
- }
123
- CSS_MAP = {
124
- [0,0] => 'css.info',
125
- }
126
- SORT_HEADER = false
127
- SORT_DEFAULT = :foo
128
- def initialize(models, session=@session)
129
- super # must come first or it will overwrite @value
130
- @value = []
131
- models.each{ |model|
132
- @value << StubInteractionChooserDrug.new(model, session)
133
- }
92
+ class StubCompositeForm < HtmlGrid::Form
93
+ COMPONENTS = {
94
+ [0, 0] => StubComposite
95
+ }
96
+ EVENT = :foo
134
97
  end
135
- def to_html(context)
136
- div = HtmlGrid::Div.new(@model, @session, self)
137
- if @drugs and !@drugs.empty?
138
- delete_all_link = HtmlGrid::Link.new(:delete, @model, @session, self)
139
- delete_all_link.href = @lookandfeel._event_url(:delete_all, [])
140
- delete_all_link.value = @lookandfeel.lookup(:interaction_chooser_delete_all)
141
- delete_all_link.css_class = 'list'
142
- div.value = delete_all_link
143
- end
144
- div.set_attribute('id', 'drugs')
145
- @value << div unless @value.find{ |v| v.attributes['id'].eql?('drugs') }
146
- super
98
+ class StubCompositeColspan1 < HtmlGrid::Composite
99
+ COMPONENTS = {}
147
100
  end
148
- end
149
-
150
- class StubDrugModel
151
- attr_reader :foo
152
- def initialize(foo)
153
- @foo = foo
101
+ class StubCompositeColspan2 < HtmlGrid::Composite
102
+ COMPONENTS = {
103
+ [0, 0] => :foo,
104
+ }
154
105
  end
155
- def fachinfo
156
- @foo
106
+ class StubCompositeColspan3 < HtmlGrid::Composite
107
+ COMPONENTS = {
108
+ [0, 0] => :foo,
109
+ [1, 0] => :bar,
110
+ }
157
111
  end
158
- def drug
159
- 'Drug'
112
+ class StubCompositeColspan4 < HtmlGrid::Composite
113
+ COMPONENTS = {
114
+ [0, 0] => :foo,
115
+ [2, 0] => :bar,
116
+ }
160
117
  end
161
- end
162
118
 
163
- class StubInteractionChooserDrugHeader < HtmlGrid::Composite
164
- COMPONENTS = {
165
- [0,0] => :fachinfo,
166
- [1,0] => :atc,
167
- [2,0] => :delete,
168
- }
169
- CSS_MAP = {
170
- [0,0] => 'small',
171
- [1,0] => 'interaction-atc',
172
- [2,0] => 'small',
173
- }
174
- HTML_ATTRIBUTES = {
175
- 'style' => 'background-color:greenyellow',
176
- }
177
- def init
178
- super
179
- end
180
- def fachinfo(model, session=@session)
181
- "fachinfo-#{model.foo}"
182
- end
183
- def atc(model, session=@session)
184
- 'atc'
185
- end
186
- def delete(model, session=@session)
187
- 'delete'
188
- end
189
- end
190
- class StubInteractionChooserDrug < HtmlGrid::Composite
191
- COMPONENTS = {
119
+ class StubInteractionChooserDrugList < HtmlGrid::List
120
+ attr_reader :model, :value
121
+ COMPONENTS = {
122
+ [0, 0] => :info_drug,
192
123
  }
193
- CSS_MAP = {}
194
- CSS_CLASS = 'composite'
195
- @@barcode ||= 0
196
- def init
197
- @@barcode += 1
198
- components.store([0,0], :header_info)
199
- css_map.store([0,0], 'subheading')
200
- 1.upto(@@barcode) { |idx|
201
- components.store([0,idx], :text_info)
124
+ CSS_MAP = {
125
+ [0, 0] => 'css.info',
202
126
  }
203
- @attributes.store('id', 'drugs_' + @@barcode.to_s)
204
- super
205
- end
206
- def header_info(model, session=@session)
207
- StubInteractionChooserDrugHeader.new(model, session, self)
208
- end
209
- def text_info(model, session=@session)
210
- "interaction for #{model.foo}"
211
- end
212
- end
213
- class TestComposite < Minitest::Test
214
- def setup
215
- @composite = StubComposite.new(StubCompositeModel.new, StubCompositeSession.new)
127
+ SORT_HEADER = false
128
+ SORT_DEFAULT = :foo
129
+ def initialize(models, session=@session)
130
+ @drugs = nil
131
+ super # must come first or it will overwrite @value
132
+ @value = []
133
+ models.each{ |model|
134
+ @value << StubInteractionChooserDrug.new(model, session)
135
+ }
136
+ end
137
+ def to_html(context)
138
+ div = HtmlGrid::Div.new(@model, @session, self)
139
+ if @drugs and !@drugs.empty?
140
+ link = HtmlGrid::Link.new(:delete, @model, @session, self)
141
+ link.href = @lookandfeel._event_url(:delete_all, [])
142
+ link.value = @lookandfeel.lookup(:interaction_chooser_delete_all)
143
+ link.css_class = 'list'
144
+ div.value = link
145
+ end
146
+ div.set_attribute('id', 'drugs')
147
+ @value << div unless @value.find{ |v| v.attributes['id'].eql?('drugs') }
148
+ super
149
+ end
216
150
  end
217
- def test_create_method
218
- foo = nil
219
- foo = @composite.create(:foo, @composite.model)
220
- assert_equal("Foo", foo)
151
+
152
+ class StubDrugModel
153
+ attr_reader :foo
154
+ def initialize(foo)
155
+ @foo = foo
156
+ end
157
+ def fachinfo
158
+ @foo
159
+ end
160
+ def drug
161
+ 'Drug'
162
+ end
221
163
  end
222
- def test_to_html
223
- expected = '<TABLE cellspacing="0"><TR><TD>Baz1FooBaz2</TD></TR><TR><TD>Baz3Baz4</TD></TR></TABLE>'
224
- assert_equal(expected, @composite.to_html(CGI.new))
164
+
165
+ class StubInteractionChooserDrugHeader < HtmlGrid::Composite
166
+ COMPONENTS = {
167
+ [0, 0] => :fachinfo,
168
+ [1, 0] => :atc,
169
+ [2, 0] => :delete,
170
+ }
171
+ CSS_MAP = {
172
+ [0, 0] => 'small',
173
+ [1, 0] => 'interaction-atc',
174
+ [2, 0] => 'small',
175
+ }
176
+ HTML_ATTRIBUTES = {
177
+ 'style' => 'background-color:greenyellow',
178
+ }
179
+ def init
180
+ super
181
+ end
182
+ def fachinfo(model, session=@session)
183
+ "fachinfo-#{model.foo}"
184
+ end
185
+ def atc(model, session=@session)
186
+ 'atc'
187
+ end
188
+ def delete(model, session=@session)
189
+ 'delete'
190
+ end
225
191
  end
226
- def test_component_css_map
227
- composite = StubComposite2.new(StubCompositeModel.new, StubCompositeSession.new)
228
- expected = '<TABLE cellspacing="0"><TR><TD><A>brafoo</A></TD></TR></TABLE>'
229
- assert_equal(expected, composite.to_html(CGI.new))
230
- composite = StubComposite3.new(StubCompositeModel.new, StubCompositeSession.new)
231
- expected = '<TABLE cellspacing="0"><TR><TD><A class="standard">brafoo</A></TD></TR></TABLE>'
232
- assert_equal(expected, composite.to_html(CGI.new))
233
- composite = StubComposite4.new(StubCompositeModel.new, StubCompositeSession.new)
192
+ class StubInteractionChooserDrug < HtmlGrid::Composite
193
+ COMPONENTS = {
194
+ }
195
+ CSS_MAP = {}
196
+ CSS_CLASS = 'composite'
197
+ @@barcode ||= 0
198
+ def init
199
+ @@barcode += 1
200
+ components.store([0,0], :header_info)
201
+ css_map.store([0,0], 'subheading')
202
+ 1.upto(@@barcode) { |idx|
203
+ components.store([0,idx], :text_info)
204
+ }
205
+ @attributes.store('id', 'drugs_' + @@barcode.to_s)
206
+ super
207
+ end
208
+ def header_info(model, session=@session)
209
+ StubInteractionChooserDrugHeader.new(model, session, self)
210
+ end
211
+ def text_info(model, session=@session)
212
+ "interaction for #{model.foo}"
213
+ end
234
214
  end
235
- def test_interaction_list_to_html
236
- models = [ StubDrugModel.new('Aspirin'),
237
- StubDrugModel.new('Marcoumar'),
238
- ]
239
- composite = StubInteractionChooserDrugList.new(models, StubCompositeSession.new)
240
- expected = [ '<TABLE cellspacing="0" class="composite" id="drugs_1">',
241
- '<TR><TD class="subheading"><TABLE cellspacing="0" style="background-color:greenyellow">',
242
- '<TR><TD class="small">fachinfo-Aspirin</TD><TD class="interaction-atc">atc</TD><TD class="small">delete</TD></TR></TABLE></TD></TR>',
243
- '<TR><TD>interaction for Aspirin</TD></TR></TABLE> <TABLE cellspacing="0" class="composite" id="drugs_2">',
244
- '<TR><TD class="subheading"><TABLE cellspacing="0" style="background-color:greenyellow">',
245
- '<TR><TD class="small">fachinfo-Marcoumar</TD><TD class="interaction-atc">atc</TD><TD class="small">delete</TD></TR></TABLE></TD></TR>',
246
- '<TR><TD>interaction for Marcoumar</TD></TR>',
247
- '<TR><TD>interaction for Marcoumar</TD></TR></TABLE> <DIV id="drugs"></DIV><TABLE cellspacing="0">',
248
- '<TR><TH>&nbsp;</TH></TR>',
249
- '<TR><TD class="css.info"></TD></TR>',
250
- '<TR><TD class="css.info-bg"></TD></TR></TABLE>',
251
- ]
252
- html = composite.to_html(CGI.new)
253
- expected.each_with_index do |line, idx|
254
- assert(html.index(line), "#{idx}: missing #{line} in #{html}")
215
+ class TestComposite < Minitest::Test
216
+ def setup
217
+ @composite = StubComposite.new(
218
+ StubCompositeModel.new, StubCompositeSession.new)
219
+ end
220
+ def test_create_method
221
+ foo = nil
222
+ foo = @composite.create(:foo, @composite.model)
223
+ assert_equal("Foo", foo)
224
+ end
225
+ def test_to_html
226
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), @composite.to_html(CGI.new))
227
+ <TABLE cellspacing="0">
228
+ <TR><TD>Baz1FooBaz2</TD></TR><TR><TD>Baz3Baz4</TD></TR>
229
+ </TABLE>
230
+ EXP
231
+ end
232
+ def test_component_css_map
233
+ table = StubComposite2.new(
234
+ StubCompositeModel.new, StubCompositeSession.new)
235
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), table.to_html(CGI.new))
236
+ <TABLE cellspacing="0">
237
+ <TR><TD><A>brafoo</A></TD></TR>
238
+ </TABLE>
239
+ EXP
240
+ table = StubComposite3.new(
241
+ StubCompositeModel.new, StubCompositeSession.new)
242
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), table.to_html(CGI.new))
243
+ <TABLE cellspacing="0">
244
+ <TR><TD><A class="standard">brafoo</A></TD></TR>
245
+ </TABLE>
246
+ EXP
247
+ table = StubComposite4.new(
248
+ StubCompositeModel.new, StubCompositeSession.new)
249
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), table.to_html(CGI.new))
250
+ <TABLE cellspacing="0">
251
+ <TR><TD><A class="standard">brafoo</A></TD></TR>
252
+ </TABLE>
253
+ EXP
254
+ end
255
+
256
+ # @todo
257
+ # Spruce up lines in expectation
258
+ def test_interaction_list_to_html
259
+ models = [
260
+ StubDrugModel.new('Aspirin'),
261
+ StubDrugModel.new('Marcoumar'),
262
+ ]
263
+ composite = StubInteractionChooserDrugList.new(
264
+ models, StubCompositeSession.new)
265
+ expected = [
266
+ '<TABLE cellspacing="0" class="composite" id="drugs_1">',
267
+ '<TR><TD class="subheading"><TABLE cellspacing="0" style="background-color:greenyellow">',
268
+ '<TR><TD class="small">fachinfo-Aspirin</TD><TD class="interaction-atc">atc</TD><TD class="small">delete</TD></TR></TABLE></TD></TR>',
269
+ '<TR><TD>interaction for Aspirin</TD></TR></TABLE> <TABLE cellspacing="0" class="composite" id="drugs_2">',
270
+ '<TR><TD class="subheading"><TABLE cellspacing="0" style="background-color:greenyellow">',
271
+ '<TR><TD class="small">fachinfo-Marcoumar</TD><TD class="interaction-atc">atc</TD><TD class="small">delete</TD></TR></TABLE></TD></TR>',
272
+ '<TR><TD>interaction for Marcoumar</TD></TR>',
273
+ '<TR><TD>interaction for Marcoumar</TD></TR></TABLE> <DIV id="drugs"></DIV><TABLE cellspacing="0">',
274
+ '<TR><TH>&nbsp;</TH></TR>',
275
+ '<TR><TD class="css.info"></TD></TR>',
276
+ '<TR><TD class="css.info-bg"></TD></TR></TABLE>',
277
+ ]
278
+ html = composite.to_html(CGI.new)
279
+ expected.each_with_index do |line, idx|
280
+ assert(html.index(line), "#{idx}: missing #{line} in #{html}")
281
+ end
255
282
  end
256
283
  end
257
284
  end