domkey 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,118 @@
1
+ require 'spec_helper'
2
+
3
+ describe Domkey::View::LabeledGroup do
4
+
5
+ class LabeledGroupExampleView
6
+ include Domkey::View
7
+
8
+ def radio_group
9
+ RadioGroup.new -> { radios(name: 'tool') }
10
+ end
11
+
12
+ #labeled radio_group with tool: as semantic descriptor
13
+ def tool
14
+ LabeledGroup.new(radio_group)
15
+ end
16
+
17
+ def checkbox_group
18
+ CheckboxGroup.new -> { checkboxes(name: 'fruit') }
19
+ end
20
+
21
+ #labeled checkbox_group with fruit: as semantic descriptor
22
+ def fruit
23
+ LabeledGroup.new(checkbox_group)
24
+ end
25
+ end
26
+
27
+ let(:view) { LabeledGroupExampleView.new }
28
+
29
+ before :all do
30
+ goto_html("test.html")
31
+ end
32
+
33
+ context 'radio group' do
34
+
35
+ context 'wrapped directly' do
36
+
37
+ it 'set string' do
38
+ view.tool.set 'Tomato'
39
+ view.tool.value.should eql ['Tomato']
40
+ end
41
+
42
+ it 'set regex' do
43
+ view.tool.set /umber$/
44
+ view.tool.value.should eql ['Cucumber']
45
+ end
46
+
47
+ it 'set array' do
48
+ view.tool.set ['Tomato', 'Cucumber']
49
+ view.tool.value.should eql ['Cucumber']
50
+ end
51
+
52
+ it 'set array string and regex' do
53
+ view.tool.set ['Tomato', /cumber$/]
54
+ view.tool.value.should eql ['Cucumber']
55
+ end
56
+
57
+ it 'set value text not found should error' do
58
+ expect { view.tool.set 'yepyep' }.to raise_error
59
+ end
60
+
61
+ it 'set value regexp not found should error' do
62
+ expect { view.tool.set /fofofo/ }.to raise_error
63
+ end
64
+
65
+ it 'options' do
66
+ view.tool.options.should eql ["Cucumber", "Tomato", "Other"]
67
+ end
68
+
69
+ end
70
+
71
+ context 'to_labeled' do
72
+
73
+ it 'set string' do
74
+ view.tool.to_labeled.set 'Tomato'
75
+ view.tool.to_labeled.value.should eql ['Tomato']
76
+ end
77
+
78
+ it 'set array' do
79
+ view.tool.to_labeled.set ['Tomato', 'Cucumber']
80
+ view.tool.to_labeled.value.should eql ['Cucumber']
81
+ end
82
+
83
+ end
84
+ end
85
+
86
+ context 'checkbox group' do
87
+
88
+ context 'wrapped directly' do
89
+
90
+ it 'set single' do
91
+ view.fruit.set 'Tomatorama'
92
+ view.fruit.value.should eql ['Tomatorama']
93
+ end
94
+
95
+ it 'set array' do
96
+ view.fruit.set ['Tomatorama', 'Cucumberama']
97
+ view.fruit.value.should eql ['Cucumberama', 'Tomatorama']
98
+ end
99
+
100
+ it 'options' do
101
+ view.fruit.options.should eql ["Cucumberama", "Tomatorama", "Other"]
102
+ end
103
+ end
104
+
105
+ context 'to_labeled' do
106
+
107
+ it 'set single' do
108
+ view.fruit.to_labeled.set 'Tomatorama'
109
+ view.fruit.to_labeled.value.should eql ['Tomatorama']
110
+ end
111
+
112
+ it 'set array' do
113
+ view.fruit.to_labeled.set ['Tomatorama', 'Cucumberama']
114
+ view.fruit.to_labeled.value.should eql ['Cucumberama', 'Tomatorama']
115
+ end
116
+ end
117
+ end
118
+ end
@@ -3,26 +3,26 @@ require 'spec_helper'
3
3
  describe Domkey::View::PageObjectCollection do
