domkey 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,212 @@
1
+ require 'spec_helper'
2
+
3
+ describe Domkey::View::SelectList do
4
+
5
+ class SelectListExampleView
6
+
7
+ include Domkey::View
8
+
9
+ def multilist
10
+ SelectList.new -> { select_list(id: 'multiselect') }
11
+ end
12
+
13
+ def singlelist
14
+ SelectList.new -> { select_list(id: 'fruit_list') }
15
+ end
16
+
17
+ end
18
+
19
+ context "Multi" do
20
+
21
+ before :all do
22
+ view = SelectListExampleView.new
23
+ @widget = view.multilist
24
+ end
25
+
26
+ before :each do
27
+ goto_html("test.html")
28
+ end
29
+
30
+ it 'initial value on the test page' do
31
+ @widget.value.should eql ["English", "Norwegian"]
32
+ end
33
+
34
+ it 'initial value by keys on the test page' do
35
+ # array
36
+ @widget.value([:index, :text, :value]).should eql [{:index=>1, :text=>"English", :value=>"2"}, {:index=>2, :text=>"Norwegian", :value=>"3"}]
37
+ # splat list
38
+ @widget.value(:index, :text).should eql [{:index=>1, :text=>"English"}, {:index=>2, :text=>"Norwegian"}]
39
+
40
+ # one element array
41
+ @widget.value([:index]).should eql [{:index=>1}, {:index=>2}]
42
+ # one elmenet splat list
43
+ @widget.value(:value).should eql [{:value=>"2"}, {:value=>"3"}]
44
+
45
+ end
46
+
47
+ it 'set string' do
48
+ @widget.set 'Polish'
49
+ end
50
+
51
+ it 'set array string or regexp' do
52
+ # texts are items visible to the user [text or label of select list option]
53
+ @widget.set ['Polish', 'Norwegian']
54
+ @widget.value.should eql ["Norwegian", "Polish"]
55
+ end
56
+
57
+ it 'set false clears all. value is empty array' do
58
+ @widget.set false
59
+ @widget.value.should eql []
60
+ end
61
+
62
+ it 'set empty array clears all. value is empty array' do
63
+ @widget.set []
64
+ @widget.value.should eql []
65
+ end
66
+
67
+ it 'set string clears all. sets one text item. value is one item' do
68
+ @widget.set 'Polish'
69
+ @widget.value.should eql ["Polish"]
70
+ end
71
+
72
+ it 'set string' do
73
+ @widget.set text: 'Polish'
74
+ @widget.value.should eql ["Polish"]
75
+ end
76
+
77
+ it 'set regexp' do
78
+ @widget.set text: /olish/
79
+ @widget.value.should eql ["Polish"]
80
+ end
81
+
82
+ it 'set by array of texts' do
83
+ @widget.set text: ['Polish', /orwegia/]
84
+ @widget.value.should eql ["Norwegian", "Polish"]
85
+ end
86
+
87
+ it 'set index by option position' do
88
+ @widget.set index: 1
89
+ @widget.value.should eql ['English']
90
+ @widget.value(:index, :value).should eql [{index: 1, value: '2'}]
91
+ end
92
+
93
+ it 'set index array of option positions' do
94
+ @widget.set index: [0, 2]
95
+ @widget.value.should eql ["Danish", "Norwegian"]
96
+ end
97
+
98
+ it 'set value attribute string' do
99
+ @widget.set value: '2'
100
+ @widget.value.should eql ['English']
101
+ end
102
+
103
+ it 'set value attribute array of strings' do
104
+ @widget.set value: ['2', '1']
105
+ @widget.value.should eql ["Danish", "English"]
106
+ end
107
+
108
+ it 'set by many qualifiers at once' do
109
+ @widget.set value: ['2', '1'],
110
+ text: 'Swedish',
111
+ index: 3
112
+ @widget.value.should eql ['Danish', 'English', 'Polish', 'Swedish']
113
+ end
114
+
115
+ it 'options' do
116
+ @widget.options.should eql [{:text=>"Danish", :value=>"1", :index=>0},
117
+ {:text=>"English", :value=>"2", :index=>1},
118
+ {:text=>"Norwegian", :value=>"3", :index=>2},
119
+ {:text=>"Polish", :value=>"", :index=>3},
120
+ {:text=>"Swedish", :value=>"Swedish", :index=>4}]
121
+ end
122
+
123
+ context "Single" do
124
+
125
+ before :all do
126
+ view = SelectListExampleView.new
127
+ @widget = view.singlelist
128
+ end
129
+
130
+ before :each do
131
+ goto_html("test.html")
132
+ end
133
+
134
+ it 'initial value is text visible to the user' do
135
+ @widget.value.should eql ['Default']
136
+ end
137
+
138
+ it 'value keys' do
139
+ @widget.value([:index, :value, :text]).should eql [{index: 3, value: 'Default', text: 'Default'}]
140
+ end
141
+
142
+ it 'set string selects visible text. value is visible text to the user' do
143
+ @widget.set 'Tomato'
144
+ @widget.value.should eql ['Tomato']
145
+
146
+ @widget.set 'Other'
147
+ @widget.value.should eql ['Other']
148
+ end
149
+
150
+ it 'set array of text or label' do
151
+ @widget.set ['Other', 'Tomato'] #cycle on single select list
152
+ @widget.value.should eql ['Tomato'] # the last one set
153
+ end
154
+
155
+ it 'set by array of text' do
156
+ @widget.set text: ['Other', 'Tomato']
157
+ @widget.value.should eql ['Tomato']
158
+ end
159
+
160
+ it 'set false has no effect. value is selected item text' do
161
+ @widget.set false
162
+ @widget.value.should eql ['Default']
163
+ end
164
+
165
+ it 'set empty array has no effect. value is selected item text' do
166
+ @widget.set []
167
+ @widget.value.should eql ['Default']
168
+ end
169
+
170
+ it 'set index position' do
171
+ @widget.set index: 1
172
+ @widget.value.should eql ['Cucumber']
173
+ end
174
+
175
+ it 'set index array' do
176
+ @widget.set index: [0, 2]
177
+ @widget.value.should eql ['Other'] # the last one wins
178
+ end
179
+
180
+ it 'set value attribute string' do
181
+ @widget.set value: 'tomato'
182
+ @widget.value.should eql ['Tomato']
183
+ end
184
+
185
+ it 'set value attribute array of strings' do
186
+ @widget.set value: ['tomato', 'gurken']
187
+ @widget.value.should eql ['Cucumber']
188
+ end
189
+
190
+ it 'set by many qualifiers at once' do
191
+ @widget.set value: ['gurken'],
192
+ text: 'Tomato',
193
+ index: 2
194
+ @widget.value.should eql ['Other']
195
+ end
196
+
197
+ it 'options' do
198
+
199
+ expected = [{:text=>"Tomato", :value=>"tomato", :index=>0},
200
+ {:text=>"Cucumber", :value=>"gurken", :index=>1},
201
+ {:text=>"Other", :value=>"", :index=>2},
202
+ {:text=>"Default", :value=>"Default", :index=>3}]
203
+
204
+ @widget.options.should eql(expected)
205
+
206
+ end
207
+
208
+ end
209
+
210
+ end
211
+
212
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rubytester
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-02 00:00:00.000000000 Z
12
+ date: 2014-04-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
@@ -107,26 +107,30 @@ files:
107
107
  - lib/domkey/view/checkbox_group.rb
