-
Notifications
You must be signed in to change notification settings - Fork 287
Expand file tree
/
Copy pathimage_spec.rb
More file actions
108 lines (89 loc) · 3.94 KB
/
Copy pathimage_spec.rb
File metadata and controls
108 lines (89 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require 'spec_helper'
require 'cloudinary'
require 'action_view'
require 'cloudinary/helper'
COMMON_TRANS = {
effect: 'sepia',
cloud_name: DUMMY_CLOUD,
client_hints: false
}
COMMON_TRANSFORMATION_STR = 'e_sepia'
def expected_srcset(public_id, path, common_trans, breakpoints)
breakpoints.map {|width| "#{path}/#{common_trans}/c_scale,w_#{width}/#{public_id} #{width}w"}.join(', ')
end
describe 'Responsive breakpoints' do
before :all do
# Test the helper in the context it runs in in production
ActionView::Base.send :include, CloudinaryHelper
end
before :each do
Cloudinary.reset_config
Cloudinary.config.analytics = false
end
let(:cloud_name) {COMMON_TRANS[:cloud_name]}
let(:root_path) {"https://res.cloudinary.com/#{cloud_name}"}
let(:upload_path) {"#{root_path}/image/upload"}
let(:options) {COMMON_TRANS}
let(:helper) {
ActionView::Base.new(ActionView::LookupContext.new([]), {}, nil)
}
let(:test_tag) {TestTag.new(helper.cl_image_tag('sample.jpg', options))}
describe 'srcset' do
it 'Should create srcset attribute with provided breakpoints' do
options[:srcset] = {:breakpoints => ResponsiveTest::BREAKPOINTS}
srcset = test_tag['srcset'].split(", ")
expect(srcset.length).to eq(4)
expected_tag = expected_srcset('sample.jpg', upload_path, COMMON_TRANSFORMATION_STR, ResponsiveTest::BREAKPOINTS)
expect(test_tag['srcset']).to match(expected_tag)
end
it "Support srcset attribute defined by min width max width and max images" do
options[:srcset] = {:min_width => ResponsiveTest::BREAKPOINTS.first,
:max_width => ResponsiveTest::BREAKPOINTS.last,
:max_images => ResponsiveTest::BREAKPOINTS.length}
expected_tag = expected_srcset('sample.jpg', upload_path, COMMON_TRANSFORMATION_STR, ResponsiveTest::BREAKPOINTS)
expect(test_tag['srcset']).to match(expected_tag)
end
it "should generate a single srcset image" do
options[:srcset] = {:min_width => ResponsiveTest::BREAKPOINTS.first,
:max_width => ResponsiveTest::BREAKPOINTS.last,
:max_images => 1}
expected_tag = expected_srcset('sample.jpg', upload_path, COMMON_TRANSFORMATION_STR, [ResponsiveTest::BREAKPOINTS.last])
expect(test_tag['srcset']).to match(expected_tag)
end
it "Should support custom transformation for srcset items" do
options[:srcset] = {
:breakpoints => ResponsiveTest::BREAKPOINTS,
:transformation => {:crop => 'crop', :width => 10, :height => 20}
}
expected_tag = expected_srcset('sample.jpg', upload_path, 'c_crop,h_20,w_10', ResponsiveTest::BREAKPOINTS)
expect(test_tag['srcset']).to match(expected_tag)
end
it "Should populate sizes attribute" do
options[:srcset] = {
:breakpoints => ResponsiveTest::BREAKPOINTS,
:sizes => true
}
expected_sizes_attr = '(max-width: 100px) 100px, (max-width: 200px) 200px, ' +
'(max-width: 300px) 300px, (max-width: 399px) 399px'
expect(test_tag['sizes']).to match(expected_sizes_attr)
end
it "Should support srcset string value" do
raw_src_set = "some srcset data as is"
options[:srcset] = raw_src_set
expect(test_tag['srcset']).to match(raw_src_set)
end
it "Should remove width and height attributes in case srcset is specified, but passed to transformation" do
options.merge!({
:srcset => {
:breakpoints => ResponsiveTest::BREAKPOINTS,
},
:width => 500,
:height => 500,
:crop => 'scale'
})
expected_tag = expected_srcset('sample.jpg', upload_path, 'c_scale,e_sepia,h_500,w_500', ResponsiveTest::BREAKPOINTS)
expect(test_tag['srcset']).to match(expected_tag)
expect(test_tag['width']).to be_nil
end
end
end