summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2017-03-23 11:00:40 +0000
committerazul <azul@riseup.net>2017-03-23 11:00:40 +0000
commitfca8411e2359eafd4c50dbb6a6b8539a7e8593c7 (patch)
treee89e5ebee660b44e30c59c737bac8b78190cb9af
parent96c3123b9a30df3d7750b1f8e4bda2aba3d1fcb7 (diff)
parentc828d0164a43c169775ae107be3fd4409d6c3ecb (diff)
Merge branch 'bugfix/ticket-validations' into 'master'
fix: keep ticket submit button clickable See merge request !27
-rw-r--r--app/assets/javascripts/buttons.js17
-rw-r--r--engines/support/test/integration/create_ticket_test.rb61
2 files changed, 54 insertions, 24 deletions
diff --git a/app/assets/javascripts/buttons.js b/app/assets/javascripts/buttons.js
index 7142957..aaa9911 100644
--- a/app/assets/javascripts/buttons.js
+++ b/app/assets/javascripts/buttons.js
@@ -5,12 +5,12 @@
*
* Some form inputs are validaded before the submission
* so triggering loading state on click events is not a
- * good idea. If the validation fails the errors will
+ * good idea. If the validation fails the errors will
* be displayed but the button would be in loading state.
*
* We used to trigger it based on form submission but
* we have a few forms that contain multiple buttons.
- * So now we mark the buttons as clicked on click and
+ * So now we mark the buttons as clicked on click and
* put the clicked button into loading state on submit.
*
*/
@@ -26,14 +26,19 @@
markAsLoading = function(submitEvent) {
var form = submitEvent.target;
- $(form).addClass('submitted')
- // bootstrap loading state:
- $(form).find('.btn.clicked[type="submit"]').button('loading');
+ var validations = form.ClientSideValidations
+
+ if ( ( typeof validations === 'undefined' ) ||
+ $(form).isValid(validations.settings.validators) ) {
+ $(form).addClass('submitted')
+ // bootstrap loading state:
+ $(form).find('.btn.clicked[type="submit"]').button('loading');
+ }
};
$(document).ready(function() {
$('form').submit(markAsLoading);
$('.btn[type="submit"]').click(markAsClicked);
});
-
+
}).call(this);
diff --git a/engines/support/test/integration/create_ticket_test.rb b/engines/support/test/integration/create_ticket_test.rb
index 6abb3d3..fcdc6b8 100644
--- a/engines/support/test/integration/create_ticket_test.rb
+++ b/engines/support/test/integration/create_ticket_test.rb
@@ -7,30 +7,30 @@ class CreateTicketTest < BrowserIntegrationTest
@testcode.save!
end
+ teardown do
+ Ticket.last.destroy if Ticket.last.present?
+ end
+
test "can submit ticket anonymously" do
- visit '/'
- click_on 'Get Help'
- fill_in 'Subject', with: 'test ticket'
- fill_in 'Description', with: 'description of the problem goes here'
- click_on 'Submit Ticket'
- assert page.has_content?("Ticket was successfully created.")
- assert page.has_content?("You can later access this ticket at the URL")
- assert page.has_content?(current_url)
- assert ticket = Ticket.last
- ticket.destroy
+ submit_ticket
+ assert_ticket_submitted
end
test "get help when creating ticket with invalid email" do
- visit '/'
- click_on 'Get Help'
- fill_in 'Subject', with: 'test ticket'
- fill_in 'Email', with: 'invalid data'
- fill_in 'Regarding User', with: 'some user'
- fill_in 'Description', with: 'description of the problem goes here'
- click_on 'Submit Ticket'
- assert page.has_content?("is invalid")
+ submit_ticket email: 'invalid data',
+ regarding_user: 'some user'
+ assert_invalid_submission
assert_equal 'invaliddata', find_field('Email').value
assert_equal 'some user', find_field('Regarding User').value
+ resubmit_ticket email: 'valid@data.info'
+ assert_ticket_submitted
+ end
+
+ test "can resubmit after missing description" do
+ submit_ticket description: ''
+ assert page.has_content?("can't be blank")
+ resubmit_ticket description: 'okay, okay... you get a subject'
+ assert_ticket_submitted
end
test "prefills fields" do
@@ -66,4 +66,29 @@ class CreateTicketTest < BrowserIntegrationTest
ticket.destroy
end
+ def submit_ticket(email: nil, regarding_user: nil, description: 'some content')
+ visit '/'
+ click_on 'Get Help'
+ fill_in 'Subject', with: 'test ticket'
+ fill_in 'Email', with: email if email
+ fill_in 'Regarding User', with: regarding_user if regarding_user
+ fill_in 'Description', with: description
+ click_on 'Submit Ticket'
+ end
+
+ def assert_invalid_submission
+ assert page.has_content?("is invalid")
+ end
+
+ def resubmit_ticket(email: nil, description: nil)
+ fill_in 'Email', with: email if email
+ fill_in 'Description', with: description if description
+ click_on 'Submit Ticket'
+ end
+
+ def assert_ticket_submitted
+ assert page.has_content?("Ticket was successfully created.")
+ assert page.has_content?("You can later access this ticket at the URL")
+ assert page.has_content?(current_url)
+ end
end