Skip to content

Commit

Permalink
Add system specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwr18 committed Sep 18, 2023
1 parent 3720025 commit 36342e6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
45 changes: 45 additions & 0 deletions spec/system/settings/onboarding_channels_spec.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions spec/system/settings/settings_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand All @@ -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/)
Expand Down

0 comments on commit 36342e6

Please sign in to comment.