Path: blob/trunk/rb/spec/unit/selenium/webdriver/common/fedcm/dialog_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 FedCM24describe Dialog do25let(:bridge) { instance_double(Remote::Bridge) }26let(:dialog) { described_class.new(bridge) }2728describe '#click' do29it 'calls click_fedcm_dialog on the bridge' do30allow(bridge).to receive(:click_fedcm_dialog_button).and_return(nil)31expect(dialog.click).to be_nil32end33end3435describe '#cancel' do36it 'calls cancel_fedcm_dialog on the bridge' do37allow(bridge).to receive(:cancel_fedcm_dialog).and_return(nil)38expect(dialog.cancel).to be_nil39end40end4142describe '#select_account' do43it 'calls select_fedcm_account on the bridge with the given index' do44index = 145allow(bridge).to receive(:select_fedcm_account).with(index).and_return(nil)46expect(dialog.select_account(index)).to be_nil47end48end4950describe '#type' do51it 'returns the type of the open dialog' do52allow(bridge).to receive(:fedcm_dialog_type).and_return('AccountChooser')53expect(dialog.type).to eq('AccountChooser')54end55end5657describe '#title' do58it 'returns the title of the dialog' do59allow(bridge).to receive(:fedcm_title).and_return('Sign in')60expect(dialog.title).to eq('Sign in')61end62end6364describe '#subtitle' do65it 'returns the subtitle of the dialog' do66allow(bridge).to receive(:fedcm_subtitle).and_return('Choose an account')67expect(dialog.subtitle).to eq('Choose an account')68end6970it 'returns nil if there is no subtitle' do71allow(bridge).to receive(:fedcm_subtitle).and_return(nil)72expect(dialog.subtitle).to be_nil73end74end7576describe '#accounts' do77it 'returns the accounts shown in the account chooser' do78accounts_data = [{'name' => 'Account1', 'email' => '[email protected]'},79{'name' => 'Account2', 'email' => '[email protected]'}]80allow(bridge).to receive(:fedcm_account_list).and_return(accounts_data)81accounts = dialog.accounts82expect(accounts.size).to eq(2)83expect(accounts[0].name).to eq('Account1')84expect(accounts[0].email).to eq('[email protected]')85expect(accounts[1].name).to eq('Account2')86expect(accounts[1].email).to eq('[email protected]')87end88end89end # Dialog90end # FedCM91end # WebDriver92end # Selenium939495