govspeak 6.5.0 → 6.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -2
  3. data/README.md +6 -5
  4. data/Rakefile +7 -4
  5. data/lib/govspeak.rb +116 -116
  6. data/lib/govspeak/header_extractor.rb +1 -1
  7. data/lib/govspeak/html_sanitizer.rb +12 -9
  8. data/lib/govspeak/kramdown_overrides.rb +2 -2
  9. data/lib/govspeak/link_extractor.rb +6 -6
  10. data/lib/govspeak/post_processor.rb +34 -14
  11. data/lib/govspeak/presenters/attachment_presenter.rb +39 -39
  12. data/lib/govspeak/presenters/contact_presenter.rb +2 -2
  13. data/lib/govspeak/presenters/h_card_presenter.rb +3 -3
  14. data/lib/govspeak/presenters/image_presenter.rb +4 -4
  15. data/lib/govspeak/structured_header_extractor.rb +2 -2
  16. data/lib/govspeak/version.rb +1 -1
  17. data/lib/kramdown/parser/govuk.rb +6 -7
  18. data/test/blockquote_extra_quote_remover_test.rb +24 -26
  19. data/test/govspeak_attachment_link_test.rb +0 -2
  20. data/test/govspeak_attachment_test.rb +0 -2
  21. data/test/govspeak_attachments_image_test.rb +12 -14
  22. data/test/govspeak_attachments_inline_test.rb +22 -24
  23. data/test/govspeak_button_test.rb +29 -31
  24. data/test/govspeak_contacts_test.rb +29 -31
  25. data/test/govspeak_extract_contact_content_ids_test.rb +1 -3
  26. data/test/govspeak_images_bang_test.rb +37 -39
  27. data/test/govspeak_images_test.rb +43 -45
  28. data/test/govspeak_link_extractor_test.rb +1 -1
  29. data/test/govspeak_link_test.rb +1 -3
  30. data/test/govspeak_structured_headers_test.rb +7 -6
  31. data/test/govspeak_table_with_headers_test.rb +68 -21
  32. data/test/govspeak_test.rb +98 -101
  33. data/test/govspeak_test_helper.rb +1 -1
  34. data/test/html_sanitizer_test.rb +17 -9
  35. data/test/html_validator_test.rb +2 -2
  36. data/test/presenters/h_card_presenter_test.rb +39 -41
  37. data/test/test_helper.rb +12 -8
  38. metadata +52 -40
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require "test_helper"
4
2
 
5
3
  class GovspeakAttachmentLinkTest < Minitest::Test
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require "test_helper"
4
2
 
5
3
  class GovspeakAttachmentTest < Minitest::Test
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require 'test_helper'
1
+ require "test_helper"
4
2
 
5
3
  class GovspeakAttachmentsImageTest < Minitest::Test
6
4
  def build_attachment(args = {})
@@ -17,7 +15,7 @@ class GovspeakAttachmentsImageTest < Minitest::Test
17
15
  end
18
16
 
19
17
  def compress_html(html)
20
- html.gsub(/[\n\r]+[\s]*/, '')
18
+ html.gsub(/[\n\r]+[\s]*/, "")
21
19
  end
22
20
 
23
21
  test "renders an empty string for an image attachment not found" do
@@ -27,7 +25,7 @@ class GovspeakAttachmentsImageTest < Minitest::Test
27
25
  test "wraps an attachment in a figure with the id if the id is present" do
28
26
  rendered = render_govspeak(
29
27
  "[embed:attachments:image:1fe8]",
30
- [build_attachment(id: 10, content_id: "1fe8")]
28
+ [build_attachment(id: 10, content_id: "1fe8")],
31
29
  )
32
30
  assert_match(/<figure id="attachment_10" class="image embedded">/, rendered)
33
31
  end
@@ -35,7 +33,7 @@ class GovspeakAttachmentsImageTest < Minitest::Test
35
33
  test "wraps an attachment in a figure without the id if the id is not present" do
36
34
  rendered = render_govspeak(
37
35
  "[embed:attachments:image:1fe8]",
38
- [build_attachment(id: nil, content_id: "1fe8")]
36
+ [build_attachment(id: nil, content_id: "1fe8")],
39
37
  )
40
38
  assert_match(/<figure class="image embedded">/, rendered)
41
39
  end
@@ -43,7 +41,7 @@ class GovspeakAttachmentsImageTest < Minitest::Test
43
41
  test "renders an attachment if there are spaces around the content_id" do
44
42
  rendered = render_govspeak(
45
43
  "[embed:attachments:image: 1fe8 ]",
46
- [build_attachment(id: 10, content_id: "1fe8")]
44
+ [build_attachment(id: 10, content_id: "1fe8")],
47
45
  )
48
46
  assert_match(/<figure id="attachment_10" class="image embedded">/, rendered)
49
47
  end
@@ -51,7 +49,7 @@ class GovspeakAttachmentsImageTest < Minitest::Test
51
49
  test "has an image element to the file" do
52
50
  rendered = render_govspeak(
53
51
  "[embed:attachments:image:1fe8]",
54
- [build_attachment(id: nil, url: "http://a.b/c.jpg", content_id: "1fe8")]
52
+ [build_attachment(id: nil, url: "http://a.b/c.jpg", content_id: "1fe8")],
55
53
  )
56
54
  assert_match(%r{<img.*src="http://a.b/c.jpg"}, rendered)
57
55
  end
@@ -59,7 +57,7 @@ class GovspeakAttachmentsImageTest < Minitest::Test
59
57
  test "renders the image title as an alt tag" do
60
58
  rendered = render_govspeak(
61
59
  "[embed:attachments:image:1fe8]",
62
- [build_attachment(id: nil, title: "My Title", content_id: "1fe8")]
60
+ [build_attachment(id: nil, title: "My Title", content_id: "1fe8")],
63
61
  )
64
62
  assert_match(%r{<img.*alt="My Title"}, rendered)
65
63
  end
@@ -67,7 +65,7 @@ class GovspeakAttachmentsImageTest < Minitest::Test
67
65
  test "can render a nil image title" do
68
66
  rendered = render_govspeak(
69
67
  "[embed:attachments:image:1fe8]",
70
- [build_attachment(id: nil, title: nil, content_id: "1fe8")]
68
+ [build_attachment(id: nil, title: nil, content_id: "1fe8")],
71
69
  )
72
70
  assert_match(%r{<img.*alt=""}, rendered)
73
71
  end
@@ -75,13 +73,13 @@ class GovspeakAttachmentsImageTest < Minitest::Test
75
73
  test "a full image attachment rendering looks correct" do
76
74
  rendered = render_govspeak(
77
75
  "[embed:attachments:image:1fe8]",
78
- [build_attachment(id: 10, url: "http://a.b/c.jpg", title: "My Title", content_id: "1fe8")]
76
+ [build_attachment(id: 10, url: "http://a.b/c.jpg", title: "My Title", content_id: "1fe8")],
79
77
  )
80
- expected_html_output = %{
78
+ expected_html_output = %(
81
79
  <figure id="attachment_10" class="image embedded">
82
80
  <div class="img"><img src="http://a.b/c.jpg" alt="My Title"></div>
83
81
  </figure>
84
- }
82
+ )
85
83
  assert_match(compress_html(expected_html_output), compress_html(rendered))
86
84
  end
87
85
 
@@ -89,7 +87,7 @@ class GovspeakAttachmentsImageTest < Minitest::Test
89
87
  test "can be rendered inside a table" do
90
88
  rendered = render_govspeak(
91
89
  "| [embed:attachments:image:1fe8] |",
92
- [build_attachment(content_id: "1fe8", id: nil)]
90
+ [build_attachment(content_id: "1fe8", id: nil)],
93
91
  )
94
92
 
95
93
  regex = %r{<td><figure class="image embedded"><div class="img">(.*?)</div></figure></td>}
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require 'test_helper'
1
+ require "test_helper"
4
2
 
5
3
  class GovspeakAttachmentsInlineTest < Minitest::Test
6
4
  def build_attachment(args = {})
@@ -23,7 +21,7 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
23
21
  test "wraps an attachment in a span with the id if the id is present" do
24
22
  rendered = render_govspeak(
25
23
  "[embed:attachments:inline:1fe8]",
26
- [build_attachment(id: 10, content_id: "1fe8")]
24
+ [build_attachment(id: 10, content_id: "1fe8")],
27
25
  )
