-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
helper_test.rb
88 lines (73 loc) · 3.16 KB
/
helper_test.rb
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
require "test_helper"
class HelperTest < ActionView::TestCase
tests Webpacker::Helper
attr_reader :request
def setup
@request = Class.new do
def send_early_hints(links) end
def base_url
"https://example.com"
end
end.new
end
def test_asset_pack_path
assert_equal "/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_path("bootstrap.js")
assert_equal "/packs/bootstrap-c38deda30895059837cf.css", asset_pack_path("bootstrap.css")
Webpacker.config.stub :extract_css?, false do
assert_nil asset_pack_path("bootstrap.css")
assert_equal "/packs/application-k344a6d59eef8632c9d1.png", asset_pack_path("application.png")
end
end
def test_asset_pack_url
assert_equal "https://example.com/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_url("bootstrap.js")
assert_equal "https://example.com/packs/bootstrap-c38deda30895059837cf.css", asset_pack_url("bootstrap.css")
Webpacker.config.stub :extract_css?, false do
assert_nil asset_pack_path("bootstrap.css")
assert_equal "https://example.com/packs/application-k344a6d59eef8632c9d1.png", asset_pack_url("application.png")
end
end
def test_image_pack_tag
assert_equal \
"<img alt=\"Edit Entry\" src=\"/packs/application-k344a6d59eef8632c9d1.png\" width=\"16\" height=\"10\" />",
image_pack_tag("application.png", size: "16x10", alt: "Edit Entry")
end
def test_javascript_pack_tag
assert_equal \
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
javascript_pack_tag("bootstrap.js")
end
def test_javascript_pack_tag_symbol
assert_equal \
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
javascript_pack_tag(:bootstrap)
end
def test_javascript_pack_tag_splat
assert_equal \
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>\n) +
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
javascript_pack_tag("bootstrap.js", "application.js", defer: true)
end
def test_javascript_pack_tag_split_chunks
assert_equal \
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>),
javascript_pack_tag("application")
end
def test_stylesheet_pack_tag
assert_equal \
%(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
stylesheet_pack_tag("bootstrap.css")
end
def test_stylesheet_pack_tag_symbol
assert_equal \
%(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
stylesheet_pack_tag(:bootstrap)
end
def test_stylesheet_pack_tag_splat
assert_equal \
%(<link rel="stylesheet" media="all" href="/packs/bootstrap-c38deda30895059837cf.css" />\n) +
%(<link rel="stylesheet" media="all" href="/packs/application-dd6b1cd38bfa093df600.css" />),
stylesheet_pack_tag("bootstrap.css", "application.css", media: "all")
end
end