Path: blob/trunk/rb/spec/unit/selenium/webdriver/common/interactions/interaction_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 Interactions24class NewDevice < InputDevice25def initialize(name = nil)26super27@type = :special28end2930def create_special(val)31add_action(NewInteraction.new(self, val))32end33end3435class NewInteraction < Interaction36def initialize(source, special)37super(source)38@special = special39@type = :newType40end4142def assert_source(source)43raise TypeError, "#{source.type} is not a valid input type" unless source.is_a? NewDevice44end4546def encode47{type: type, special: @special}48end49end5051class SubActionBuilder < ActionBuilder52def special_action(special, device: nil)53special_input(device).create_special(special)54self55end5657private5859def special_input(name = nil)60device(name: name, type: :newType) || add_input(NewDevice.new('new'))61end62end6364describe Interaction do65it 'can create subclass' do66bridge = instance_double(Remote::Bridge)67allow(bridge).to receive(:send_actions)68sub_action_builder = SubActionBuilder.new(bridge)69sub_action_builder.special_action('special').perform7071expect(bridge).to have_received(:send_actions).with([{type: :special,72id: 'new',73actions: [{type: :newType,74special: 'special'}]}])75end7677it 'raises a NotImplementedError if not a subclass' do78expect { described_class.new(NoneInput.new) }.to raise_error(NotImplementedError)79end80end81end # Interactions82end # WebDriver83end # Selenium848586