Verified Commit 120c49c9 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

some MR feedback changes

parent 14aefab4
$(() => {
if (_(window.location.pathname).split('/').last() === 'last_submitted_hours_and_feedbacks') {
enableWaiveFormXhrSubmit()
}
})
const throttle = (callBack, time = 1000) => _.throttle(callBack, time)
const enableWaiveFormXhrSubmit = () => {
const waiveIbanForm = $('#volunteer-update-waive-and-iban')
if (waiveIbanForm.length === 0) { return }
const volunteerId = waiveIbanForm.find('input[name$="assignment[volunteer_attributes][id]"]').val()
_(['waive', 'iban', 'bank']).map(fieldName => {
return {
fieldElement: waiveIbanForm.find(`input[name$="assignment[volunteer_attributes][${fieldName}]"]`),
fieldName
}
}).forEach(({ fieldElement, fieldName }) => {
$(fieldElement).on('input', throttle(({ target }) => {
_(['waive', 'iban', 'bank']).forEach(fieldName => {
waiveIbanForm.find(`input[name$="assignment[volunteer_attributes][${fieldName}]"]`).on('input', throttle(({ target }) => {
$.ajax({
data: { volunteer: { [fieldName]: valueOrChecked($(target)) } },
method: 'PATCH',
......@@ -24,6 +12,6 @@ const enableWaiveFormXhrSubmit = () => {
})
}))
})
}
})
const valueOrChecked = field => (field.prop('type') === 'checkbox') ? field.prop('checked') : field.val();
const valueOrChecked = field => field.is(':checkbox') ? field.is(':checked') : field.val();
......@@ -81,7 +81,7 @@ class VolunteersController < ApplicationController
def update_waive_and_iban
authorize @volunteer
@volunteer.update(volunteer_params)
@volunteer.update(volunteer_params.slice(:iban, :waive, :bank))
render json: nil, status: :ok
end
......
......@@ -71,7 +71,7 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
end
end
def fill_field_with_send_keys(locator, text)
def fill_field_char_by_char_and_wait_for_ajax(locator, text)
field = page.find_field(locator)
text.split('').each do |char|
field.native.send_keys(char)
......
......@@ -19,13 +19,11 @@ class VolunteerSubmitsAfterRemindTest < ApplicationSystemTestCase
@volunteer.update(waive: false, iban: nil, bank: nil)
visit last_submitted_hours_and_feedbacks_assignment_path(@assignment)
fill_field_with_send_keys('IBAN', 'CH12345')
sleep 1
fill_field_char_by_char_and_wait_for_ajax('IBAN', 'CH12345')
@volunteer.reload
assert_equal 'CH12345', @volunteer.iban
fill_field_with_send_keys('Bank', 'Name of the bank')
sleep 1
fill_field_char_by_char_and_wait_for_ajax('Bank', 'Name of the bank')
@volunteer.reload
assert_equal 'Name of the bank', @volunteer.bank
......@@ -34,7 +32,7 @@ class VolunteerSubmitsAfterRemindTest < ApplicationSystemTestCase
assert page.has_field? 'Name der Bank', with: 'Name of the bank'
check 'Ich verzichte auf die Auszahlung von Spesen.'
sleep 1
sleep 0.3
@volunteer.reload
assert @volunteer.waive
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment