Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/common/interactions/scroll_spec.rb
1865 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require File.expand_path('../../spec_helper', __dir__)
21
22
module Selenium
23
module WebDriver
24
module Interactions
25
describe Scroll do
26
let(:source) { Interactions.wheel('scroll') }
27
let(:element) { instance_double(Element) }
28
let(:origin) { :viewport }
29
let(:duration) { 0.5 }
30
let(:x) { 25 }
31
let(:y) { 50 }
32
let(:delta_x) { 30 }
33
let(:delta_y) { 60 }
34
let(:scroll) do
35
described_class.new(source: source,
36
duration: duration,
37
delta_x: delta_x,
38
delta_y: delta_y,
39
origin: origin,
40
x: x,
41
y: y)
42
end
43
44
describe '#initialize' do
45
it 'raises a TypeError if source is not a Wheel' do
46
key = Interactions.key('key')
47
expect { described_class.new(source: key) }.to raise_error(TypeError)
48
end
49
end
50
51
describe '#type' do
52
it 'equals :scroll' do
53
expect(scroll.type).to eq(:scroll)
54
end
55
end
56
57
describe '#encode' do
58
context 'with element' do
59
it 'returns a Hash with source, duration, x and y' do
60
scroll = described_class.new(source: source,
61
duration: duration,
62
delta_x: delta_x,
63
delta_y: delta_y,
64
origin: element,
65
x: x,
66
y: y)
67
allow(element).to receive(:is_a?).with(Element).and_return(true)
68
69
expect(scroll.encode).to eq('type' => 'scroll',
70
'origin' => element,
71
'duration' => (duration * 1000).to_i,
72
'x' => x,
73
'y' => y,
74
'deltaX' => delta_x,
75
'deltaY' => delta_y)
76
end
77
end
78
79
context 'with viewport origin' do
80
it 'returns a Hash valid attributes' do
81
expect(scroll.encode).to eq('type' => 'scroll',
82
'origin' => 'viewport',
83
'duration' => (duration * 1000).to_i,
84
'x' => x,
85
'y' => y,
86
'deltaX' => delta_x,
87
'deltaY' => delta_y)
88
end
89
end
90
end
91
end
92
end # Interactions
93
end # WebDriver
94
end # Selenium
95
96