diff --git a/decidim-proposals/app/services/decidim/proposals/diff_renderer.rb b/decidim-proposals/app/services/decidim/proposals/diff_renderer.rb index e13654401f22f..c9225e574a7e0 100644 --- a/decidim-proposals/app/services/decidim/proposals/diff_renderer.rb +++ b/decidim-proposals/app/services/decidim/proposals/diff_renderer.rb @@ -15,13 +15,14 @@ def attribute_types address: :string, latitude: :string, longitude: :string, - decidim_proposals_proposal_state_id: :string + decidim_proposals_proposal_state_id: :state } end # Parses the values before parsing the changeset. def parse_changeset(attribute, values, type, diff) return parse_scope_changeset(attribute, values, type, diff) if type == :scope + return parse_state_changeset(attribute, values, type, diff) if type == :state values = parse_values(attribute, values) old_value = values[0] @@ -37,6 +38,22 @@ def parse_changeset(attribute, values, type, diff) ) end + def parse_state_changeset(attribute, values, type, diff) + return unless diff + + old_scope = Decidim::Proposals::ProposalState.find_by(id: values[0]) + new_scope = Decidim::Proposals::ProposalState.find_by(id: values[1]) + + diff.update( + attribute => { + type:, + label: I18n.t(attribute, scope: i18n_scope), + old_value: old_scope ? translated_attribute(old_scope.title) : "", + new_value: new_scope ? translated_attribute(new_scope.title) : "" + } + ) + end + # Handles which values to use when diffing emendations and # normalizes line endings of the :body attribute values. # Returns and Array of two Strings. diff --git a/decidim-proposals/config/locales/en.yml b/decidim-proposals/config/locales/en.yml index d6a80889b28af..9adfd0f312adb 100644 --- a/decidim-proposals/config/locales/en.yml +++ b/decidim-proposals/config/locales/en.yml @@ -19,6 +19,7 @@ en: automatic_hashtags: Hashtags automatically added body: Body category_id: Category + decidim_proposals_proposal_state_id: State decidim_scope_id: Scope has_address: Has address scope_id: Scope diff --git a/decidim-proposals/spec/system/proposals_versions_spec.rb b/decidim-proposals/spec/system/proposals_versions_spec.rb index f1e900e0addac..7ac973a510a51 100644 --- a/decidim-proposals/spec/system/proposals_versions_spec.rb +++ b/decidim-proposals/spec/system/proposals_versions_spec.rb @@ -102,5 +102,31 @@ end end end + + it "show the correct state" do + form_params = { + internal_state: "evaluating", + answer: { en: "Foo" }, + cost: 2000, + cost_report: { en: "Cost report" }, + execution_period: { en: "Execution period" } + } + form = Decidim::Proposals::Admin::ProposalAnswerForm.from_params(form_params).with_context( + current_user: proposal.authors.first, + current_component: proposal.component, + current_organization: proposal.component.organization + ) + Decidim::Proposals::Admin::AnswerProposal.call(form, proposal) + + visit current_path + click_on("Version 3 of 3") + + within "#diff-for-state" do + expect(page).to have_content("State") + within ".diff > ul > .ins" do + expect(page).to have_content("Evaluating") + end + end + end end end