Skip to content

Commit

Permalink
fix: Add some tests to the feature
Browse files Browse the repository at this point in the history
  • Loading branch information
AyakorK committed Nov 20, 2023
1 parent d492e5e commit 6158821
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
4 changes: 4 additions & 0 deletions spec/system/examples/registration_hide_nickname_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
select "1992", from: :registration_user_year
check :registration_user_tos_agreement
check :registration_user_additional_tos
check :registration_user_newsletter

find("*[type=submit]").click
end
Expand Down Expand Up @@ -80,6 +81,7 @@
select "1992", from: :registration_user_year
check :registration_user_tos_agreement
check :registration_user_additional_tos
check :registration_user_newsletter

find("*[type=submit]").click
end
Expand Down Expand Up @@ -118,6 +120,7 @@
select "1992", from: :registration_user_year
check :registration_user_tos_agreement
check :registration_user_additional_tos
check :registration_user_newsletter

find("*[type=submit]").click
end
Expand Down Expand Up @@ -179,6 +182,7 @@
select "1992", from: :registration_user_year
check :registration_user_tos_agreement
check :registration_user_additional_tos
check :registration_user_newsletter

find("*[type=submit]").click
end
Expand Down
3 changes: 3 additions & 0 deletions spec/system/examples/registration_password_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@

check :registration_user_tos_agreement
check :registration_user_additional_tos
check :registration_user_newsletter

find("*[type=submit]").click
end

Expand Down Expand Up @@ -165,6 +167,7 @@
check :registration_user_newsletter
check :registration_user_tos_agreement
check :registration_user_additional_tos
check :registration_user_newsletter

check :registration_user_additional_tos
find("*[type=submit]").click
Expand Down
102 changes: 101 additions & 1 deletion spec/system/registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

describe "Registration", type: :system do
let(:organization) { create(:organization) }

before do
switch_to_host(organization.host)
end
Expand All @@ -17,4 +16,105 @@
it_behaves_like "on/off registration instant validation"

it_behaves_like "on/off registration hide nickname"

# --------- NEWSLETTER MODAL TESTS ---------

def fill_registration_form
fill_in :registration_user_name, with: "Nikola Tesla"
fill_in :registration_user_email, with: "[email protected]"
fill_in :registration_user_password, with: "sekritpass123"

select "City", from: :registration_user_living_area
select translated(city_residential_area.name), from: :registration_user_city_residential_area
select translated(city_work_area.name), from: :registration_user_city_work_area
select "Other", from: :registration_user_gender
select "September", from: :registration_user_month
select "1992", from: :registration_user_year
check :registration_user_tos_agreement
check :registration_user_additional_tos
end

context "when signing up" do
let!(:city_residential_area) { create(:scope, parent: city_parent_scope) }
let!(:city_work_area) { create(:scope, parent: city_parent_scope) }

let!(:city_parent_scope) do
create(:scope,
id: 58,
name: {
fr: "Ville de Toulouse",
en: "Toulouse city"
},
organization: organization)
end
let!(:metropolis_parent_scope) do
create(:scope,
id: 59,
name: {
fr: "Métropole de Toulouse",
en: "Toulouse metropolis"
},
organization: organization)
end

before do
allow(Decidim::FriendlySignup).to receive(:hide_nickname).and_return(true)
visit decidim.new_user_registration_path
end

describe "on first sight" do
it "shows fields empty" do
expect(page).to have_content("Sign up to participate")
expect(page).to have_field("registration_user_name", with: "")
expect(page).to have_field("registration_user_email", with: "")
expect(page).to have_field("registration_user_password", with: "")
expect(page).to have_field("registration_user_newsletter", checked: false)
end
end

context "when newsletter checkbox is unchecked" do
it "opens modal on submit" do
within ".new_user" do
find("*[type=submit]").click
end
expect(page).to have_css("#sign-up-newsletter-modal", visible: :visible)
end

it "checks when clicking the checking button" do
fill_registration_form
within ".new_user" do
find("*[type=submit]").click
end
expect(page).to have_css("#sign-up-newsletter-modal", visible: :all)
click_button "Check and continue"
end

it "submit after modal has been opened and selected an option" do
within ".new_user" do
find("*[type=submit]").click
end
click_button "Keep unchecked"
expect(page).to have_css("#sign-up-newsletter-modal", visible: :all)
fill_registration_form
within ".new_user" do
find("*[type=submit]").click
end
expect(page).to have_field("registration_user_newsletter", checked: false)
end
end

context "when newsletter checkbox is checked but submit fails" do
before do
fill_registration_form
page.check("registration_user_newsletter")
end

it "keeps the user newsletter checkbox true value" do
expect(page).to have_field("registration_user_newsletter", checked: true)
within ".new_user" do
find("*[type=submit]").click
end
end
end
end
end

0 comments on commit 6158821

Please sign in to comment.