diff --git a/spec/system/settings/onboarding_channels_spec.rb b/spec/system/settings/onboarding_channels_spec.rb new file mode 100644 index 000000000..d9dbec141 --- /dev/null +++ b/spec/system/settings/onboarding_channels_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Configuring Onboarding Channels' do + let(:admin) { create(:user, admin: true) } + let(:organization) { create(:organization) } + let(:jwt_payload) { { invite_code: SecureRandom.base64(16), action: 'onboarding', organization_id: organization.id } } + let(:jwt) do + JsonWebToken.encode(jwt_payload) + end + + it 'allows activating and deactivating onboarding channels' do + visit settings_path(as: admin) + + # All activated by default + within('.OnboardingChannelsCheckboxes') do + Setting.channels.each_key do |key| + expect(page).to have_field(key.to_s.camelize, id: "setting[channels][#{key}]", checked: true) + end + + uncheck 'Email' + end + + click_on 'Speichern' + expect(page).to have_current_path(settings_path(as: admin)) + + within('.OnboardingChannelsCheckboxes') do + Setting.channels.keys.map(&:to_sym).each do |key| + checked_status = !key.eql?(:email) + expect(page).to have_field(key.to_s.camelize, id: "setting[channels][#{key}]", checked: checked_status) + end + end + + visit onboarding_path(jwt: jwt) + + within('.OnboardingChannelButtons') do + Setting.channels.keys.map(&:to_sym).each do |key| + unless key.eql?(:email) + expect(page).to have_link(key.to_s.camelize, class: 'Button', href: "/onboarding/#{key.to_s.dasherize}?jwt=#{jwt}") + end + end + end + end +end diff --git a/spec/system/settings/settings_form_spec.rb b/spec/system/settings/settings_form_spec.rb index d8187a35e..079035a4a 100644 --- a/spec/system/settings/settings_form_spec.rb +++ b/spec/system/settings/settings_form_spec.rb @@ -8,6 +8,11 @@ it 'Exposes certain fields only to admin' do visit settings_path(as: user) + # Channels + Setting.channels.each do |key, _value| + expect(page).not_to have_field(key.to_s.camelize, id: "setting[channels][#{key}]") + end + # Data protection link expect(page).not_to have_field('Link zur Datenschutzerklärung') expect(page).not_to have_text(/Der Link wird während des Onboardings in der Fußzeile angezeigt. Vor der Anmeldung müssen neue/) @@ -31,6 +36,11 @@ user.update(admin: true) visit settings_path(as: user) + # Channels + Setting.channels.each do |key, _value| + expect(page).to have_field(key.to_s.camelize, id: "setting[channels][#{key}]") + end + # Data protection link expect(page).to have_field('Link zur Datenschutzerklärung') expect(page).to have_text(/Der Link wird während des Onboardings in der Fußzeile angezeigt. Vor der Anmeldung müssen neue/)