diff --git a/app/assets/stylesheets/tpi/pages/ascor.scss b/app/assets/stylesheets/tpi/pages/ascor.scss index 310f0cdd5..533f99bf1 100644 --- a/app/assets/stylesheets/tpi/pages/ascor.scss +++ b/app/assets/stylesheets/tpi/pages/ascor.scss @@ -264,6 +264,11 @@ $see-more-width-tablet: 130px; background-color: transparentize($ascor-background-color, 0.96); } + &__header { + position: relative; + padding-bottom: 10px; + } + &__title { color: $dark; font-family: $family-sans-serif; @@ -285,6 +290,10 @@ $see-more-width-tablet: 130px; } } + &__areas { + display: none; + } + &__area { outline: solid 1px $grey-lighter-medium; padding: 15px 20px 30px 20px; @@ -493,7 +502,26 @@ $see-more-width-tablet: 130px; } } - input.toggle:checked + .country-assessment__area-block { + input.toggle.pillar:checked + .country-assessment__pillar { + .country-assessment__areas { + display: block; + } + + .country-assessment__more.pillar { + top: 25px; + bottom: -1px; + + &:before { + content: 'See less'; + } + + &::after { + transform: rotate(-180deg); + } + } + } + + input.toggle.area:checked + .country-assessment__area-block { .country-assessment__indicators { display: block; } diff --git a/app/javascript/components/tpi/AscorQuestionLegend.js b/app/javascript/components/tpi/AscorQuestionLegend.js index 27fe583ea..0e0322a10 100644 --- a/app/javascript/components/tpi/AscorQuestionLegend.js +++ b/app/javascript/components/tpi/AscorQuestionLegend.js @@ -1,7 +1,10 @@ -import React, { useEffect } from 'react'; +import React, { useState, useEffect } from 'react'; +import cx from 'classnames'; const AscorQuestionLegend = () => { - const isChecked = () => { + const [isVisible, setVisible] = useState(false); + + const isCheckedArea = () => { let anyChecked = false; document @@ -9,7 +12,7 @@ const AscorQuestionLegend = () => { .forEach((section) => { let areaChecked = false; - section.querySelectorAll('input.toggle').forEach((input) => { + section.querySelectorAll('.country-assessment__areas > input.toggle').forEach((input) => { areaChecked = areaChecked || input.checked; anyChecked = anyChecked || input.checked; }); @@ -19,14 +22,33 @@ const AscorQuestionLegend = () => { }); }; + const isCheckedPillar = () => { + let anyChecked = false; + + document.querySelectorAll('.country-assessment > input.toggle.pillar').forEach((input) => { + anyChecked = anyChecked || input.checked; + }); + + setVisible(anyChecked); + }; + useEffect(() => { const eventListeners = []; document .querySelectorAll( - '.country-assessment > .country-assessment__pillar > input.toggle' + '.country-assessment .country-assessment__areas > input.toggle' + ) + .forEach((input) => { + const listener = input.addEventListener('click', isCheckedArea); + eventListeners.push([input, listener]); + }); + + document + .querySelectorAll( + '.country-assessment > input.toggle.pillar' ) .forEach((input) => { - const listener = input.addEventListener('click', isChecked); + const listener = input.addEventListener('click', isCheckedPillar); eventListeners.push([input, listener]); }); @@ -38,7 +60,7 @@ const AscorQuestionLegend = () => { }); return ( -
+
Legend
diff --git a/app/views/tpi/ascor/_assessment.html.erb b/app/views/tpi/ascor/_assessment.html.erb index afbcd21e3..ce39734f6 100644 --- a/app/views/tpi/ascor/_assessment.html.erb +++ b/app/views/tpi/ascor/_assessment.html.erb @@ -5,32 +5,38 @@ <%= react_component('AscorQuestionLegend') %> <% pillars.each_with_index do |pillar, i| %> +
-
<%= "Pillar #{i + 1}" %>
-

<%= pillar.text %>

+
+
<%= "Pillar #{i + 1}" %>
+

<%= pillar.text %>

+ +
- <% ascor_sub_indicators_for(pillar, areas).each do |area| %> - -
-
-
-
<%= "Area #{area.code}" %>
-
<%= area.text %>
+
+ <% ascor_sub_indicators_for(pillar, areas).each do |area| %> + +
+
+
+
<%= "Area #{area.code}" %>
+
<%= area.text %>
+
+
- -
-
- <% if ascor_sub_indicators_for(area, indicators).present? %> - <%= render 'tpi/ascor/assessment_indicators', area: area, indicators: ascor_sub_indicators_for(area, indicators), metrics: metrics %> - <% if area.code == 'EP.2' %> - <%= render 'tpi/ascor/benchmarks_chart' %> +
+ <% if ascor_sub_indicators_for(area, indicators).present? %> + <%= render 'tpi/ascor/assessment_indicators', area: area, indicators: ascor_sub_indicators_for(area, indicators), metrics: metrics %> + <% if area.code == 'EP.2' %> + <%= render 'tpi/ascor/benchmarks_chart' %> + <% end %> + <% else %> + <%= render 'tpi/ascor/assessment_metrics', metrics: ascor_sub_indicators_for(area, metrics) %> <% end %> - <% else %> - <%= render 'tpi/ascor/assessment_metrics', metrics: ascor_sub_indicators_for(area, metrics) %> - <% end %> +
-
- <% end %> + <% end %> +
<% end %> \ No newline at end of file diff --git a/spec/system/public/tpi/ascor_spec.rb b/spec/system/public/tpi/ascor_spec.rb index 6fcec1a3d..fe8255f62 100644 --- a/spec/system/public/tpi/ascor_spec.rb +++ b/spec/system/public/tpi/ascor_spec.rb @@ -38,7 +38,14 @@ visit '/ascor/japan' end + it 'shows assessment pillars' do + ASCOR::AssessmentIndicator.pillar.order(:id).each do |pillar| + expect(page).to have_text(pillar.text.upcase) + end + end + it 'shows assessment results' do + find_all('label.country-assessment__more.pillar').each(&:click) areas = ASCOR::AssessmentIndicator.area.order(:id) ASCOR::AssessmentIndicator.pillar.order(:id).each do |pillar| within_ascor_pillar pillar.text do @@ -50,7 +57,8 @@ end it 'generates EP.1.a.i and EP.1.a.ii metrics' do - find("label[for='ascor_assessment_indicator_#{ASCOR::AssessmentIndicator.find_by(code: 'EP.1').id}']").click + find_all('label.country-assessment__more.pillar').each(&:click) + find("label[for='area-ascor_assessment_indicator_#{ASCOR::AssessmentIndicator.find_by(code: 'EP.1').id}']").click expect(page).to have_text("i. What is the country's most recent emissions level?") expect(page).to have_text("ii. What is the country's most recent emissions trend?") end