Skip to content

Commit

Permalink
Merge pull request #4654 from pulibrary/4641-modal-form-submit-close
Browse files Browse the repository at this point in the history
Submit and close modal feedback form
  • Loading branch information
christinach authored Dec 17, 2024
2 parents 5c3ecdc + 82fd0cc commit 113a3e4
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 3 deletions.
8 changes: 8 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@
//
//= require ./custom_range_limit.js
//= require ./orangelight.js

// Wait for the modal to open
document.addEventListener('show.blacklight.blacklight-modal', function () {
// Wait for the form to be submitted successfully
$('.modal_form').on('ajax:success', function () {
Blacklight.Modal.hide();
});
});
3 changes: 2 additions & 1 deletion app/views/catalog/_ask_a_question_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<%= render :partial=>'shared/flash_msg' %>
<%= simple_form_for(
form,
remote: true,
url: contact_question_path,
data: { blacklight_modal: 'trigger' },
html: {class: "modal_form"}
Expand All @@ -18,7 +19,7 @@
<%= f.input :feedback_desc, as: :hidden %>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bl-dismiss="modal">Cancel</button>
<%= f.submit "Send", class: "btn btn-primary", data: {bl_dismiss: "modal"}, id: 'submit-question' %>
<%= f.submit "Send", class: "btn btn-primary", id: 'submit-question' %>
</div>
<% end %>
</div>
3 changes: 2 additions & 1 deletion app/views/catalog/_report_harmful_language_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<%= render :partial=>'shared/flash_msg' %>
<%= simple_form_for(
form,
remote: true,
url: contact_report_harmful_language_path,
data: { blacklight_modal: 'trigger' },
html: { class: "modal_form" }
Expand Down Expand Up @@ -35,6 +36,6 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bl-dismiss="modal">Cancel</button>
<%= f.submit "Send", class: "btn btn-primary", data: {bl_dismiss: "modal"}, id: 'submit-question' %>
<%= f.submit "Send", class: "btn btn-primary", id: 'submit-question' %>
</div>
<% end %>
3 changes: 2 additions & 1 deletion app/views/catalog/_suggest_correction_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<%= render :partial=>'shared/flash_msg' %>
<%= simple_form_for(
form,
remote: true,
url: contact_suggestion_path,
data: { blacklight_modal: 'trigger' },
html: { class: "modal_form" }
Expand All @@ -20,7 +21,7 @@
<%= f.input :feedback_desc, as: :hidden %>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bl-dismiss="modal">Cancel</button>
<%= f.submit "Send", class: "btn btn-primary", data: {bl_dismiss: "modal"}, id: 'submit-suggestion' %>
<%= f.submit "Send", class: "btn btn-primary", id: 'submit-suggestion' %>
</div>
<% end %>
</div>
1 change: 1 addition & 0 deletions spec/features/report_harmful_language_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
end

it 'gives an error when the email is invalid' do
pending 'see https://github.com/pulibrary/orangelight/issues/4655'
expect(page).to have_content 'Email is not a valid email address'
end
end
19 changes: 19 additions & 0 deletions spec/system/ask_a_question_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,23 @@
expect(page).to have_text 'Your question has been submitted'
end
end
describe 'pressing the send button' do
before do
stub_libanswers_api
stub_holding_locations
visit '/catalog/99101035463506421'
scroll_to(:bottom) # needed when js: true
click_link 'Ask a Question'
fill_in 'ask_a_question_form_name', with: 'Agatha'
fill_in 'ask_a_question_form_email', with: 'agatha@poi.uk'
fill_in 'ask_a_question_form_message', with: 'Murder on the Orient Express'
end
it 'closes the modal', js: true do
expect(page).to have_text('Ask a Question')
expect(page).to have_text('Message')
click_button 'Send'
expect(current_path).to eq '/catalog/99101035463506421'
expect(page).not_to have_text('Message')
end
end
end
16 changes: 16 additions & 0 deletions spec/system/report_harmful_language_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,20 @@
expect(page).to have_text 'Thank you for reporting problematic language in the Princeton University Library catalog'
end
end
describe 'pressing the send button' do
before do
stub_libanswers_api
stub_holding_locations
visit '/catalog/99105509673506421'
scroll_to(:bottom) # needed when js: true
click_link 'Report Harmful Language'
fill_in 'report_harmful_language_form_message', with: 'Please correct the harmful content of this record'
end
it 'closes the modal', js: true do
expect(page).to have_text('You are reporting the use of harmful language in this catalog record')
click_button 'Send'
expect(current_path).to eq '/catalog/99105509673506421'
expect(page).not_to have_text('You are reporting the use of harmful language in this catalog record')
end
end
end
18 changes: 18 additions & 0 deletions spec/system/suggest_correction_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,22 @@
expect(page).not_to have_text('Please use this area to report errors or omissions')
end
end
describe 'pressing the send button' do
before do
stub_libanswers_api
stub_holding_locations
visit '/catalog/99105509673506421'
scroll_to(:bottom) # needed when js: true
click_link 'Suggest a Correction'
fill_in 'suggest_correction_form_name', with: 'Hercule Poirot'
fill_in 'suggest_correction_form_email', with: 'herpo@poi.her'
fill_in 'suggest_correction_form_message', with: 'Death on the Nile'
end
it 'closes the modal', js: true do
expect(page).to have_text('Please use this area to report errors or omissions')
click_button 'Send'
expect(current_path).to eq '/catalog/99105509673506421'
expect(page).not_to have_text('Please use this area to report errors or omissions')
end
end
end

0 comments on commit 113a3e4

Please sign in to comment.