Path: blob/trunk/rb/spec/unit/selenium/webdriver/common/print_options_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__)20require 'selenium/webdriver/common/print_options'2122module Selenium23module WebDriver24describe PrintOptions do25let(:options) { described_class.new }2627it 'has default values' do28expect(options.orientation).to eq('portrait')29expect(options.scale).to eq(1.0)30expect(options.background).to be(false)31expect(options.page_size).to eq({width: 21.0, height: 29.7})32expect(options.margins).to eq({top: 1.0, bottom: 1.0, left: 1.0, right: 1.0})33end3435it 'can set custom page size' do36custom_size = {width: 25.0, height: 30.0}37options.page_size = custom_size38expect(options.page_size).to eq(custom_size)39end4041it 'can set predefined page sizes using symbols' do42options.page_size = :a443expect(options.page_size).to eq({width: 21.0, height: 29.7})4445options.page_size = :legal46expect(options.page_size).to eq({width: 21.59, height: 35.56})4748options.page_size = :tabloid49expect(options.page_size).to eq({width: 27.94, height: 43.18})5051options.page_size = :letter52expect(options.page_size).to eq({width: 21.59, height: 27.94})53end5455it 'raises an error for unsupported predefined page size symbols' do56expect { options.page_size = :invalid }.to raise_error(ArgumentError, /Invalid page size/)57end5859it 'can convert to a hash' do60options.scale = 0.561options.background = true62options.page_ranges = '1-3'63hash = options.to_h6465expect(hash).to eq(66{67orientation: 'portrait',68scale: 0.5,69background: true,70pageRanges: '1-3',71paperWidth: 21.0,72paperHeight: 29.7,73marginTop: 1.0,74marginBottom: 1.0,75marginLeft: 1.0,76marginRight: 1.077}78)79end80end81end82end838485