Path: blob/trunk/rb/spec/unit/selenium/webdriver/common/interactions/scroll_spec.rb
1865 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require File.expand_path('../../spec_helper', __dir__)2021module Selenium22module WebDriver23module Interactions24describe Scroll do25let(:source) { Interactions.wheel('scroll') }26let(:element) { instance_double(Element) }27let(:origin) { :viewport }28let(:duration) { 0.5 }29let(:x) { 25 }30let(:y) { 50 }31let(:delta_x) { 30 }32let(:delta_y) { 60 }33let(:scroll) do34described_class.new(source: source,35duration: duration,36delta_x: delta_x,37delta_y: delta_y,38origin: origin,39x: x,40y: y)41end4243describe '#initialize' do44it 'raises a TypeError if source is not a Wheel' do45key = Interactions.key('key')46expect { described_class.new(source: key) }.to raise_error(TypeError)47end48end4950describe '#type' do51it 'equals :scroll' do52expect(scroll.type).to eq(:scroll)53end54end5556describe '#encode' do57context 'with element' do58it 'returns a Hash with source, duration, x and y' do59scroll = described_class.new(source: source,60duration: duration,61delta_x: delta_x,62delta_y: delta_y,63origin: element,64x: x,65y: y)66allow(element).to receive(:is_a?).with(Element).and_return(true)6768expect(scroll.encode).to eq('type' => 'scroll',69'origin' => element,70'duration' => (duration * 1000).to_i,71'x' => x,72'y' => y,73'deltaX' => delta_x,74'deltaY' => delta_y)75end76end7778context 'with viewport origin' do79it 'returns a Hash valid attributes' do80expect(scroll.encode).to eq('type' => 'scroll',81'origin' => 'viewport',82'duration' => (duration * 1000).to_i,83'x' => x,84'y' => y,85'deltaX' => delta_x,86'deltaY' => delta_y)87end88end89end90end91end # Interactions92end # WebDriver93end # Selenium949596