Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stimulus controller for dependent checkboxes and add specs #994

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
%p=t('.info_text', terminate_on: c.model.wizard.terminate_on, sektion: c.model.wizard.sektion_name)
= c.fields_for do |form|
= form.labeled(:termination_reason_id) do
= form.select :termination_reason_id, c.model.termination_reason_options, {prompt: true}
= form.select :termination_reason_id, c.model.termination_reason_options, {prompt: true}, class: "form-select form-select-sm"
41 changes: 21 additions & 20 deletions app/views/wizards/steps/termination/_summary.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@
-# 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.
- if current_user.backoffice? and c.model.mitglied_termination_by_section_only?
.alert.alert-info
= t('.termination_by_section_only')
- if c.model.family_membership?
.alert.alert-warning
%p= t('.family_warning', family_member_names: c.model.family_member_names)
%p= t('.info_text', terminate_on: c.model.wizard.terminate_on, sektion: c.model.wizard.sektion_name)
= c.fields_for do |form|
= form.labeled(:termination_reason_id) do
= form.select :termination_reason_id, c.model.termination_reason_options, {prompt: true}
.alert.alert-info
%strong=t('.data_retention_info_title')
%p=t('.data_retention_info_text')
= form.labeled(:data_retention_consent) do
= form.check_box :data_retention_consent
%p

- stimulus_ctrl = 'form-field-check-dependent'
%div{data: { controller: stimulus_ctrl }}
- if current_user.backoffice? and c.model.mitglied_termination_by_section_only?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- if current_user.backoffice? and c.model.mitglied_termination_by_section_only?
- if current_user.backoffice? && c.model.mitglied_termination_by_section_only?

.alert.alert-info
= t('.termination_by_section_only')
- if c.model.family_membership?
.alert.alert-warning
%p= t('.family_warning', family_member_names: c.model.family_member_names)
%p= t('.info_text', terminate_on: c.model.wizard.terminate_on, sektion: c.model.wizard.sektion_name)
= c.fields_for do |form|
= form.labeled(:termination_reason_id) do
= form.select :termination_reason_id, c.model.termination_reason_options, {prompt: true}, class: "form-select form-select-sm"
.alert.alert-info
%strong=t('.data_retention_info_title')
%p=t('.data_retention_info_text')
= form.labeled(:data_retention_consent) do
= form.check_box :data_retention_consent, {data: { "#{stimulus_ctrl}-target" => "checkbox" }}
= t('.newsletter_info_text')
= form.labeled(:subscribe_newsletter) do
= form.check_box :subscribe_newsletter, {prompt: true}
%p
= form.check_box :subscribe_newsletter, {prompt: true, data: { action: "#{stimulus_ctrl}#handleCheckbox", "dependent-checkbox" => true }}
= t('.fundraiser_info_text')
= form.labeled(:subscribe_fundraising_list) do
= form.check_box :subscribe_fundraising_list, {prompt: true}
= form.labeled(:subscribe_fundraising_list) do
= form.check_box :subscribe_fundraising_list, {prompt: true, data: { action: "#{stimulus_ctrl}#handleCheckbox", "dependent-checkbox" => true }}
40 changes: 40 additions & 0 deletions spec/features/memberships/sac_terminate_membership_wizard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,46 @@
.to change { role.termination_reason }.from(nil).to(termination_reason)
.and change { role.delete_on }.to(Date.new(Date.current.year, 12, 31))
end

it "checks data_retention_consent when subscribe_newsletter is checked" do
visit history_group_person_path(group_id: group.id, id: person.id)
within("#role_#{role.id}") do
click_link "Austritt"
end
choose "Sofort"
click_button "Weiter"
check "Newsletter beibehalten"
expect(find("#wizards_memberships_terminate_sac_membership_wizard_summary_data_retention_consent")).to be_checked
uncheck "Newsletter beibehalten"
expect(find("#wizards_memberships_terminate_sac_membership_wizard_summary_data_retention_consent")).not_to be_checked
end

it "checks data_retention_consent when sac spenden is checked" do
visit history_group_person_path(group_id: group.id, id: person.id)
within("#role_#{role.id}") do
click_link "Austritt"
end
choose "Sofort"
click_button "Weiter"
check "Ich möchte weiterhin über Spendenaktionen informiert werden."
expect(find("#wizards_memberships_terminate_sac_membership_wizard_summary_data_retention_consent")).to be_checked
uncheck "Ich möchte weiterhin über Spendenaktionen informiert werden."
expect(find("#wizards_memberships_terminate_sac_membership_wizard_summary_data_retention_consent")).not_to be_checked
end

it "check newsletter and sac spenden uncheck one, doesnt uncheck data_retention_consent" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it "check newsletter and sac spenden uncheck one, doesnt uncheck data_retention_consent" do
it "do not uncheck data_retention_consent when unchecking newsletter or sac spenden" do

visit history_group_person_path(group_id: group.id, id: person.id)
within("#role_#{role.id}") do
click_link "Austritt"
end
choose "Sofort"
click_button "Weiter"
check "Newsletter beibehalten"
check "Ich möchte weiterhin über Spendenaktionen informiert werden."
expect(find("#wizards_memberships_terminate_sac_membership_wizard_summary_data_retention_consent")).to be_checked
uncheck "Newsletter beibehalten"
expect(find("#wizards_memberships_terminate_sac_membership_wizard_summary_data_retention_consent")).to be_checked
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(find("#wizards_memberships_terminate_sac_membership_wizard_summary_data_retention_consent")).to be_checked
expect(find("#wizards_memberships_terminate_sac_membership_wizard_summary_data_retention_consent")).to be_checked
uncheck "Ich möchte weiterhin über Spendenaktionen informiert werden."
expect(find("#wizards_memberships_terminate_sac_membership_wizard_summary_data_retention_consent")).to be_checked

Noch testen obs beim anderen Feld auch so ist

end
end

context "as normal user" do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/memberships/terminate_sac_membership_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
end.not_to(change { person.subscriptions.count })
end

it "creates newsletter subscription" do
it "creates fundraising subscription" do
params[:subscribe_fundraising_list] = true
expect do
expect(termination.save!).to eq true
Expand Down
Loading