28
26
  assert_match(/<span id="attachment_10" class="attachment-inline">/, rendered)
29
27
  end
@@ -31,7 +29,7 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
31
29
  test "wraps an attachment in a span without the id if the id is not present" do
32
30
  rendered = render_govspeak(
33
31
  "[embed:attachments:inline:1fe8]",
34
- [build_attachment(id: nil, content_id: "1fe8")]
32
+ [build_attachment(id: nil, content_id: "1fe8")],
35
33
  )
36
34
  assert_match(/<span class="attachment-inline">/, rendered)
37
35
  end
@@ -39,7 +37,7 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
39
37
  test "renders an attachment where the content id has spaces" do
40
38
  rendered = render_govspeak(
41
39
  "[embed:attachments:inline: 1fe8 ]",
42
- [build_attachment(id: nil, content_id: "1fe8")]
40
+ [build_attachment(id: nil, content_id: "1fe8")],
43
41
  )
44
42
  assert_match(/<span class="attachment-inline">/, rendered)
45
43
  end
@@ -47,7 +45,7 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
47
45
  test "links to the attachment file" do
48
46
  rendered = render_govspeak(
49
47
  "[embed:attachments:inline:1fe8]",
50
- [build_attachment(content_id: "1fe8", url: "http://a.b/f.pdf", title: "My Pdf")]
48
+ [build_attachment(content_id: "1fe8", url: "http://a.b/f.pdf", title: "My Pdf")],
51
49
  )
52
50
  assert_match(%r{<a href="http://a.b/f.pdf">My Pdf</a>}, rendered)
53
51
  end
@@ -55,7 +53,7 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
55
53
  test "renders with a nil title" do
56
54
  rendered = render_govspeak(
57
55
  "[embed:attachments:inline:1fe8]",
58
- [build_attachment(content_id: "1fe8", url: "http://a.b/f.pdf", title: nil)]
56
+ [build_attachment(content_id: "1fe8", url: "http://a.b/f.pdf", title: nil)],
59
57
  )
60
58
  assert_match(%r{<a href="http://a.b/f.pdf"></a>}, rendered)
61
59
  end
@@ -63,7 +61,7 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
63
61
  test "renders on a single line" do
64
62
  rendered = render_govspeak(
65
63
  "[embed:attachments:inline:2bc1]",
66
- [build_attachment(content_id: "2bc1", external?: true)]
64
+ [build_attachment(content_id: "2bc1", external?: true)],
67
65
  )
