Skip to content

Commit

Permalink
Merge pull request #53 from bmic-development/jtm_fixing_questionnaire…
Browse files Browse the repository at this point in the history
…_javascript

Jtm fixing questionnaire javascript
  • Loading branch information
Stuart-Johnson committed Feb 6, 2017
2 parents 815ef7a + 185b501 commit 31cf124
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
$ ->
# Copyright © 2011-2016 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~

window.set_disabled = ->
activeQuestionnaires = $('.active-questionnaire')
inactiveQuestionnaires = $('.inactive-questionnaire')

if activeQuestionnaires.length > 0
$.each inactiveQuestionnaires, (key, value) ->
$(value).addClass('disabled')
$ ->
set_disabled()


Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<% if @questionnaire.save %>
swal("Success", "Questionnaire status updated", "success")
$('.questionnaires-index-table').html("<%= j render 'additional_details/questionnaires_index_table', questionnaires: @questionnaires %>")
set_disabled()
<% else %>
swal("Error", "Questionnaire status not updated", "error")
<% end %>
6 changes: 6 additions & 0 deletions spec/factories/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
one_time_fee false
end

trait :with_questionnaires do
after(:create) do |service|
service.questionnaires = create_list(:questionnaire, 2, service: service, active: 0)
end
end

transient do
line_item_count 0
pricing_map_count 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright © 2011-2016 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~

require 'rails_helper'

RSpec.describe 'User has multiple questionnaires that can be activated', js: true do

let_there_be_lane

before(:each) do
@service = create(:service_with_ctrc_organization, :with_questionnaires)
end

describe "Both are inactive" do

before(:each) do
visit service_additional_details_questionnaires_path(@service)
expect(page).to_not have_css '.disabled'
end

it 'disables other inactive questionnaire buttons when one is activated' do
first(".inactive-questionnaire").click
wait_for_javascript_to_finish
expect(page).to have_css '.disabled', count: @service.questionnaires.count - 1
end

it 're-enables other inactive questionnaire buttons when one is deactivated' do
first(".inactive-questionnaire").click
wait_for_javascript_to_finish
click_button 'OK'
first(".active-questionnaire").click
wait_for_javascript_to_finish
expect(page).to_not have_css '.disabled'
end
end

describe "One is active" do

before(:each) do
@service.questionnaires.first.update_attribute(:active, 1)
visit service_additional_details_questionnaires_path(@service)
expect(page).to have_css '.disabled', count: @service.questionnaires.count - 1
end

it 're-enables other inactive questionnaire buttons when one is deactivated' do
first(".active-questionnaire").click
wait_for_javascript_to_finish
expect(page).to_not have_css '.disabled'
end
end
end

0 comments on commit 31cf124

Please sign in to comment.