108
108
  - lib/domkey/view/label_mapper.rb
109
109
  - lib/domkey/view/labeled_group.rb
110
+ - lib/domkey/view/option_selectable.rb
111
+ - lib/domkey/view/option_selectable_group.rb
110
112
  - lib/domkey/view/page_object.rb
111
113
  - lib/domkey/view/page_object_collection.rb
112
114
  - lib/domkey/view/radio_group.rb
113
- - lib/domkey/view/watir_widget.rb
114
- - lib/domkey/view/widgetry_package.rb
115
+ - lib/domkey/view/select_list.rb
116
+ - lib/domkey/view/widgetry/dispatcher.rb
117
+ - lib/domkey/view/widgetry/package.rb
115
118
  - spec/browser_spec.rb
116
119
  - spec/checkbox_group_spec.rb
117
120
  - spec/html/test.html
118
121
  - spec/labeled_group_spec.rb
122
+ - spec/option_selectable_spec.rb
119
123
  - spec/page_object_collection_spec.rb
120
124
  - spec/page_object_decorators_spec.rb
121
125
  - spec/page_object_spec.rb
122
126
  - spec/page_spec.rb
123
127
  - spec/radio_group_spec.rb
128
+ - spec/select_list_spec.rb
124
129
  - spec/selenium_webdriver_api_example.rb
125
130
  - spec/spec_helper.rb
126
131
  - spec/view_cargo_spec.rb
127
132
  - spec/view_dom_spec.rb
128
133
  - spec/view_doms_spec.rb
129
- - spec/watir_widget_select_spec.rb
130
134
  - spec/watirspec_pageobjects/watirspec_spec.rb
131
135
  homepage: ''
132
136
  licenses:
@@ -157,15 +161,16 @@ test_files:
157
161
  - spec/checkbox_group_spec.rb
158
162
  - spec/html/test.html
159
163
  - spec/labeled_group_spec.rb
164
+ - spec/option_selectable_spec.rb
160
165
  - spec/page_object_collection_spec.rb
161
166
  - spec/page_object_decorators_spec.rb
162
167
  - spec/page_object_spec.rb
163
168
  - spec/page_spec.rb
164
169
  - spec/radio_group_spec.rb
170
+ - spec/select_list_spec.rb
165
171
  - spec/selenium_webdriver_api_example.rb
166
172
  - spec/spec_helper.rb
167
173
  - spec/view_cargo_spec.rb
168
174
  - spec/view_dom_spec.rb
169
175
  - spec/view_doms_spec.rb
170
- - spec/watir_widget_select_spec.rb
171
176
  - spec/watirspec_pageobjects/watirspec_spec.rb
