From 6dd42e7150ff73e2525b182308e0fb69a07fc9c8 Mon Sep 17 00:00:00 2001 From: aaronskiba <71047780+aaronskiba@users.noreply.github.com> Date: Thu, 25 Jan 2024 14:44:39 -0700 Subject: [PATCH 1/2] Avoid rendering "You must answer at least 0% ..." Add extra handling for set_visibility_info. Only render "You must answer at least %{percentage}%% of the questions" when percentage is a non-zero value. --- app/views/plans/_share_form.html.erb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/views/plans/_share_form.html.erb b/app/views/plans/_share_form.html.erb index e68cede35a..6e94db3391 100644 --- a/app/views/plans/_share_form.html.erb +++ b/app/views/plans/_share_form.html.erb @@ -4,13 +4,21 @@ <% administerable = @plan.administerable_by?(current_user.id) %> <% email_tooltip = _("Enter the email address of your collaborator: If they are already using #{ApplicationService.application_name}, they will see this plan on their dashboard, and recieve an email. If they are not currently using #{ApplicationService.application_name}, they will recieve an email inviting them to the tool so they can collaborate on your plan.") %> <% permissions_tooltip = _('Co-owner: Has admin-rights to the plan (can invite other users, view the plan, answer questions, or comment). Editor: Has edit-rights to the plan (can view the plan, answer questions, or comment). Read Only: Has read-rights to the plan (can view the plan or comment)') %> +<% percentage = Rails.configuration.x.plans.default_percentage_answered %> +<%# Only include "You must answer at least x% ..." if x is non-zero %> +<% set_visibility_info = if percentage&.nonzero? + _('Public or organisational visibility is intended for finished plans. You must answer at least %{percentage}%% of the questions to enable these options. Note: test plans are set to private visibility by default.') % { percentage: percentage } + else + _('Public or organisational visibility is intended for finished plans. Note: test plans are set to private visibility by default.') + end +%>

<%= _('Set plan visibility') %>

<% allow_visibility = @plan.visibility_allowed? %> <%= form_with model: @plan, id: "set_visibility" do |f| %> > -

<%= _('Public or organisational visibility is intended for finished plans. You must answer at least %{percentage}%% of the questions to enable these options. Note: test plans are set to private visibility by default.') % { :percentage => Rails.configuration.x.plans.default_percentage_answered } %>

+

<%= set_visibility_info %>

From 433ccb9404d4e761e766d613e5f32ae6ae1eb9c9 Mon Sep 17 00:00:00 2001 From: aaronskiba <71047780+aaronskiba@users.noreply.github.com> Date: Fri, 26 Jan 2024 11:32:07 -0700 Subject: [PATCH 2/2] Test set_visibility_info with different percents --- spec/views/plans/_share_form.html.erb_spec.rb | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 spec/views/plans/_share_form.html.erb_spec.rb diff --git a/spec/views/plans/_share_form.html.erb_spec.rb b/spec/views/plans/_share_form.html.erb_spec.rb new file mode 100644 index 0000000000..8a3cc99766 --- /dev/null +++ b/spec/views/plans/_share_form.html.erb_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'plans/_share_form.html.erb' do + before(:each) do + @plan = create(:plan, :creator) + @user = @plan.owner + sign_in(@user) + @plan_roles = @plan.roles.where(active: true) + end + + it 'Renders set_visibility_info correctly according to default_percentage_answered value' do + # Check what renders when default_percentage_answered is between 1 and 100 + Rails.configuration.x.plans.default_percentage_answered = rand(1..100) + render partial: 'plans/share_form' + expect(rendered.include?(format(_('Public or organisational visibility is intended for finished plans. ' \ + 'You must answer at least %{percentage}%% of the questions to enable ' \ + 'these options. Note: test plans are set to private visibility by default.'), + percentage: Rails.configuration.x.plans.default_percentage_answered))).to eql(true) + + # Check what renders when default_percentage_answered is 0 + Rails.configuration.x.plans.default_percentage_answered = 0 + render partial: 'plans/share_form' + expect(rendered.include?(_('Public or organisational visibility is intended for finished plans. ' \ + 'Note: test plans are set to private visibility by default.'))).to eql(true) + end +end