diff --git a/app/domain/invoices/sac_memberships/section_signup_fee_presenter.rb b/app/domain/invoices/sac_memberships/section_signup_fee_presenter.rb index f5f988289..15948f00e 100644 --- a/app/domain/invoices/sac_memberships/section_signup_fee_presenter.rb +++ b/app/domain/invoices/sac_memberships/section_signup_fee_presenter.rb @@ -27,7 +27,7 @@ class SectionSignupFeePresenter delegate :discount_factor, to: :context attr_reader :beitragskategorie, :section - def initialize(section, beitragskategorie, date = Time.zone.today) + def initialize(section, beitragskategorie, date: Time.zone.today) @section = section @beitragskategorie = ActiveSupport::StringInquirer.new(beitragskategorie.to_s) @context = Context.new(date) @@ -45,9 +45,9 @@ def beitragskategorie_label I18n.t("beitragskategorien.#{beitragskategorie}", scope: i18n_scope) end - def beitragskategorie_amount + def beitragskategorie_amount(skip_entry_fee: false) parts = [format_position_amount(:annual_fee)] - if entry_fee.positive? + if entry_fee.positive? && !skip_entry_fee parts += [translate_position_text(:entry_fee)] parts += [format_position_amount(:entry_fee)] end diff --git a/app/models/wizards/memberships/join_zusatzsektion.rb b/app/models/wizards/memberships/join_zusatzsektion.rb index 92b6b865a..de335880e 100644 --- a/app/models/wizards/memberships/join_zusatzsektion.rb +++ b/app/models/wizards/memberships/join_zusatzsektion.rb @@ -51,8 +51,12 @@ def backoffice? @backoffice end - def fees_for(beitragskategorie, reference_date) - Invoices::SacMemberships::SectionSignupFeePresenter.new(choose_sektion.group, beitragskategorie, reference_date) + def fees_for(beitragskategorie) + Invoices::SacMemberships::SectionSignupFeePresenter.new( + choose_sektion.group, + beitragskategorie, + date: Time.zone.now.beginning_of_year + ) end private diff --git a/app/models/wizards/memberships/switch_stammsektion.rb b/app/models/wizards/memberships/switch_stammsektion.rb index ea9344704..d3ccd07d0 100644 --- a/app/models/wizards/memberships/switch_stammsektion.rb +++ b/app/models/wizards/memberships/switch_stammsektion.rb @@ -43,8 +43,12 @@ def backoffice? @backoffice end - def fees_for(beitragskategorie, reference_date) - Invoices::SacMemberships::SectionSignupFeePresenter.new(choose_sektion.group, beitragskategorie, reference_date) + def fees_for(beitragskategorie) + Invoices::SacMemberships::SectionSignupFeePresenter.new( + choose_sektion.group, + beitragskategorie, + date: Time.zone.now.beginning_of_year + ) end private diff --git a/app/models/wizards/signup/sektion_wizard.rb b/app/models/wizards/signup/sektion_wizard.rb index a19d072a7..9549fb546 100644 --- a/app/models/wizards/signup/sektion_wizard.rb +++ b/app/models/wizards/signup/sektion_wizard.rb @@ -48,8 +48,8 @@ def fee fees_for(beitragskategorie) end - def fees_for(beitragskategorie, reference_date = Time.zone.today) - Invoices::SacMemberships::SectionSignupFeePresenter.new(group.layer_group, beitragskategorie, reference_date) + def fees_for(beitragskategorie) + Invoices::SacMemberships::SectionSignupFeePresenter.new(group.layer_group, beitragskategorie) end private diff --git a/app/views/memberships/join_zusatzsektions/_form.html.haml b/app/views/memberships/join_zusatzsektions/_form.html.haml index f07659174..9bd899091 100644 --- a/app/views/memberships/join_zusatzsektions/_form.html.haml +++ b/app/views/memberships/join_zusatzsektions/_form.html.haml @@ -10,8 +10,8 @@ = c.with_aside do .col-md - if wizard.step(:choose_sektion)&.group - = render 'wizards/signup/section_fee_summary', active: true, - adult: wizard.fees_for(:adult, Time.zone.now.beginning_of_year), - family: wizard.fees_for(:family, Time.zone.now.beginning_of_year), - youth: wizard.fees_for(:youth, Time.zone.now.beginning_of_year) + = render 'wizards/signup/section_fee_summary', active: true, skip_entry_fee: true, + adult: wizard.fees_for(:adult), + family: wizard.fees_for(:family), + youth: wizard.fees_for(:youth) = render(SelfRegistration::InfosComponent.new) diff --git a/app/views/memberships/switch_stammsektions/_form.html.haml b/app/views/memberships/switch_stammsektions/_form.html.haml index 62775eae8..2f0ebf0f6 100644 --- a/app/views/memberships/switch_stammsektions/_form.html.haml +++ b/app/views/memberships/switch_stammsektions/_form.html.haml @@ -11,7 +11,7 @@ .col-md - if wizard.step(:choose_sektion)&.group = render 'wizards/signup/section_fee_summary', active: true, - adult: wizard.fees_for(:adult, Time.zone.now.beginning_of_year), - family: wizard.fees_for(:family, Time.zone.now.beginning_of_year), - youth: wizard.fees_for(:youth, Time.zone.now.beginning_of_year) + adult: wizard.fees_for(:adult), + family: wizard.fees_for(:family), + youth: wizard.fees_for(:youth) = render(SelfRegistration::InfosComponent.new) diff --git a/app/views/wizards/signup/_section_fee_summary.html.haml b/app/views/wizards/signup/_section_fee_summary.html.haml index 1285d915d..e167ab9e3 100644 --- a/app/views/wizards/signup/_section_fee_summary.html.haml +++ b/app/views/wizards/signup/_section_fee_summary.html.haml @@ -2,6 +2,8 @@ -# Affero General Public License version 3 or later. See the COPYING file at the top-level directory -# or at https://github.com/hitobito/hitobito. +- amount_args = local_assigns.slice(:skip_entry_fee).to_h + %aside.card{class: ("d-none" unless active)} .card-body %h2.card-title=t('.title', section: adult.section) @@ -10,10 +12,10 @@ %tbody %tr %td= adult.beitragskategorie_label - %td= adult.beitragskategorie_amount + %td= adult.beitragskategorie_amount(**amount_args) %tr.border-top %td= family.beitragskategorie_label - %td= family.beitragskategorie_amount + %td= family.beitragskategorie_amount(**amount_args) %tr.border-top %td= youth.beitragskategorie_label - %td= youth.beitragskategorie_amount + %td= youth.beitragskategorie_amount(**amount_args) diff --git a/spec/domain/invoices/sac_memberships/section_signup_fee_presenter_spec.rb b/spec/domain/invoices/sac_memberships/section_signup_fee_presenter_spec.rb index f3bd1db1a..ccca23868 100644 --- a/spec/domain/invoices/sac_memberships/section_signup_fee_presenter_spec.rb +++ b/spec/domain/invoices/sac_memberships/section_signup_fee_presenter_spec.rb @@ -32,11 +32,21 @@ expect(presenter.beitragskategorie_label).to eq expected_labels[beitragskategorie] end - it "has identical beitragskategorie_amount all year long" do - travel_to(Date.new(2024, 11)) do - parts = presenter.beitragskategorie_amount.split(" + ") - expect(parts.first).to eq "CHF #{format("%.2f", annual_fee)}" - expect(parts.second).to eq "einmalige Eintrittsgebühr CHF #{format("%.2f", entry_fee)}" + describe "beitragskategorie_amount" do + it "is identical all year long" do + travel_to(Date.new(2024, 11)) do + parts = presenter.beitragskategorie_amount.split(" + ") + expect(parts.first).to eq "CHF #{format("%.2f", annual_fee)}" + expect(parts.second).to eq "einmalige Eintrittsgebühr CHF #{format("%.2f", entry_fee)}" + end + end + + it "can exclude entry_fee" do + travel_to(Date.new(2024, 11)) do + parts = presenter.beitragskategorie_amount(skip_entry_fee: true).split(" + ") + expect(parts.first).to eq "CHF #{format("%.2f", annual_fee)}" + expect(parts.second).to be_nil + end end end diff --git a/spec/features/memberships/join_zusatzsektion_spec.rb b/spec/features/memberships/join_zusatzsektion_spec.rb index 05d4390a5..e6d79c7d1 100644 --- a/spec/features/memberships/join_zusatzsektion_spec.rb +++ b/spec/features/memberships/join_zusatzsektion_spec.rb @@ -92,6 +92,7 @@ click_on "Weiter" expect(page).to have_css "li.active", text: "Bestätigung" expect(page).to have_content "Beitragskategorien SAC Matterhorn" + expect(page).not_to have_css(".card", text: "einmalige Eintrittsgebühr") expect do click_on "Kostenpflichtig bestellen" expect(page).to have_css "#flash .alert-success", diff --git a/spec/views/wizards/signup/_section_fee_summary.html.haml_spec.rb b/spec/views/wizards/signup/_section_fee_summary.html.haml_spec.rb new file mode 100644 index 000000000..7fb886cb6 --- /dev/null +++ b/spec/views/wizards/signup/_section_fee_summary.html.haml_spec.rb @@ -0,0 +1,52 @@ +# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of +# hitobito_sac_cas and licensed under the Affero General Public License version 3 +# or later. See the COPYING file at the top-level directory or at +# https://github.com/hitobito/hitobito_sac_cas. + +require "spec_helper" + +describe "wizards/signup/_section_fee_summary.html.haml" do + include FormatHelper + let(:group) { groups(:bluemlisalp) } + let(:adult) { fees_for(:adult) } + let(:family) { fees_for(:family) } + let(:youth) { fees_for(:youth) } + + let(:dom) { + Capybara::Node::Simple.new(@rendered) + } + + def fees_for(beitragskategorie) + Invoices::SacMemberships::SectionSignupFeePresenter.new(group, beitragskategorie, date: Time.zone.now.beginning_of_year) + end + + it "is hidden if not active" do + render locals: {adult:, family:, youth:, active: false} + expect(dom).to have_css "aside.card.d-none" + end + + it "is hidden if not active" do + render locals: {adult:, family:, youth:, active: true} + expect(dom).to have_css "aside.card:not(.d-none)" + end + + it "renders label and amount" do + render locals: {adult:, family:, youth:, active: true} + expect(dom).to have_css "tr:nth-of-type(1) td:nth-of-type(1)", text: "Einzelmitgliedschaft" + expect(dom).to have_css "tr:nth-of-type(1) td:nth-of-type(2)", text: "CHF 127.00 + einmalige Eintrittsgebühr CHF 20.00" + expect(dom).to have_css "tr:nth-of-type(2) td:nth-of-type(1)", text: "Familienmitgliedschaft" + expect(dom).to have_css "tr:nth-of-type(2) td:nth-of-type(2)", text: "CHF 179.00 + einmalige Eintrittsgebühr CHF 35.00" + expect(dom).to have_css "tr:nth-of-type(3) td:nth-of-type(1)", text: "Jugendmitgliedschaft" + expect(dom).to have_css "tr:nth-of-type(3) td:nth-of-type(2)", text: "CHF 76.00 + einmalige Eintrittsgebühr CHF 15.00" + end + + it "renders label and amount without entry fee" do + render locals: {adult:, family:, youth:, active: true, skip_entry_fee: true} + expect(dom).to have_css "tr:nth-of-type(1) td:nth-of-type(1)", text: "Einzelmitgliedschaft" + expect(dom).to have_css "tr:nth-of-type(1) td:nth-of-type(2)", text: "CHF 127.00" + expect(dom).to have_css "tr:nth-of-type(2) td:nth-of-type(1)", text: "Familienmitgliedschaft" + expect(dom).to have_css "tr:nth-of-type(2) td:nth-of-type(2)", text: "CHF 179.00" + expect(dom).to have_css "tr:nth-of-type(3) td:nth-of-type(1)", text: "Jugendmitgliedschaft" + expect(dom).to have_css "tr:nth-of-type(3) td:nth-of-type(2)", text: "CHF 76.00" + end +end