68
66
  assert_match(%r{<span id="attachment[^\n]*</span>}, rendered)
69
67
  end
@@ -71,7 +69,7 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
71
69
  test "doesn't have spaces between the span and the link" do
72
70
  rendered = render_govspeak(
73
71
  "[embed:attachments:inline:2bc1]",
74
- [build_attachment(content_id: "2bc1", id: nil)]
72
+ [build_attachment(content_id: "2bc1", id: nil)],
75
73
  )
76
74
  assert_match(%r{<span class="attachment-inline"><a href=".*">.*</a></span>}, rendered)
77
75
  end
@@ -79,7 +77,7 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
79
77
  test "will show HTML type (in brackets) if file_extension is specified as html" do
80
78
  rendered = render_govspeak(
81
79
  "[embed:attachments:inline:1fe8]",
82
- [build_attachment(content_id: "1fe8", file_extension: "html")]
80
+ [build_attachment(content_id: "1fe8", file_extension: "html")],
83
81
  )
84
82
  assert_match(%r{(<span class="type">HTML</span>)}, rendered)
85
83
  end
@@ -87,7 +85,7 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
87
85
  test "will show url (in brackets) if specified as external" do
88
86
  rendered = render_govspeak(
89
87
  "[embed:attachments:inline:1fe8]",
90
- [build_attachment(content_id: "1fe8", url: "http://a.b/f.pdf", external?: true)]
88
+ [build_attachment(content_id: "1fe8", url: "http://a.b/f.pdf", external?: true)],
91
89
  )
92
90
  assert_match(%r{(<span class="url">http://a.b/f.pdf</span>)}, rendered)
93
91
  end
@@ -95,7 +93,7 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
95
93
  test "will not show url if file_extension is specified as html" do
96
94
  rendered = render_govspeak(
97
95
  "[embed:attachments:inline:1fe8]",
98
- [build_attachment(content_id: "1fe8", url: "http://a.b/f.pdf", file_extension: "html", external?: true)]
96
+ [build_attachment(content_id: "1fe8", url: "http://a.b/f.pdf", file_extension: "html", external?: true)],
99
97
  )
100
98
  refute_match(%r{(<span class="url">http://a.b/f.pdf</span>)}, rendered)
101
99
  end
@@ -103,7 +101,7 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
103
101
  test "will show a file extension in a abbr element for non html" do
104
102
  rendered = render_govspeak(
105
103
  "[embed:attachments:inline:1fe8]",
106
- [build_attachment(content_id: "1fe8", file_extension: "csv")]
104
+ [build_attachment(content_id: "1fe8", file_extension: "csv")],
107
105
  )
108
106
  refute_match(%r{<span class="type"><abbr title="Comma-separated values">CSV</abbr></span>}, rendered)
109
107
  end
@@ -111,7 +109,7 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
111
109
  test "will show file size in a span" do
112
110
  rendered = render_govspeak(
113
111
  "[embed:attachments:inline:1fe8]",
114
- [build_attachment(content_id: "1fe8", file_size: 1024)]
112
+ [build_attachment(content_id: "1fe8", file_size: 1024)],
115
113
  )
116
114
  assert_match(%r{<span class="file-size">1 KB</span>}, rendered)
117
115
  end
@@ -119,12 +117,12 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
119
117
  test "will show number of pages" do
120
118
  rendered = render_govspeak(
121
119
  "[embed:attachments:inline:1fe8]",
122
- [build_attachment(content_id: "1fe8", number_of_pages: 1)]
120
+ [build_attachment(content_id: "1fe8", number_of_pages: 1)],
123
121
  )
124
122
  assert_match(%r{<span class="page-length">1 page</span>}, rendered)
125
123
  rendered = render_govspeak(
126
124
  "[embed:attachments:inline:1fe8]",
127
- [build_attachment(content_id: "1fe8", number_of_pages: 2)]
125
+ [build_attachment(content_id: "1fe8", number_of_pages: 2)],
128
126
  )
129
127
  assert_match(%r{<span class="page-length">2 pages</span>}, rendered)
130
128
  end
@@ -139,12 +137,12 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
139
137
  file_extension: "txt",
140
138
  file_size: 2048,
141
139
  number_of_pages: 2,
142
- )]
140
+ )],
143
141
  )
144
- link = %{<a href="#{Regexp.quote('http://a.b/test.txt')}">My Attached Text File</a>}
145
- type = %{<span class="type">Plain text</span>}
146
- file_size = %{<span class="file-size">2 KB</span>}
147
- pages = %{<span class="page-length">2 pages</span>}
142
+ link = %(<a href="#{Regexp.quote('http://a.b/test.txt')}">My Attached Text File</a>)
143
+ type = %(<span class="type">Plain text</span>)
144
+ file_size = %(<span class="file-size">2 KB</span>)
145
+ pages = %(<span class="page-length">2 pages</span>)
148
146
  assert_match(/#{link}\s+\(#{type}, #{file_size}, #{pages}\)/, rendered)
149
147
  end
150
148
 
@@ -153,8 +151,8 @@ class GovspeakAttachmentsInlineTest < Minitest::Test
153
151
  "[embed:attachments:inline:1fe8] and [embed:attachments:inline:2abc]",
154
152
  [
155
153
  build_attachment(content_id: "1fe8", url: "http://a.b/test.txt", title: "Text File"),
156
- build_attachment(content_id: "2abc", url: "http://a.b/test.pdf", title: "PDF File")
157
- ]
154
+ build_attachment(content_id: "2abc", url: "http://a.b/test.pdf", title: "PDF File"),
155
+ ],
158
156
  )
159
157
  assert_match(%r{<a href="http://a.b/test.txt">Text File</a>}, rendered)
160
158
  assert_match(%r{<a href="http://a.b/test.pdf">PDF File</a>}, rendered)
@@ -1,74 +1,72 @@
1
- # encoding: UTF-8
1
+ require "test_helper"
2
+ require "govspeak_test_helper"
2
3
 
3
- require 'test_helper'
4
- require 'govspeak_test_helper'
5
-
6
- require 'ostruct'
4
+ require "ostruct"
7
5
 
8
6
  class GovspeakTest < Minitest::Test
9
7
  include GovspeakTestHelper
10
8
 
11
9
  test_given_govspeak "{button start cross-domain-tracking:UA-23066786-5}[Start now](https://www.registertovote.service.gov.uk/register-to-vote/start){/button}" do
12
- assert_html_output '<p><a role="button" class="button button-start" href="https://www.registertovote.service.gov.uk/register-to-vote/start" data-module="cross-domain-tracking" data-tracking-code="UA-23066786-5" data-tracking-name="govspeakButtonTracker">Start now</a></p>'
10
+ assert_html_output '<p><a class="gem-c-button govuk-button govuk-button--start" role="button" data-module="cross-domain-tracking" data-tracking-code="UA-23066786-5" data-tracking-name="govspeakButtonTracker" href="https://www.registertovote.service.gov.uk/register-to-vote/start"> Start now <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>'
13
11
  assert_text_output "Start now"
14
12
  end
15
13
 
16
14
  # The same as above but with line breaks
17
15
  test_given_govspeak "{button start cross-domain-tracking:UA-23066786-5}\n\n\n[Start now](https://www.registertovote.service.gov.uk/register-to-vote/start)\n\n\n{/button}" do
18
- assert_html_output '<p><a role="button" class="button button-start" href="https://www.registertovote.service.gov.uk/register-to-vote/start" data-module="cross-domain-tracking" data-tracking-code="UA-23066786-5" data-tracking-name="govspeakButtonTracker">Start now</a></p>'
16
+ assert_html_output '<p><a class="gem-c-button govuk-button govuk-button--start" role="button" data-module="cross-domain-tracking" data-tracking-code="UA-23066786-5" data-tracking-name="govspeakButtonTracker" href="https://www.registertovote.service.gov.uk/register-to-vote/start"> Start now <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>'
19
17
  assert_text_output "Start now"
20
18
  end
21
19
 
22
20
  test_given_govspeak "{button cross-domain-tracking:UA-23066786-5}[Start now](https://www.registertovote.service.gov.uk/register-to-vote/start){/button}" do
23
- assert_html_output '<p><a role="button" class="button" href="https://www.registertovote.service.gov.uk/register-to-vote/start" data-module="cross-domain-tracking" data-tracking-code="UA-23066786-5" data-tracking-name="govspeakButtonTracker">Start now</a></p>'
21
+ assert_html_output '<p><a class="gem-c-button govuk-button" role="button" data-module="cross-domain-tracking" data-tracking-code="UA-23066786-5" data-tracking-name="govspeakButtonTracker" href="https://www.registertovote.service.gov.uk/register-to-vote/start">Start now</a></p>'
24
22
  assert_text_output "Start now"
25
23
  end
26
24
 
27
25
  test_given_govspeak "{button start}[Start now](https://www.registertovote.service.gov.uk/register-to-vote/start){/button}" do
28
- assert_html_output '<p><a role="button" class="button button-start" href="https://www.registertovote.service.gov.uk/register-to-vote/start">Start now</a></p>'
26
+ assert_html_output '<p><a class="gem-c-button govuk-button govuk-button--start" role="button" href="https://www.registertovote.service.gov.uk/register-to-vote/start"> Start now <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>'
29
27
  assert_text_output "Start now"
30
28
  end
31
29
 
32
30
  test_given_govspeak "{button}[Start now](https://www.registertovote.service.gov.uk/register-to-vote/start){/button}" do
33
- assert_html_output '<p><a role="button" class="button" href="https://www.registertovote.service.gov.uk/register-to-vote/start">Start now</a></p>'
31
+ assert_html_output '<p><a class="gem-c-button govuk-button" role="button" href="https://www.registertovote.service.gov.uk/register-to-vote/start">Start now</a></p>'
34
32
  assert_text_output "Start now"
35
33
  end
36
34
 
37
35
  # Test other text outputs
38
36
  test_given_govspeak "{button}[Something else](https://www.registertovote.service.gov.uk/register-to-vote/start){/button}" do
39
- assert_html_output '<p><a role="button" class="button" href="https://www.registertovote.service.gov.uk/register-to-vote/start">Something else</a></p>'
37
+ assert_html_output '<p><a class="gem-c-button govuk-button" role="button" href="https://www.registertovote.service.gov.uk/register-to-vote/start">Something else</a></p>'
40
38
  assert_text_output "Something else"
41
39
  end
42
40
 
43
41
  # Test that nothing renders when not given a link
44
42
  test_given_govspeak "{button}I shouldn't render a button{/button}" do
45
- assert_html_output '<p>{button}I shouldn’t render a button{/button}</p>'
43
+ assert_html_output "<p>{button}I shouldn’t render a button{/button}</p>"
46
44
  end
47
45
 
48
46
  test_given_govspeak "Text before the button with line breaks \n\n\n{button}[Start Now](http://www.gov.uk){/button}\n\n\n test after the button" do
49
- assert_html_output %{
47
+ assert_html_output %(
50
48
  <p>Text before the button with line breaks</p>
51
49
 
52
- <p><a role="button" class="button" href="http://www.gov.uk">Start Now</a></p>
50
+ <p><a class="gem-c-button govuk-button" role="button" href="http://www.gov.uk">Start Now</a></p>
53
51
 
54
52
  <p>test after the button</p>
55
- }
53
+ )
56
54
  assert_text_output "Text before the button with line breaks Start Now test after the button"
57
55
  end
58
56
 
59
57
  # Test README examples
60
58
  test_given_govspeak "{button}[Continue](https://gov.uk/random){/button}" do
61
- assert_html_output '<p><a role="button" class="button" href="https://gov.uk/random">Continue</a></p>'
59
+ assert_html_output '<p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>'
62
60
  assert_text_output "Continue"
63
61
  end
64
62
 
65
63
  test_given_govspeak "{button start}[Start Now](https://gov.uk/random){/button}" do
66
- assert_html_output '<p><a role="button" class="button button-start" href="https://gov.uk/random">Start Now</a></p>'
64
+ assert_html_output '<p><a class="gem-c-button govuk-button govuk-button--start" role="button" href="https://gov.uk/random"> Start Now <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>'
67
65
  assert_text_output "Start Now"
68
66
  end
69
67
 
70
68
  test_given_govspeak "{button start cross-domain-tracking:UA-XXXXXX-Y}[Start Now](https://example.com/external-service/start-now){/button}" do
71
- assert_html_output '<p><a role="button" class="button button-start" href="https://example.com/external-service/start-now" data-module="cross-domain-tracking" data-tracking-code="UA-XXXXXX-Y" data-tracking-name="govspeakButtonTracker">Start Now</a></p>'
69
+ assert_html_output '<p><a class="gem-c-button govuk-button govuk-button--start" role="button" data-module="cross-domain-tracking" data-tracking-code="UA-XXXXXX-Y" data-tracking-name="govspeakButtonTracker" href="https://example.com/external-service/start-now"> Start Now <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>'
72
70
  assert_text_output "Start Now"
73
71
  end
74
72
 
@@ -82,23 +80,23 @@ class GovspeakTest < Minitest::Test
82
80
 
83
81
  # Make sure button renders when typical linebreaks are before it, seen in publishing applications
84
82
  test_given_govspeak "{button}[Line breaks](https://gov.uk/random){/button}\r\n\r\n{button}[Continue](https://gov.uk/random){/button}\r\n\r\n{button}[Continue](https://gov.uk/random){/button}" do
85
- assert_html_output %{
86
- <p><a role="button" class="button" href="https://gov.uk/random">Line breaks</a></p>
83
+ assert_html_output %(
84
+ <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Line breaks</a></p>
87
85
 
88
- <p><a role="button" class="button" href="https://gov.uk/random">Continue</a></p>
86
+ <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>
89
87
 
90
- <p><a role="button" class="button" href="https://gov.uk/random">Continue</a></p>
91
- }
88
+ <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>
89
+ )
92
90
  end
93
91
 
94
92
  test_given_govspeak "{button}[More line breaks](https://gov.uk/random){/button}\n\n{button}[Continue](https://gov.uk/random){/button}\n\n{button}[Continue](https://gov.uk/random){/button}" do
95
- assert_html_output %{
96
- <p><a role="button" class="button" href="https://gov.uk/random">More line breaks</a></p>
93
+ assert_html_output %(
94
+ <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">More line breaks</a></p>
97
95
 
98
- <p><a role="button" class="button" href="https://gov.uk/random">Continue</a></p>
96
+ <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>
99
97
 
100
- <p><a role="button" class="button" href="https://gov.uk/random">Continue</a></p>
101
- }
98
+ <p><a class="gem-c-button govuk-button" role="button" href="https://gov.uk/random">Continue</a></p>
99
+ )
102
100
  end
103
101
 
104
102
  test_given_govspeak %{
@@ -114,7 +112,7 @@ class GovspeakTest < Minitest::Test
114
112
  lorem lorem lorem
115
113
  lorem lorem lorem
116
114
  } do
117
- assert_html_output %{
115
+ assert_html_output %(
118
116
  <h2 id="register-to-vote">Register to vote</h2>
119
117
 
120
118
  <p>Introduction text about the service.</p>
@@ -122,10 +120,10 @@ class GovspeakTest < Minitest::Test
122
120
  <p>lorem lorem lorem
123
121
  lorem lorem lorem</p>
124
122
 
125
- <p><a role="button" class="button button-start" href="https://gov.uk/random">Start Now</a></p>
123
+ <p><a class="gem-c-button govuk-button govuk-button--start" role="button" href="https://gov.uk/random"> Start Now <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewbox="0 0 33 40" role="presentation" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path></svg></a></p>
126
124
 
127
125
  <p>lorem lorem lorem
128
126
  lorem lorem lorem</p>
129
- }
127
+ )
130
128
  end
131
129
  end
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require 'test_helper'
1
+ require "test_helper"
4
2
 
5
3
  class GovspeakContactsTest < Minitest::Test
6
4
  def build_contact(attrs = {})
@@ -19,8 +17,8 @@ class GovspeakContactsTest < Minitest::Test
19
17
  region: "London",
20
18
  postal_code: "WC2B 6NH",
21
19
  world_location: "United Kingdom",
22
- }
23
- ]
20
+ },
21
+ ],
24
22
  ),
