htmlgrid 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +8 -0
- data/Manifest.txt +2 -3
- data/lib/htmlgrid/component.rb +1 -1
- data/lib/htmlgrid/composite.rb +1 -1
- data/lib/htmlgrid/errormessage.rb +1 -1
- data/lib/htmlgrid/grid.rb +258 -275
- data/lib/htmlgrid/label.rb +14 -14
- data/lib/htmlgrid/list.rb +23 -23
- data/lib/htmlgrid/version.rb +1 -1
- data/test/suite.rb +0 -2
- data/test/test_add_row.rb +75 -56
- data/test/test_component.rb +3 -3
- data/test/test_composite.rb +210 -178
- data/test/test_grid.rb +19 -25
- data/test/test_helper.rb +9 -0
- data/test/test_interaction_list.rb +242 -215
- data/test/test_label.rb +4 -0
- data/test/test_list.rb +1 -7
- data/test/test_select.rb +10 -19
- metadata +18 -5
- data/LICENCE.txt +0 -515
- data/test/rebuild.rb +0 -39
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> </TD></TR><TR><TD>testfeld</TD></TR></TABLE>'
|
334
324
|
assert_equal(expected, @grid.to_html(CGI.new))
|
335
325
|
end
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
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)
|
data/test/test_helper.rb
ADDED
@@ -16,242 +16,269 @@ require 'htmlgrid/form'
|
|
16
16
|
require 'htmlgrid/list'
|
17
17
|
require 'htmlgrid/div'
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
50
|
+
class StubCompositeComponent < HtmlGrid::Component
|
51
|
+
def to_html(context)
|
52
|
+
context.a(@attributes) { 'brafoo' }
|
53
|
+
end
|
40
54
|
end
|
41
|
-
|
42
|
-
|
55
|
+
class StubComposite2 < HtmlGrid::Composite
|
56
|
+
COMPONENTS = {
|
57
|
+
[0, 0] => StubCompositeComponent,
|
58
|
+
}
|
43
59
|
end
|
44
|
-
|
45
|
-
|
46
|
-
"Baz#{@barcount}"
|
60
|
+
class StubComposite3 < StubComposite2
|
61
|
+
COMPONENT_CSS_MAP = {[0, 0, 4, 4] => 'standard'}
|
47
62
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
72
|
+
class StubCompositeModel
|
78
73
|
end
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
136
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
def initialize(foo)
|
153
|
-
@foo = foo
|
101
|
+
class StubCompositeColspan2 < HtmlGrid::Composite
|
102
|
+
COMPONENTS = {
|
103
|
+
[0, 0] => :foo,
|
104
|
+
}
|
154
105
|
end
|
155
|
-
|
156
|
-
|
106
|
+
class StubCompositeColspan3 < HtmlGrid::Composite
|
107
|
+
COMPONENTS = {
|
108
|
+
[0, 0] => :foo,
|
109
|
+
[1, 0] => :bar,
|
110
|
+
}
|
157
111
|
end
|
158
|
-
|
159
|
-
|
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
|
164
|
-
|
165
|
-
|
166
|
-
|
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
|
-
|
194
|
-
|
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
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
end
|
213
|
-
|
214
|
-
|
215
|
-
|
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
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
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
|
-
|
223
|
-
|
224
|
-
|
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
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
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
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
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> </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
|