forked from sclevine/agouti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselection_properties_test.go
281 lines (241 loc) · 10.2 KB
/
selection_properties_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
package agouti_test
import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/sclevine/agouti"
"github.com/sclevine/agouti/api"
"github.com/sclevine/agouti/internal/element"
. "github.com/sclevine/agouti/internal/matchers"
"github.com/sclevine/agouti/internal/mocks"
)
var _ = Describe("Selection Properties", func() {
var (
selection *MultiSelection
session *mocks.Session
elementRepository *mocks.ElementRepository
firstElement *mocks.Element
secondElement *mocks.Element
)
BeforeEach(func() {
session = &mocks.Session{}
firstElement = &mocks.Element{}
secondElement = &mocks.Element{}
elementRepository = &mocks.ElementRepository{}
selection = NewTestMultiSelection(session, elementRepository, "#selector")
})
Describe("#Text", func() {
BeforeEach(func() {
elementRepository.GetExactlyOneCall.ReturnElement = firstElement
})
It("should successfully return the text", func() {
firstElement.GetTextCall.ReturnText = "some text"
Expect(selection.Text()).To(Equal("some text"))
})
Context("when the element repository fails to return exactly one element", func() {
It("should return an error", func() {
elementRepository.GetExactlyOneCall.Err = errors.New("some error")
_, err := selection.Text()
Expect(err).To(MatchError("failed to select element from selection 'CSS: #selector': some error"))
})
})
Context("when the session fails to retrieve the element text", func() {
It("should return an error", func() {
firstElement.GetTextCall.Err = errors.New("some error")
_, err := selection.Text()
Expect(err).To(MatchError("failed to retrieve text for selection 'CSS: #selector': some error"))
})
})
})
Describe("#Active", func() {
BeforeEach(func() {
elementRepository.GetExactlyOneCall.ReturnElement = firstElement
})
It("should successfully compare the active and selected elements", func() {
activeElement := &api.Element{}
session.GetActiveElementCall.ReturnElement = activeElement
_, err := selection.Active()
Expect(err).NotTo(HaveOccurred())
Expect(firstElement.IsEqualToCall.Element).To(ExactlyEqual(activeElement))
})
Context("when the active element equals the selected element", func() {
It("should successfully return true", func() {
firstElement.IsEqualToCall.ReturnEquals = true
Expect(selection.Active()).To(BeTrue())
})
})
Context("when the active element does not equal the selected element", func() {
It("should successfully return false", func() {
firstElement.IsEqualToCall.ReturnEquals = false
Expect(selection.Active()).To(BeFalse())
})
})
Context("when the element repository fails to return exactly one element", func() {
It("should return an error", func() {
elementRepository.GetExactlyOneCall.Err = errors.New("some error")
_, err := selection.Active()
Expect(err).To(MatchError("failed to select element from selection 'CSS: #selector': some error"))
})
})
Context("when the session fails to retrieve the active element", func() {
It("should return an error", func() {
session.GetActiveElementCall.Err = errors.New("some error")
_, err := selection.Active()
Expect(err).To(MatchError("failed to retrieve active element: some error"))
})
})
Context("when the session fails to compare active element to the selected element", func() {
It("should return an error", func() {
firstElement.IsEqualToCall.Err = errors.New("some error")
_, err := selection.Active()
Expect(err).To(MatchError("failed to compare selection to active element: some error"))
})
})
})
Describe("#Attribute", func() {
BeforeEach(func() {
elementRepository.GetExactlyOneCall.ReturnElement = firstElement
})
It("should request the attribute value using the attribute name", func() {
_, err := selection.Attribute("some-attribute")
Expect(err).NotTo(HaveOccurred())
Expect(firstElement.GetAttributeCall.Attribute).To(Equal("some-attribute"))
})
It("should successfully return the attribute value", func() {
firstElement.GetAttributeCall.ReturnValue = "some value"
Expect(selection.Attribute("some-attribute")).To(Equal("some value"))
})
Context("when the element repository fails to return exactly one element", func() {
It("should return an error", func() {
elementRepository.GetExactlyOneCall.Err = errors.New("some error")
_, err := selection.Attribute("some-attribute")
Expect(err).To(MatchError("failed to select element from selection 'CSS: #selector': some error"))
})
})
Context("when the session fails to retrieve the requested element attribute", func() {
It("should return an error", func() {
firstElement.GetAttributeCall.Err = errors.New("some error")
_, err := selection.Attribute("some-attribute")
Expect(err).To(MatchError("failed to retrieve attribute value for selection 'CSS: #selector': some error"))
})
})
})
Describe("#CSS", func() {
BeforeEach(func() {
elementRepository.GetExactlyOneCall.ReturnElement = firstElement
})
It("should request the CSS property value using the property name", func() {
_, err := selection.CSS("some-property")
Expect(err).NotTo(HaveOccurred())
Expect(firstElement.GetCSSCall.Property).To(Equal("some-property"))
})
It("should successfully return the property value", func() {
firstElement.GetCSSCall.ReturnValue = "some value"
Expect(selection.CSS("some-property")).To(Equal("some value"))
})
Context("when the element repository fails to return exactly one element", func() {
It("should return an error", func() {
elementRepository.GetExactlyOneCall.Err = errors.New("some error")
_, err := selection.CSS("some-property")
Expect(err).To(MatchError("failed to select element from selection 'CSS: #selector': some error"))
})
})
Context("when the the session fails to retrieve the requested element CSS property", func() {
It("should return an error", func() {
firstElement.GetCSSCall.Err = errors.New("some error")
_, err := selection.CSS("some-property")
Expect(err).To(MatchError("failed to retrieve CSS property value for selection 'CSS: #selector': some error"))
})
})
})
Describe("#Selected", func() {
BeforeEach(func() {
elementRepository.GetAtLeastOneCall.ReturnElements = []element.Element{firstElement, secondElement}
})
It("should return true when all elements are selected", func() {
firstElement.IsSelectedCall.ReturnSelected = true
secondElement.IsSelectedCall.ReturnSelected = true
Expect(selection.Selected()).To(BeTrue())
})
It("should return false when any elements are not selected", func() {
firstElement.IsSelectedCall.ReturnSelected = true
secondElement.IsSelectedCall.ReturnSelected = false
Expect(selection.Selected()).To(BeFalse())
})
Context("when the element repository fails to return at least one element", func() {
It("should return an error", func() {
elementRepository.GetAtLeastOneCall.Err = errors.New("some error")
_, err := selection.Selected()
Expect(err).To(MatchError("failed to select elements from selection 'CSS: #selector': some error"))
})
})
Context("when the the session fails to retrieve any elements' selected status", func() {
It("should return an error", func() {
firstElement.IsSelectedCall.ReturnSelected = true
secondElement.IsSelectedCall.Err = errors.New("some error")
_, err := selection.Selected()
Expect(err).To(MatchError("failed to determine whether selection 'CSS: #selector' is selected: some error"))
})
})
})
Describe("#Visible", func() {
BeforeEach(func() {
elementRepository.GetAtLeastOneCall.ReturnElements = []element.Element{firstElement, secondElement}
})
It("should return true when all elements are visible", func() {
firstElement.IsDisplayedCall.ReturnDisplayed = true
secondElement.IsDisplayedCall.ReturnDisplayed = true
Expect(selection.Visible()).To(BeTrue())
})
It("should return false when any elements are not visible", func() {
firstElement.IsDisplayedCall.ReturnDisplayed = true
secondElement.IsDisplayedCall.ReturnDisplayed = false
Expect(selection.Visible()).To(BeFalse())
})
Context("when the element repository fails to return at least one element", func() {
It("should return an error", func() {
elementRepository.GetAtLeastOneCall.Err = errors.New("some error")
_, err := selection.Visible()
Expect(err).To(MatchError("failed to select elements from selection 'CSS: #selector': some error"))
})
})
Context("when the the session fails to retrieve any elements' visible status", func() {
It("should return an error", func() {
firstElement.IsDisplayedCall.ReturnDisplayed = true
secondElement.IsDisplayedCall.Err = errors.New("some error")
_, err := selection.Visible()
Expect(err).To(MatchError("failed to determine whether selection 'CSS: #selector' is visible: some error"))
})
})
})
Describe("#Enabled", func() {
BeforeEach(func() {
elementRepository.GetAtLeastOneCall.ReturnElements = []element.Element{firstElement, secondElement}
})
It("should return true when all elements are enabled", func() {
firstElement.IsEnabledCall.ReturnEnabled = true
secondElement.IsEnabledCall.ReturnEnabled = true
Expect(selection.Enabled()).To(BeTrue())
})
It("should return false when any elements are not enabled", func() {
firstElement.IsEnabledCall.ReturnEnabled = true
secondElement.IsEnabledCall.ReturnEnabled = false
Expect(selection.Enabled()).To(BeFalse())
})
Context("when the element repository fails to return at least one element", func() {
It("should return an error", func() {
elementRepository.GetAtLeastOneCall.Err = errors.New("some error")
_, err := selection.Enabled()
Expect(err).To(MatchError("failed to select elements from selection 'CSS: #selector': some error"))
})
})
Context("when the the session fails to retrieve any element's enabled status", func() {
It("should return an error", func() {
firstElement.IsEnabledCall.ReturnEnabled = true
secondElement.IsEnabledCall.Err = errors.New("some error")
_, err := selection.Enabled()
Expect(err).To(MatchError("failed to determine whether selection 'CSS: #selector' is enabled: some error"))
})
})
})
})