-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcustom_form_helpers_spec.rb
149 lines (117 loc) · 3.9 KB
/
custom_form_helpers_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
require "rails_helper"
RSpec.describe CustomFormHelpers, type: :helper do
let(:form_object) { instance_double("FormObject") }
let(:builder) do
GOVUKDesignSystemFormBuilder::FormBuilder.new(
:disclosure_check,
form_object,
self,
{},
)
end
describe "#continue_button" do
let(:expected_markup) { '<button type="submit" formnovalidate="formnovalidate" class="govuk-button" data-module="govuk-button" data-prevent-double-click="true">Continue</button>' }
let(:template) { instance_double("template", params:) }
before do
allow(builder).to receive(:template).and_return(template)
end
context "when there is no next step param" do
let(:params) { {} }
it "outputs the govuk continue button without the next step hidden tag" do
expect(
builder.continue_button,
).to eq(expected_markup)
end
end
context "when the next step param is not recognised" do
let(:params) { { next_step: "foobar" } }
it "outputs the govuk continue button without the next step hidden tag" do
expect(
builder.continue_button,
).to eq(expected_markup)
end
end
context "when there is a valid next step param" do
let(:params) { { next_step: "cya" } }
it "outputs the govuk continue button with the next step hidden tag" do
allow(
template,
).to receive(:hidden_field_tag).with(
:next_step, "/steps/check/check_your_answers"
).and_return("<hidden_tag_here>".html_safe)
expect(
builder.continue_button,
).to eq("<hidden_tag_here>#{expected_markup}")
end
end
end
describe "#i18n_caption" do
before do
allow(form_object).to receive(:conviction_subtype).and_return(:foobar)
end
it "seeks the expected locale key" do
expect(I18n).to receive(:t).with(
:foobar, scope: %i[helpers caption disclosure_check]
)
builder.i18n_caption
end
end
describe "#i18n_legend" do
before do
allow(form_object).to receive(:i18n_attribute).and_return(:foobar)
end
it "seeks the expected locale key" do
expect(I18n).to receive(:t).with(
:foobar, scope: %i[helpers legend disclosure_check], default: :default
)
builder.i18n_legend
end
end
describe "#i18n_date_hint" do
let(:found_key) { "hint text about dates" }
before do
allow(I18n).to receive(:t).with(
"helpers/dictionary.date_hint_text",
).and_return(found_key)
end
describe "with lead_text argument" do
it "seeks the expected key" do
expect(found_key).to receive(:html_safe)
builder.i18n_date_hint("lead text")
end
it "wraps lead text in p tags" do
expect(builder.i18n_date_hint("lead text")).to include "<p>lead text</p>"
end
end
describe "without lead_text argument" do
it "gets lead text from i18n_lead_text" do
allow(builder).to receive(:i18n_lead_text).and_return "i18n_lead_text"
expect(builder.i18n_date_hint).to include "<p>i18n_lead_text</p>"
end
end
end
describe "#i18n_hint" do
let(:found_locale) { instance_double("locale") }
before do
allow(form_object).to receive(:i18n_attribute).and_return(:foobar)
end
it "seeks the expected locale key" do
allow(I18n).to receive(:t).with(
"foobar_html", scope: %i[helpers hint disclosure_check], default: :default_html
).and_return(found_locale)
expect(found_locale).to receive(:html_safe)
builder.i18n_hint
end
end
describe "#i18n_lead_text" do
before do
allow(form_object).to receive(:i18n_attribute).and_return(:foobar)
end
it "seeks the expected locale key" do
expect(I18n).to receive(:t).with(
:foobar, scope: %i[helpers lead_text disclosure_check], default: :default
)
builder.i18n_lead_text
end
end
end