25
23
  email_addresses: attrs.fetch(
26
24
  :email_addresses,
@@ -28,8 +26,8 @@ class GovspeakContactsTest < Minitest::Test
28
26
  {
29
27
  title: "",
30
28
  email: "people@digital.cabinet-office.gov.uk",
31
- }
32
- ]
29
+ },
30
+ ],
33
31
  ),
34
32
  phone_numbers: attrs.fetch(
35
33
  :phone_numbers,
@@ -37,23 +35,23 @@ class GovspeakContactsTest < Minitest::Test
37
35
  {
38
36
  title: "helpdesk",
39
37
  number: "+4412345 67890",
40
- }
41
- ]
38
+ },
39
+ ],
42
40
  ),
43
41
  contact_form_links: attrs.fetch(
44
42
  :contact_form_links,
45
43
  [
46
44
  {
47
- link: "https://www.gov.uk/contact"
48
- }
49
- ]
50
- )
51
- }
45
+ link: "https://www.gov.uk/contact",
46
+ },
47
+ ],
48
+ ),
49
+ },
52
50
  }
53
51
  end
54
52
 
55
53
  def compress_html(html)
56
- html.gsub(/[\n\r]+[\s]*/, '')
54
+ html.gsub(/[\n\r]+[\s]*/, "")
57
55
  end
