diff --git a/app/helpers/variance_helper.rb b/app/helpers/variance_helper.rb index 5ce84b4d..5ff88e2a 100644 --- a/app/helpers/variance_helper.rb +++ b/app/helpers/variance_helper.rb @@ -46,4 +46,8 @@ module VarianceHelper def measures_with_insufficient_data(presenters:) presenters.filter { |presenter| presenter.score == nil } end + + def measures_with_sufficient_data(presenters:) + presenters.filter { |presenter| presenter.score != nil } + end end diff --git a/app/views/dashboard/_variance_graph.erb b/app/views/dashboard/_variance_graph.erb index dafbea83..21e5398c 100644 --- a/app/views/dashboard/_variance_graph.erb +++ b/app/views/dashboard/_variance_graph.erb @@ -1,9 +1,9 @@ - <% unless measures_with_insufficient_data(presenters: presenters).empty? %>

Note: The following measures are not displayed due to limited availability of school admin data and/or low survey response rates: <%= measures_with_insufficient_data(presenters: presenters).map(&:measure_name).join('; ') %>.

<% end %> - xmlns="http://www.w3.org/2000/svg"> +<% displayed_presenters = measures_with_sufficient_data(presenters: presenters) %> + xmlns="http://www.w3.org/2000/svg"> @@ -25,7 +25,7 @@ x="<%= label_width_percentage %>%" y="0" width="<%= graph_width_percentage %>%" - height=<%= graph_background_height(number_of_rows: presenters.size) %> + height=<%= graph_background_height(number_of_rows: displayed_presenters.size) %> filter="url(#inset-shadow)" > @@ -60,7 +60,7 @@ > - <%= presenters.each_with_index do |presenter, index| %> + <%= displayed_presenters.each_with_index do |presenter, index| %> <%= presenter.measure_name %> @@ -80,13 +81,14 @@ y="<%= heading_gutter %>" width="<%= graph_width_percentage %>%" > - <%= presenters.each_with_index do |presenter, index| %> + <%= displayed_presenters.each_with_index do |presenter, index| %> data-for-measure-id="<%= presenter.measure_id %>" + height=<%= measure_row_bar_height %> + data-for-measure-id="<%= presenter.measure_id %>" stroke="none" /> <% end %> @@ -98,7 +100,7 @@ x="<%= label_width_percentage %>%" y="0" width="<%= graph_width_percentage %>%" - height="<%= graph_background_height(number_of_rows: presenters.size) %>" + height="<%= graph_background_height(number_of_rows: displayed_presenters.size) %>" > Benchmark diff --git a/spec/features/school_dashboard_feature_spec.rb b/spec/features/school_dashboard_feature_spec.rb index 53c68636..5f67eed1 100644 --- a/spec/features/school_dashboard_feature_spec.rb +++ b/spec/features/school_dashboard_feature_spec.rb @@ -227,9 +227,7 @@ def district_admin_sees_dashboard_content district_admin_sees_student_physical_safety district_admin_sees_problem_solving_emphasis - expect(page).to have_css("[data-for-measure-id='3A-i'][width='0.0%']") - - page.assert_selector('.measure-row-bar', count: Measure.count) + page.assert_selector('.measure-row-bar', count: 5) district_admin_sees_measures_in_correct_order end diff --git a/spec/views/dashboard/index.html.erb_spec.rb b/spec/views/dashboard/index.html.erb_spec.rb index 47465584..14c1c895 100644 --- a/spec/views/dashboard/index.html.erb_spec.rb +++ b/spec/views/dashboard/index.html.erb_spec.rb @@ -1,6 +1,7 @@ require 'rails_helper' describe 'dashboard/index.html.erb' do + subject { Nokogiri::HTML(rendered) } let(:support_for_teaching) { create(:measure, name: 'Support For Teaching Development & Growth') } let(:effective_leadership) { create(:measure, name: 'Effective Leadership') } @@ -13,11 +14,11 @@ describe 'dashboard/index.html.erb' do render end - context 'when there are measures for which, in the given academic year, the school has insufficient responses' do + context 'when some presenters have a nil score' do let(:measure_graph_row_presenters) { [ MeasureGraphRowPresenter.new(measure: support_for_teaching, score: nil), - MeasureGraphRowPresenter.new(measure: create(:measure), score: rand), + MeasureGraphRowPresenter.new(measure: create(:measure, name: 'Should Be Displayed', measure_id: 'should-be-displayed'), score: rand), MeasureGraphRowPresenter.new(measure: effective_leadership, score: nil), MeasureGraphRowPresenter.new(measure: professional_qualifications, score: nil) ] @@ -26,17 +27,37 @@ describe 'dashboard/index.html.erb' do it 'displays a note detailing which measures have insufficient responses for the given school & academic year' do expect(rendered).to match /Note: The following measures are not displayed due to limited availability of school admin data and\/or low survey response rates: Support For Teaching Development & Growth; Effective Leadership; Professional Qualifications./ end + + it 'displays a variance row and label only those presenters for which the score is not nil' do + displayed_variance_rows = subject.css('[data-for-measure-id]') + expect(displayed_variance_rows.count).to eq 1 + expect(displayed_variance_rows.first.attribute('data-for-measure-id').value).to eq 'should-be-displayed' + + displayed_variance_labels = subject.css('[data-variance-row-label]') + expect(displayed_variance_labels.count).to eq 1 + expect(displayed_variance_labels.first.inner_text).to include 'Should Be Displayed' + end end - context 'when there are no measures for which, in the given academic year, the school has insufficient responses' do + context 'when all the presenters have a non-nil score' do let(:measure_graph_row_presenters) { [ - MeasureGraphRowPresenter.new(measure: create(:measure), score: rand) + MeasureGraphRowPresenter.new(measure: create(:measure, name: 'Display Me', measure_id: 'display-me'), score: rand) ] } it 'does not display a note detailing which measures have insufficient responses for the given school & academic year' do expect(rendered).not_to match /Note: The following measures are not displayed due to limited availability of school admin data and\/or low survey response rates/ end + + it 'displays a variance row for each presenter' do + displayed_variance_rows = subject.css('[data-for-measure-id]') + expect(displayed_variance_rows.count).to eq 1 + expect(displayed_variance_rows.first.attribute('data-for-measure-id').value).to eq 'display-me' + + displayed_variance_labels = subject.css('[data-variance-row-label]') + expect(displayed_variance_labels.count).to eq 1 + expect(displayed_variance_labels.first.inner_text).to include 'Display Me' + end end end