Skip to content

Commit

Permalink
Merge pull request #400 from sparc-request/jw-ml_service_calendar_qty…
Browse files Browse the repository at this point in the history
…_max_bug

Jw ml service calendar qty max bug
  • Loading branch information
wtholt committed May 20, 2016
2 parents a299231 + f9fc93a commit 8058260
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
8 changes: 7 additions & 1 deletion app/assets/javascripts/service_calendar.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,15 @@ $(document).ready ->
$(document).on('change', '.line_item_quantity', ->
if $(this).data('study_tracker') == true
save_line_item_by_ajax(this)
recalculate_one_time_fee_totals()
else
update_otf_line_item(this)
recalculate_one_time_fee_totals()
# If new val is greater than units_per_qty_max, do no recalculate totals
new_val = $(this).val()
max_val = $(this).attr('units_per_qty_max')
if (parseInt(new_val) <= parseInt(max_val)) && (parseInt(new_val) >= parseInt(min_val))
recalculate_one_time_fee_totals()

return false
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
%td= line_item.service.try(:displayed_pricing_map).try(:quantity_type).try(:humanize)
%td.width-50
= text_field_tag "service_request[line_items_attributes][#{line_item.id}][quantity]", line_item.quantity, |
unit_minimum: line_item.service.displayed_pricing_map.quantity_minimum, class: 'line_item_quantity', current_quantity: line_item.quantity, previous_quantity: line_item.quantity, |
unit_minimum: line_item.service.displayed_pricing_map.quantity_minimum, units_per_qty_max: line_item.service.displayed_pricing_map.units_per_qty_max, class: 'line_item_quantity', current_quantity: line_item.quantity, previous_quantity: line_item.quantity, |
update: update_otf_qty_and_units_per_qty_service_request_service_calendars_path(@service_request, line_item_id: line_item.id, type: 'qty') |
%td
%td
Expand Down
17 changes: 16 additions & 1 deletion spec/features/service_calendar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@

describe 'unit minimum too low' do

it 'should throw js error' do
it 'should retain original total direct cost' do
fill_in "service_request_line_items_attributes_#{line_item.id}_units_per_quantity", with: 1
page.execute_script('$(".units_per_quantity").change()')
wait_for_javascript_to_finish

fill_in "service_request_line_items_attributes_#{line_item.id}_quantity", with: 0
wait_for_javascript_to_finish
page.execute_script('$(".line_item_quantity").change()')
wait_for_javascript_to_finish

expect(page).to have_css('.otf_total_direct_cost', text: '$50.00')
end
end

Expand All @@ -92,6 +95,18 @@

expect(page).to have_css('#unit_max_error', text: 'more than the maximum allowed')
end

it 'should retain original total direct cost' do
fill_in "service_request_line_items_attributes_#{line_item.id}_units_per_quantity", with: 1
page.execute_script('$(".units_per_quantity").change()')
wait_for_javascript_to_finish

fill_in "service_request_line_items_attributes_#{line_item.id}_quantity", with: 55
page.execute_script('$(".line_item_quantity").change()')
wait_for_javascript_to_finish

expect(page).to have_css('.otf_total_direct_cost', text: '$50.00')
end
end
end
end
Expand Down

0 comments on commit 8058260

Please sign in to comment.