58
56
 
59
57
  test "contact is rendered when present in options[:contacts]" do
@@ -61,7 +59,7 @@ class GovspeakContactsTest < Minitest::Test
61
59
  govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
62
60
 
63
61
  rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
64
- expected_html_output = %{
62
+ expected_html_output = %(
65
63
  <div id="contact_4f3383e4-48a2-4461-a41d-f85ea8b89ba0" class="contact postal-address">
66
64
  <div class="content">
67
65
  <h3>Government Digital Service</h3>
@@ -89,7 +87,7 @@ class GovspeakContactsTest < Minitest::Test
89
87
  </div>
90
88
  </div>
91
89
  </div>
92
- }
90
+ )
93
91
 
94
92
  assert_equal(compress_html(expected_html_output), compress_html(rendered))
95
93
  end
@@ -105,7 +103,7 @@ class GovspeakContactsTest < Minitest::Test
105
103
  contact = build_contact(post_addresses: [])
106
104
  govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
107
105
  rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
108
- expected_html_output = %{
106
+ expected_html_output = %(
109
107
  <div id="contact_4f3383e4-48a2-4461-a41d-f85ea8b89ba0" class="contact">
110
108
  <div class="content">
111
109
  <h3>Government Digital Service</h3>
@@ -127,7 +125,7 @@ class GovspeakContactsTest < Minitest::Test
127
125
  </div>
128
126
  </div>
129
127
  </div>
130
- }
128
+ )
131
129
  assert_equal(compress_html(expected_html_output), compress_html(rendered))