4
4
 
5
5
  before :all do
6
- Domkey.browser.goto("file://" + __dir__ + "/html/test.html")
6
+ goto_html("test.html")
7
7
  end
8
8
 
9
9
  it 'init error' do
10
- # TODO. tighter scope what can be a watirproc
10
+ # TODO. tighter scope what can be a package
11
11
  expect { Domkey::View::PageObjectCollection.new 'foo' }.to raise_error(Domkey::Exception::Error)
12
12
  end
13
13
 
14
14
  context 'when container is browser by default' do
15
15
 
16
- context 'watirproc is watirproc defining collection' do
16
+ context 'package is package defining collection' do
17
17
 
18
18
  before :each do
19
- # watirproc is definition of watir collection
20
- # watirproc when instantiated must respond to :each
19
+ # package is definition of watir collection
20
+ # package when instantiated must respond to :each
21
21
  # test sample:
22
22
  # we have 3 text_fields with class that begins with street
23
- watirproc = lambda { text_fields(class: /^street/) }
23
+ package = lambda { text_fields(class: /^street/) }
24
24
 
25
- @cbs = Domkey::View::PageObjectCollection.new watirproc
25
+ @cbs = Domkey::View::PageObjectCollection.new package
26
26
  end
27
27
 
28
28
  it 'count or size' do
@@ -63,7 +63,7 @@ describe Domkey::View::PageObjectCollection do
63
63
 
64
64
  end
65
65
 
66
- context 'watirproc is hash' do
66
+ context 'package is hash' do
67
67
 
68
68
  before :all do
69
69
  # would we do that? give me all text_fields :street and all text_fields :city ? in one collection?
@@ -74,10 +74,10 @@ describe Domkey::View::PageObjectCollection do
74
74
  Domkey.browser.text_fields(class: /^city/).count.should == 4
75
75
 
76
76
  # when I define my keyed collection
77
- watirproc = {street: lambda { text_fields(class: /^street/) },
78
- city: lambda { text_fields(class: /^city/) }}
77
+ package = {street: lambda { text_fields(class: /^street/) },
78
+ city: lambda { text_fields(class: /^city/) }}
79
79
 
80
- @cbs = Domkey::View::PageObjectCollection.new watirproc
80
+ @cbs = Domkey::View::PageObjectCollection.new package
81
81
  end
82
82
 
83
83
  it 'count' do
@@ -115,11 +115,11 @@ describe Domkey::View::PageObjectCollection do
115
115
 
116
116
  end
117
117
 
118
- context 'watirproc is pageobjectcollection' do
118
+ context 'package is pageobjectcollection' do
119
119
 
120
120
  it 'initialize' do
121
- watirproc = lambda { text_fields(class: /^street/) }
122
- pageobjectcollection = Domkey::View::PageObjectCollection.new watirproc
121
+ package = lambda { text_fields(class: /^street/) }
122
+ pageobjectcollection = Domkey::View::PageObjectCollection.new package
123
123
 
124
124
  @cbs = Domkey::View::PageObjectCollection.new pageobjectcollection
125
125
  end
@@ -1,32 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
- # domain specific page objects composed from regular page object
4
- # PageObject is a type of object that responds to set and value.
5
- # it is the Role it plays
6
- # DateSelector is a type of decoration for domain specific pageobject
7
- module Domkey
8
3
 
9
- module View
4
+ describe 'PageObject Decorators' do
10
5
 
11
- #example of specialized domain specific pageobject.
12
- # behavior of set and value
13
- class DateSelectorPageObject < PageObject
6
+ # domain specific page objects composed from regular page object
7
+ # PageObject is a type of object that responds to set and value.
8
+ # it is the Role it plays
9
+ # DateSelector is a type of decoration for domain specific pageobject
14
10
 
15
- def set value
16
- watirproc.each_pair { |k, po| po.set(value.send(k)) }
17
- end
18
11
 
