Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/common/print_options_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
require 'selenium/webdriver/common/print_options'
22
23
module Selenium
24
module WebDriver
25
describe PrintOptions do
26
let(:options) { described_class.new }
27
28
it 'has default values' do
29
expect(options.orientation).to eq('portrait')
30
expect(options.scale).to eq(1.0)
31
expect(options.background).to be(false)
32
expect(options.page_size).to eq({width: 21.0, height: 29.7})
33
expect(options.margins).to eq({top: 1.0, bottom: 1.0, left: 1.0, right: 1.0})
34
end
35
36
it 'can set custom page size' do
37
custom_size = {width: 25.0, height: 30.0}
38
options.page_size = custom_size
39
expect(options.page_size).to eq(custom_size)
40
end
41
42
it 'can set predefined page sizes using symbols' do
43
options.page_size = :a4
44
expect(options.page_size).to eq({width: 21.0, height: 29.7})
45
46
options.page_size = :legal
47
expect(options.page_size).to eq({width: 21.59, height: 35.56})
48
49
options.page_size = :tabloid
50
expect(options.page_size).to eq({width: 27.94, height: 43.18})
51
52
options.page_size = :letter
53
expect(options.page_size).to eq({width: 21.59, height: 27.94})
54
end
55
56
it 'raises an error for unsupported predefined page size symbols' do
57
expect { options.page_size = :invalid }.to raise_error(ArgumentError, /Invalid page size/)
58
end
59
60
it 'can convert to a hash' do
61
options.scale = 0.5
62
options.background = true
63
options.page_ranges = '1-3'
64
hash = options.to_h
65
66
expect(hash).to eq(
67
{
68
orientation: 'portrait',
69
scale: 0.5,
70
background: true,
71
pageRanges: '1-3',
72
paperWidth: 21.0,
73
paperHeight: 29.7,
74
marginTop: 1.0,
75
marginBottom: 1.0,
76
marginLeft: 1.0,
77
marginRight: 1.0
78
}
79
)
80
end
81
end
82
end
83
end
84
85