132
130
  end
133
131
 
@@ -136,15 +134,15 @@ class GovspeakContactsTest < Minitest::Test
136
134
  {
137
135
  street_address: "125 Kingsway",
138
136
  country_name: "United Kingdom",
139
- }
137
+ },
140
138
  ])
141
139
  govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
142
140
  rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
143
- expected = %{
141
+ expected = %(
144
142
  <p class="adr">
145
143
  <span class="street-address">125 Kingsway</span>
146
144
  </p>
147
- }
145
+ )
148
146
  assert_match(compress_html(expected), compress_html(rendered))
149
147
  end
150
148
 
@@ -152,44 +150,44 @@ class GovspeakContactsTest < Minitest::Test
152
150
  contact = build_contact(post_addresses: [
153
151
  {
154
152
  street_address: "",
155
- }
153
+ },
156
154
  ])
157
155
  govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
158
156
  rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
159
- refute_match(%{<p class="adr">}, compress_html(rendered))
157
+ refute_match(%(<p class="adr">), compress_html(rendered))
160
158
  end
161
159
 
162
160
  test "contact with an empty email address is not rendered" do
163
161
  contact = build_contact(email_addresses: [
164
162
  {
165
163
  email: "",
166
- }
164
+ },
167
165
  ])
168
166
  govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