19
- def value
20
- h = {}
21
- watirproc.each_pair { |k, po| h[k] = po.value }
22
- Date.parse "%s/%s/%s" % [h[:year], h[:month], h[:day]]
23
- end
12
+ #example of specialized domain specific pageobject.
13
+ # behavior of set and value
14
+ class DateSelectorPageObject < Domkey::View::PageObject
15
+
16
+ def set value
17
+ package.each_pair { |k, po| po.set(value.send(k)) }
24
18
  end
25
- end
26
- end
27
19
 
20
+ def value
21
+ h = {}
22
+ package.each_pair { |k, po| h[k] = po.value }
23
+ Date.parse "%s/%s/%s" % [h[:year], h[:month], h[:day]]
24
+ end
25
+ end
28
26
 
29
- module DomkeySpecHelper
30
27
 
31
28
  class CheckboxTextField
32
29
 
@@ -77,27 +74,23 @@ module DomkeySpecHelper
77
74
  h = pageobject.value
78
75
  Date.parse "%s/%s/%s" % [h[:year], h[:month], h[:day]]
79
76
  end
80
-
81
77
  end
82
78
 
83
- end
84
-
85
- describe 'PageObject Decorators' do
86
79
 
87
80
  before :all do
88
- Domkey.browser.goto("file://" + __dir__ + "/html/test.html")
81
+ goto_html("test.html")
89
82
  end
90
83
 
91
84
  context 'DateSelector' do
92
85
 
93
- it 'as pageobject component wrapped by decorator' do
86
+ it 'as pageobject component wrapped by composite' do
94
87
 
95
88
  watir_object = {day: lambda { text_field(id: 'day_field') },
96
89
  month: lambda { text_field(id: 'month_field') },
97
90
  year: lambda { text_field(id: 'year_field') }}
98
91
 
99
92
  foo = Domkey::View::PageObject.new watir_object
100
- dmy = DomkeySpecHelper::DateSelector.new foo
93
+ dmy = DateSelector.new foo
101
94
 
102
95
  dmy.set Date.today
103
96
  dmy.value.should eql Date.today
@@ -110,7 +103,7 @@ describe 'PageObject Decorators' do
110
103
  year: lambda { text_field(id: 'year_field') }}
111
104
 
112
105
  #foo = Domkey::Page::PageObject.new watir_object, @container
113
- dmy = Domkey::View::DateSelectorPageObject.new watir_object
106
+ dmy = DateSelectorPageObject.new watir_object
114
107
 
115
108
  dmy.set Date.today
116
109
  dmy.value.should eql Date.today
@@ -118,36 +111,32 @@ describe 'PageObject Decorators' do
118
111
 
119
112
  end
120
113
 
121
-
122
114
  context 'CheckboxTextField' do
123
115
 
116
+ it 'as pageobject component wrapped by composite' do
124
117
 
125
- it 'as pageobject component wrapped by decorator' do
126
-
127
- watir_object = {switch: lambda { checkbox(id: 'feature_checkbox1') },
128
- blurb: lambda { text_field(id: 'feature_textarea1') }}
129
-
130
- #pageobject as component
131
- foo = Domkey::View::PageObject.new watir_object
132
-
133
- foo.set switch: true, blurb: 'I am a blurb'
134
- foo.set switch: false
135
- foo.set switch: true
118
+ pageobject = Domkey::View::PageObject.new switch: -> { checkbox(id: 'feature_checkbox1') },
119
+ blurb: -> { textarea(id: 'feature_textarea1') }
136
120
 
137
- # decorator add specific behavior to set and value methods
138
- tbcf = DomkeySpecHelper::CheckboxTextField.new foo
121
+ # turn switch on and enter text in text area
122
+ pageobject.set switch: true, blurb: 'I am a blurb text after you turn on switch'
123
+ pageobject.set switch: false # => turn switch off, clear textarea blurb entry
124
+ pageobject.set switch: true # => turn switch on
139
125
 
