-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconversation_js_features_spec.rb
More file actions
259 lines (205 loc) · 7.95 KB
/
conversation_js_features_spec.rb
File metadata and controls
259 lines (205 loc) · 7.95 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
RSpec.describe "Conversation JavaScript features", :aws_credentials_stubbed, :chunked_content_index, :js do
scenario "questions with answers" do
given_i_am_a_web_chat_user
and_i_have_dismissed_the_cookie_banner
when_i_visit_the_conversation_page
and_i_enter_a_first_question
then_i_see_the_first_question_was_accepted
when_the_first_answer_is_generated
then_i_can_see_the_first_answer
when_i_enter_a_second_question
then_i_see_the_second_question_was_accepted
when_the_second_answer_is_generated
then_i_can_see_the_second_answer
end
scenario "client side validation" do
given_i_am_a_web_chat_user
and_i_have_dismissed_the_cookie_banner
when_i_visit_the_conversation_page
and_i_enter_an_empty_question
then_i_see_a_presence_validation_message
when_i_enter_a_valid_question
then_i_see_the_valid_question_was_accepted
end
scenario "server side validation" do
given_i_am_a_web_chat_user
and_i_have_dismissed_the_cookie_banner
when_i_visit_the_conversation_page
and_i_enter_a_question_with_pii
then_i_see_a_pii_validation_message
when_i_enter_a_valid_question
then_i_see_the_valid_question_was_accepted
end
scenario "reloading the page while an answer is pending" do
given_i_am_a_web_chat_user
and_i_have_dismissed_the_cookie_banner
when_i_visit_the_conversation_page
and_i_enter_a_first_question
then_i_see_the_first_question_was_accepted
when_i_reload_the_page
and_the_first_answer_is_generated
then_i_can_see_the_first_answer
end
scenario "character limits" do
given_i_am_a_web_chat_user
and_i_have_dismissed_the_cookie_banner
when_i_visit_the_conversation_page
and_i_type_in_a_question_approaching_the_character_count_limit
then_i_see_a_character_count_warning
when_i_type_in_a_question_exceeding_the_character_count_limit
then_i_see_a_character_count_error
end
scenario "loading messages" do
given_i_am_a_web_chat_user
and_i_have_dismissed_the_cookie_banner
when_i_visit_the_conversation_page
and_i_enter_a_first_question_with_a_slow_response
then_i_see_a_question_loading_message
when_i_see_the_first_question_was_accepted
then_i_see_an_answer_loading_message
when_the_first_answer_is_generated
then_i_can_see_the_first_answer
and_i_see_no_answer_loading_message
end
scenario "showing clear chat link in navigation" do
given_i_am_a_web_chat_user
and_i_have_dismissed_the_cookie_banner
when_i_visit_the_conversation_page
then_i_cant_see_the_clear_chat_link
when_i_enter_a_first_question
then_i_see_the_first_question_was_accepted
and_i_can_see_the_clear_chat_link
end
def when_i_visit_the_conversation_page
visit show_conversation_path
end
def when_i_enter_a_first_question
@first_question = "How do I setup a workplace pension?"
fill_in "create_question[user_question]", with: @first_question
click_on "Send"
end
alias_method :when_i_enter_a_valid_question, :when_i_enter_a_first_question
alias_method :and_i_enter_a_first_question, :when_i_enter_a_first_question
def and_i_enter_a_first_question_with_a_slow_response
@first_question = "How do I setup a workplace pension?"
conversation = build(:conversation, signon_user: @signon_user)
prepared_question = create(:question, message: @first_question, conversation:)
allow(Question).to receive(:new).and_return(prepared_question)
# delay the server side response to provide time for a delayed loading state
allow(prepared_question).to receive(:save!) { sleep 1 }
fill_in "create_question[user_question]", with: @first_question
click_on "Send"
end
def then_i_see_the_first_question_was_accepted
within(".js-new-conversation-messages-list") do
expect(page).to have_content(@first_question)
end
end
alias_method :then_i_see_the_valid_question_was_accepted, :then_i_see_the_first_question_was_accepted
alias_method :when_i_see_the_first_question_was_accepted, :then_i_see_the_valid_question_was_accepted
def then_i_see_an_answer_loading_message
within(".js-new-conversation-messages-list") do
expect(page).to have_content("Generating your answer")
end
end
def and_i_see_no_answer_loading_message
within(".js-new-conversation-messages-list") do
expect(page).not_to have_content("Generating your answer")
end
end
def then_i_see_a_question_loading_message
within(".js-new-conversation-messages-list") do
expect(page).to have_content("Loading your question")
end
end
def then_i_see_no_question_loading_message
within(".js-new-conversation-messages-list") do
expect(page).not_to have_content("Loading your question")
end
end
def when_the_first_answer_is_generated
@first_answer = "You can use a simple service on GOV.UK"
stubs_for_mock_answer(@first_question,
@first_answer,
sources_used: %w[link_1])
execute_queued_sidekiq_jobs
end
alias_method :and_the_first_answer_is_generated, :when_the_first_answer_is_generated
def then_i_can_see_the_first_answer
expect(page).to have_content(@first_answer)
end
def when_i_enter_a_second_question
@second_question = "Sounds good, what's the name of the service?"
fill_in "create_question[user_question]", with: @second_question
click_on "Send"
end
def then_i_see_the_second_question_was_accepted
within(".js-new-conversation-messages-list") do
expect(page).to have_content(@second_question)
end
end
def when_the_second_answer_is_generated
@second_answer = "The simple workplace pension service"
stubs_for_mock_answer(@second_question,
@second_answer,
sources_used: %w[link_1],
create_content_chunk: false)
execute_queued_sidekiq_jobs
end
alias_method :and_the_second_answer_is_generated, :when_the_second_answer_is_generated
def then_i_can_see_the_second_answer
expect(page).to have_content(@second_answer)
end
def and_i_enter_an_empty_question
fill_in "create_question[user_question]", with: ""
click_on "Send"
end
def then_i_see_a_presence_validation_message
expect(page).to have_content(Form::CreateQuestion::USER_QUESTION_PRESENCE_ERROR_MESSAGE)
end
def and_i_enter_a_question_with_pii
fill_in "create_question[user_question]", with: "My phone number is 07123456789"
click_on "Send"
end
def then_i_see_a_pii_validation_message
expect(page).to have_content(/Personal data has been detected/)
end
def when_i_reload_the_page
refresh
end
def and_i_type_in_a_question_approaching_the_character_count_limit
character_count = Form::CreateQuestion::USER_QUESTION_LENGTH_MAXIMUM - 50
fill_in "create_question[user_question]", with: "A" * character_count
end
def when_i_type_in_a_question_exceeding_the_character_count_limit
character_count = Form::CreateQuestion::USER_QUESTION_LENGTH_MAXIMUM + 10
fill_in "create_question[user_question]", with: "A" * character_count
end
def then_i_see_a_character_count_warning
expect(page).to have_content("You have 50 characters remaining")
end
def then_i_see_a_character_count_error
expect(page).to have_content("You have 10 characters too many")
end
def then_i_cant_see_the_clear_chat_link
within(".app-c-header") do
# This is link is visually hidden but doesn't register as visible: :hidden
# to capybara so have to assert on CSS selector
expect(page).to have_selector(
"a.app-c-header__clear-chat.app-c-header__clear-chat--focusable-only",
text: "Clear chat",
)
end
end
def and_i_can_see_the_clear_chat_link
within(".app-c-header") do
expect(page).to have_selector(
"a.app-c-header__clear-chat:not(.app-c-header__clear-chat--focusable-only)",
text: "Clear chat",
)
end
end
def when_i_visit_the_conversation_page
visit show_conversation_path
end
end