169
167
  rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
170
- refute_match(%{<p class="email">}, compress_html(rendered))
168
+ refute_match(%(<p class="email">), compress_html(rendered))
171
169
  end
172
170
 
173
171
  test "contact with an empty contact form is not rendered" do
174
172
  contact = build_contact(contact_form_links: [
175
173
  {
176
174
  link: "",
177
- }
175
+ },
178
176
  ])
179
177
  govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
180
178
  rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
181
- refute_match(%{<p class="contact_form_url">}, compress_html(rendered))
179
+ refute_match(%(<p class="contact_form_url">), compress_html(rendered))
182
180
  end
183
181
 
184
182
  test "contact with an empty phone number is not rendered" do
185
183
  contact = build_contact(phone_numbers: [
186
184
  {
187
185
  number: "",
188
- }
186
+ },
189
187
  ])
190
188
  govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
191
189
  rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
192
- refute_match(%{<p class="tel">}, compress_html(rendered))
190
+ refute_match(%(<p class="tel">), compress_html(rendered))
193
191
  end
194
192
 
195
193
  test "it auto links text in the description" do
@@ -197,7 +195,7 @@ class GovspeakContactsTest < Minitest::Test
197
195
 
198
196
  govspeak = "[Contact:4f3383e4-48a2-4461-a41d-f85ea8b89ba0]"
199
197
  rendered = Govspeak::Document.new(govspeak, contacts: [contact]).to_html
200
- assert_match(%{<p class="comments">My description about <a href="https://www.gov.uk">https://www.gov.uk</a></p>},
198
+ assert_match(%(<p class="comments">My description about <a href="https://www.gov.uk">https://www.gov.uk</a></p>),
201
199
  compress_html(rendered))
202
200
  end
203
201
  end