140
- tbcf.set true
141
- tbcf.set false
142
- tbcf.set 'hhkhkjhj'
126
+ # wrap with composite and handle specific behavior to set and value
127
+ cbtf = CheckboxTextField.new(pageobject)
143
128
 
129
+ cbtf.set true
130
+ cbtf.set false
131
+ cbtf.set 'Domain Specific Behavior to set value - check checkbox and enter text'
132
+ cbtf.value.should eql('Domain Specific Behavior to set value - check checkbox and enter text')
144
133
  end
145
134
 
146
135
  context 'building array of CheckboxTextFields in the view' do
147
136
 
148
137
  it 'algorithm from predictable pattern' do
149
138
 
150
- #given predictable pattern that singals the presence of pageobjects
139
+ #given predictable pattern that signals the presence of pageobjects
151
140
  divs = Domkey::View::PageObjectCollection.new lambda { divs(:id, /^feature_/) }
152
141
 
153
142
  features = divs.map do |div|
@@ -156,19 +145,19 @@ describe 'PageObject Decorators' do
156
145
  id = div.element.id.split("_").last
157
146
 
158
147
  #definiton for each PageObject
159
- watir_object = {switch: lambda { checkbox(id: "feature_checkbox#{id}") },
160
- blurb: lambda { text_field(id: "feature_textarea#{id}") },
161
- label: lambda { label(for: "feature_checkbox#{id}") }}
148
+ watir_object = {switch: -> { checkbox(id: "feature_checkbox#{id}") },
149
+ blurb: -> { text_field(id: "feature_textarea#{id}") },
150
+ label: -> { label(for: "feature_checkbox#{id}") }}
162
151
 
163
152
  pageobject = Domkey::View::PageObject.new watir_object
164
153
  #domain specific pageobject
165
- DomkeySpecHelper::CheckboxTextField.new(pageobject)
154
+ CheckboxTextField.new(pageobject)
166
155
  end
167
156
 
168
157
  # array of Domain Specific PageObjects
169
158
  features.first.set 'bla'
170
159
  features.map { |e| e.value }.should eql ["bla", false]
171
- features.map { |e| e.pageobject.element(:label).text }.should eql ["Nude Beach", "Golf Course"]
160
+ features.map { |e| e.pageobject.element(:label).text }.should eql ["Enable Checkbox for TextArea", "Golf Course"]
172
161
  features.find { |e| e.label == 'Golf Course' }.value.should be_false
173
162
  end
174
163
 
@@ -187,7 +176,7 @@ describe 'PageObject Decorators' do
187
176
  pageobject = PageObject.new switch: -> { checkbox(id: "feature_checkbox#{i}") },
188
177
  blurb: -> { text_field(id: "feature_textarea#{i}") },
189
178
  label: -> { label(for: "feature_checkbox#{i}") }
190
- DomkeySpecHelper::CheckboxTextField.new(pageobject)
179
+ CheckboxTextField.new(pageobject)
191
180
  end
192
181
  end
193
182
 
@@ -6,35 +6,36 @@ require 'spec_helper'
6
6
  describe Domkey::View::PageObject do
7
7
 
8
8
  before :all do
9
- Domkey.browser.goto("file://" + __dir__ + "/html/test.html")
9
+ goto_html("test.html")
10
10
  end
11
11
 
12
12
  context 'exceptions' do
13
13
 
14
- it 'bad proc for watirproc argument' do
14
+ it 'bad proc for package argument' do
15
15
  expect { Domkey::View::PageObject.new lambda { 'foo' } }.to raise_error(Domkey::Exception::Error)
16
16
  end
17
17
 
18
- it 'bad object for watirproc argument' do
18
+ it 'bad object for package argument' do
19
19
  expect { Domkey::View::PageObject.new(Object.new) }.to raise_error(Domkey::Exception::Error)
20
20
  end
21
21
  end
22
22
 
23
23
  context 'when container is browser by default and' do
24
24
 