@@ -1,106 +0,0 @@
1
- module Domkey
2
-
3
- module View
4
-
5
- # @api private
6
- class WatirWidget
7
-
8
- def initialize(object)
9
- @object = object
10
- object_class_name = @object.class.name.split('::').last
11
- @set_method = "set_%s" % object_class_name
12
- @value_method = "value_%s" % object_class_name
13
- @options_method = "options_%s" % object_class_name
14
- end
15
-
16
- def set value
17
- return __send__(@set_method, value) if respond_to?(@set_method, true)
18
- @object.set value
19
- end
20
-
21
- def value
22
- return __send__(@value_method) if respond_to?(@value_method, true)
23
- @object.value
24
- end
25
-
26
- def options
27
- return __send__(@options_method) if respond_to?(@options_method, true)
28
- opts = @object.options
29
- opts.count == 0 ? [] : opts
30
- end
31
-
32
- private
33
-
34
- def options_Select
35
- @object.options.map do |o|
36
- {text: o.text,
37
- value: o.value}
38
- end
39
- end
40
-
41
- # for Watir::Select
42
- # @param [String] text or label to be selected. Text visible to the user on the page
43
- # @param [Array<String>] collection for multiselect to select
44
- def set_Select value
45
- @object.clear if @object.multiple?
46
- set_Select_strategy value
47
- end
48
-
49
- def set_Select_strategy value
50
- case value
51
- when String
52
- @object.select value
53
- when Array
54
- value.each { |v| set_Select_strategy v }
55
- when Hash
56
- value.each_pair do |how, what|
57
-
58
- #-- select by option position: can be one or many index: 0, index: [0,1,2,3]
59
- if how == :index
60
- case what
61
- when Fixnum
62
- @object.options[what].select
63
- when Array
64
- what.each do |i|
65
- @object.options[i].select
66
- end
67
- end
68
- end
69
-
70
- #-- select by option value: attribute (invisible to the user)
71
- if how == :value
72
- case what
73
- when String
74
- @object.select_value what
75
- when Array
76
- what.each { |v| @object.select_value v }
77
- end
78
- end
79
-
80
- #-- select by text visible to the user. This is the same as default set 'Text' behavior
81
- if how == :text
82
- case what
83
- when String
84
- set_Select_strategy what
85
- when Array
86
- what.each { |v| set_Select_strategy v }
87
- end
88
- end
89
-
90
- end
91
-
92
- end
93
-
94
- end
95
-
96
- # @return [String] text or label from Select, not actual 'value' attribute?
97
- # @return [Array<String>] collection for multiselect list
98
- # @return [False] when nothing selected in multiselect list
99
- def value_Select
100
- @object.selected_options.map { |o| o.text }
101
- end
102
-
103
-
104
- end
105
- end
106
- end
@@ -1,48 +0,0 @@
1
- module Domkey
2
-
3
- module View
4
-
5
- module WidgetryPackage
6
-
7
- attr_accessor :package, :container
8
-
9
- # initialize PageObject or PageObjectCollection
10
- # for PageObject expects WebdriverElement a single element definition i.e text_field, checkbox
11
- # for PageObjectCollection expects WebdriverElement a collection definition i.e. text_fields, checkboxes
12
- # @param package [Proc(WebdriverElement)]
13
- # @param package [PageObject]
14
- # @param package [Hash{Symbol => Proc(WebdriverElement)]
15
- # @param package [Hash{Symbol => PageObject]
16
- def initialize package, container=lambda { Domkey.browser }
17
- @container = container
18
- @package = initialize_this package
19
- end
20
-
21
- # access widgetry of watir elements composing this page object
22
- # @param [Symbol] (false)
23
- # @return [Hash{Symbol => WebdriverElement}]
24
- # @return [WebdriverElement]
25
- def element(key=false)
26
- return instantiator unless package.respond_to?(:each_pair)
27
- return package.fetch(key).element if key
28
- Hash[package.map { |key, package| [key, package.element] }]
29
- end
30
-
31
- private
32
-
33
- # talks to the browser
34
- # returns runtime element in a specified container
35
- # @return [WebdriverElement]
36
- def instantiator
37
- container_instantiator.instance_exec(&package)
38
- end
39
-
40
- # talks to the browser
41
- # returns runtime container element in a browser/driver
42
- # @return [WebdriverElement]
43
- def container_instantiator
44
- container.respond_to?(:call) ? container.call : container.send(:instantiator)
45
- end
46
- end
47
- end
48
- end
@@ -1,176 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Domkey::View::WatirWidget do
4
-
5
- context Watir::Select do
6
-
7
- context "Multi" do
8
-
9
- before :all do
10
- @object = Domkey.browser.select(id: 'multiselect')
11
- @widget = Domkey::View::WatirWidget.new(@object)
12
- end
13
-
14
- before :each do
15
- goto_html("test.html")
16
- end
17
-
18
- it 'initial value on the test page' do
19
- @widget.value.should eql ["English", "Norwegian"]
20
- end
21
-
22
- it 'set array of strings clears all. sets text items provided. value is array of visible texts' do
23
- # texts are items visible to the user [text or label of select list option]
24
- @widget.set ['Polish', 'Norwegian']
25
- @widget.value.should eql ["Norwegian", "Polish"]
26
- end
27
-
28
- it 'set false clears all. value is empty array' do
29
- @widget.set false
30
- @widget.value.should eql []
31
- end
32
-
33
- it 'set empty array clears all. value is empty array' do
34
- @widget.set []
35
- @widget.value.should eql []
36
- end
37
-
38
- it 'set string clears all. sets one text item. value is one item' do
39
- @widget.set 'Polish'
40
- @widget.value.should eql ["Polish"]
41
- end
42
-
43
- it 'set by text' do
44
- @widget.set text: 'Polish'
45
- @widget.value.should eql ["Polish"]
46
- end
47
-
48
- it 'set by array of texts' do
49
- # client would not usually do this.
50
- # Client would simply call set ['Polish', 'Norwegian']
51
- # becuase text: qualifer is a default way of setting select list by visible text
52
- @widget.set text: ['Polish', 'Norwegian']
53
- @widget.value.should eql ["Norwegian", "Polish"]
54
- end
55
-
56
- it 'set index by option position' do
57
- @widget.set index: 1
58
- @widget.value.should eql ['English']
59
- end
60
-
61
- it 'set index array of option positions' do
62
- @widget.set index: [0, 2]
63
- @widget.value.should eql ["Danish", "Norwegian"]
64
- end
65
-
66
- it 'set value attribute string' do
67
- @widget.set value: '2'
68
- @widget.value.should eql ['English']
69
- end
70
-
71
- it 'set value attribute array of strings' do
72
- @widget.set value: ['2', '1']
73
- @widget.value.should eql ["Danish", "English"]
74
- end
75
-
76
- it 'set by many qualifiers at once' do
77
- @widget.set value: ['2', '1'],
78
- text: 'Swedish',
79
- index: 3
80
- @widget.value.should eql ['Danish', 'English', 'Polish', 'Swedish']
81
- end
82
-
83
- it 'options' do
84
- @widget.options.should eql [{:text=>"Danish", :value=>"1"},
85
- {:text=>"English", :value=>"2"},
86
- {:text=>"Norwegian", :value=>"3"},
87
- {:text=>"Polish", :value=>""},
88
- {:text=>"Swedish", :value=>"Swedish"}]
89
- end
90
-
91
- end
92
-
93
- context "Single" do
94
-
95
- before :all do
96
- object = Domkey.browser.select(id: 'fruit_list')
97
- @widget = Domkey::View::WatirWidget.new(object)
98
- end
99
-
100
- before :each do
101
- goto_html("test.html")
102
- end
103
-
104
- it 'initial value on the test page visible text to the user' do
105
- @widget.value.should eql ['Default']
106
- end
107
-
108
- it 'set string selects visible text. value is visible text to the user' do
109
- # option text
110
- @widget.set 'Tomato'
111
- @widget.value.should eql ['Tomato'] # not value attribute, visible text [text, label]
112
-
113
- # option label attribute text
114
- @widget.set 'Other'
115
- @widget.value.should eql ['Other']
116
- end
117
-
118
- it 'set array of text or label' do
119
- @widget.set ['Other', 'Tomato'] #cycle on single select list
120
- @widget.value.should eql ['Tomato'] # the last one set
121
- end
122
-
123
- it 'set by array of text' do
124
- @widget.set text: ['Other', 'Tomato']
125
- @widget.value.should eql ['Tomato']
126
- end
127
-
128
- it 'set false has no effect. value is selected item text' do
129
- @widget.set false
130
- @widget.value.should eql ['Default']
131
- end
132
-
133
- it 'set empty array has no effect. value is selected item text' do
134
- @widget.set []
135
- @widget.value.should eql ['Default']
136
- end
137
-
138
- it 'set index position' do
139
- @widget.set index: 1
140
- @widget.value.should eql ['Cucumber']
141
- end
142
-
143
- it 'set index array' do
144
- @widget.set index: [0, 2]
145
- @widget.value.should eql ['Other'] # the last one wins
146
- end
147
-
148
- it 'set value attribute string' do
149
- @widget.set value: 'tomato'
150
- @widget.value.should eql ['Tomato']
151
- end
152
-
153
- it 'set value attribute array of strings' do
154
- @widget.set value: ['tomato', 'gurken']
155
- @widget.value.should eql ['Cucumber']
156
- end
157
-
158
- it 'set by many qualifiers at once' do
159
- @widget.set value: ['gurken'],
160
- text: 'Tomato',
161
- index: 2
162
- @widget.value.should eql ['Other']
163
- end
164
-
165
- it 'options' do
166
- @widget.options.should eql [{:text=>"Tomato", :value=>"tomato"},
167
- {:text=>"Cucumber", :value=>"gurken"},
168
- {:text=>"Other", :value=>""},
169
- {:text=>"Default", :value=>"Default"}]
170
- end
171
-
172
- end
173
-
174
- end
175
-
176
- end