/
attachment_link_spec.rb
88 lines (77 loc) · 2.21 KB
/
attachment_link_spec.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 "rails_helper"
describe "Attachment Link", type: :view do
def component_name
"attachment_link"
end
it "fails to render when no attachment is given" do
assert_raises do
render_component({})
end
end
it "renders an attachment link" do
render_component(attachment: { title: "Attachment", url: "https://gov.uk/attachment" })
assert_select ".gem-c-attachment-link"
assert_select "a[href='https://gov.uk/attachment']", text: "Attachment"
end
it "can have a target specified" do
render_component(
attachment: { title: "Attachment", url: "attachment" },
target: "_blank",
)
assert_select "a[href=attachment][target=_blank]"
end
it "can include attribute metadata" do
render_component(
attachment: {
title: "Attachment",
url: "attachment",
content_type: "text/xml",
filename: "attachment.xml",
file_size: 2048,
number_of_pages: 2,
},
)
assert_select "abbr.gem-c-attachment-link__abbr[title='XML Document']", text: "XML"
expect(rendered).to match(/2 KB/)
expect(rendered).to match(/2 pages/)
end
it "can show file type that doesn't have an abbreviation" do
render_component(
attachment: {
title: "Attachment",
url: "attachment",
content_type: "text/plain",
},
)
expect(rendered).to match(/Plain Text/)
end
it "embeds any specified data attributes into the link" do
render_component(
attachment: {
title: "Attachment",
url: "attachment",
},
data_attributes: { gtm: "attachment-preview" },
)
assert_select "a.govuk-link[data-gtm='attachment-preview']"
end
it "does not have a newline character after the last metadata attribute's closing span tag" do
render_component(
attachment: {
title: "Attachment",
url: "attachment",
content_type: "text/plain",
},
)
expect(rendered).to end_with("</span>)</span>")
end
it "does not have any newline characters after the link element" do
render_component(
attachment: {
title: "Attachment",
url: "attachment",
},
)
expect(rendered).not_to match(/<\/a>\n/)
end
end