25
- it 'watirproc is watirproc' do
26
- watirproc = lambda { text_field(id: 'street1') }
27
- street = Domkey::View::PageObject.new watirproc
25
+ it 'package is package' do
26
+ package = lambda { text_field(id: 'street1') }
27
+ street = Domkey::View::PageObject.new package
28
28
 
29
- street.watirproc.should be_kind_of(Proc)
29
+ street.package.should be_kind_of(Proc)
30
30
  street.element.should be_kind_of(Watir::TextField) #one default element
31
31
 
32
32
  # talk to browser
33
33
  street.set 'Lamar'
34
34
  street.value.should eql 'Lamar'
35
+ street.options.should be_empty # by default options are empty
35
36
  end
36
37
 
37
- it 'watirproc is pageobject' do
38
+ it 'package is pageobject' do
38
39
  # setup
39
40
  watir_object = lambda { text_field(id: 'street1') }
40
41
  pageobject = Domkey::View::PageObject.new watir_object
@@ -42,22 +43,23 @@ describe Domkey::View::PageObject do
42
43
  # test
43
44
  street = Domkey::View::PageObject.new pageobject
44
45
 
45
- street.watirproc.should be_kind_of(Proc)
46
+ street.package.should be_kind_of(Proc)
46
47
  street.element.should be_kind_of(Watir::TextField)
47
48
 
48
49
 
49
50
  # talk to browser
50
51
  street.set 'zooom' #sending string here so no hash like in composed object
51
52
  street.value.should eql 'zooom'
53
+ street.options.should be_empty
52
54
  end
53
55
 
54
- it 'watirproc is proc hash where values are watirprocs' do
55
- hash = {street1: lambda { text_field(id: 'street1') }, city: lambda { text_field(id: 'city1') }}
56
- watirproc = lambda { hash }
57
- address = Domkey::View::PageObject.new watirproc
56
+ it 'package is proc hash where values are packages' do
57
+ hash = {street1: lambda { text_field(id: 'street1') }, city: lambda { text_field(id: 'city1') }}
58
+ package = lambda { hash }
59
+ address = Domkey::View::PageObject.new package
58
60
 
59
- address.watirproc.should respond_to(:each_pair)
60
- address.watirproc.each_pair do |k, v|
61
+ address.package.should respond_to(:each_pair)
62
+ address.package.each_pair do |k, v|
61
63
  k.should be_kind_of(Symbol)
62
64
  v.should be_kind_of(Domkey::View::PageObject) #should respond to set and value
63
65
  end
@@ -67,16 +69,17 @@ describe Domkey::View::PageObject do
67
69
  v.should be_kind_of(Watir::TextField) #resolve suitecase
68
70
  end
69
71
 
72
+ address.options.should eql({:street1=>[], :city=>[]})
70
73
  end
71
74
 
72
- it 'watirproc is hash where values are watirprocs' do
75
+ it 'package is hash where values are packages' do
73
76
 
74
77
  hash = {street1: lambda { text_field(id: 'street1') }, city: lambda { text_field(id: 'city1') }}
75
78
 
76
79
  address = Domkey::View::PageObject.new hash
77
80
 
78
- address.watirproc.should respond_to(:each_pair)
79
- address.watirproc.each_pair do |k, v|
81
+ address.package.should respond_to(:each_pair)
82
+ address.package.each_pair do |k, v|
80
83
  k.should be_kind_of(Symbol)
81
84
  v.should be_kind_of(Domkey::View::PageObject) #should respond to set and value
82
85
  end
@@ -120,6 +123,8 @@ describe Domkey::View::PageObject do
120
123
  e = lambda { text_field(class: 'city') }
121
124
  city = Domkey::View::PageObject.new e, container
122
125
  city.set 'Hellocontainer'
126
+ city.value.should eql 'Hellocontainer'
127
+ city.options.should be_empty
123
128
 
124
129
  #verify
125
130
  Domkey.browser.div(:id, 'container').text_field(:class, 'city').value.should == 'Hellocontainer'