Skip to content

Commit

Permalink
Add examples to check phone number validation in registration system …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
entantoencuanto committed Apr 17, 2024
1 parent b588a19 commit 07c8a7d
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion spec/system/registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ def fill_extra_user_fields
end

let(:phone_number) do
{ "enabled" => true }
{ "enabled" => true, "pattern" => phone_number_pattern, "placeholder" => nil }
end
let(:phone_number_pattern) { "^(\\+34)?[0-9 ]{9,12}$" }

let(:location) do
{ "enabled" => true }
Expand Down Expand Up @@ -107,6 +108,39 @@ def fill_extra_user_fields
expect(page).to have_content("message with a confirmation link has been sent")
end

context "with phone number pattern blank" do
let(:phone_number_pattern) { nil }

it "allows to create a new account" do
fill_registration_form
fill_extra_user_fields

within "form.new_user" do
find("*[type=submit]").click
end

expect(page).to have_content("message with a confirmation link has been sent")
end
end

context "with phone number pattern not compatible with number" do
let(:phone_number_pattern) { "^(\\+34)?[0-1 ]{9,12}$" }

it "does not allow to create a new account" do
fill_registration_form
fill_extra_user_fields

within "form.new_user" do
find("*[type=submit]").click
end

expect(page).to have_no_content("message with a confirmation link has been sent")
within("label[for='registration_user_phone_number']") do
expect(page).to have_content("There is an error in this field.")
end
end
end

it_behaves_like "mandatory extra user fields", "date_of_birth"
it_behaves_like "mandatory extra user fields", "gender"
it_behaves_like "mandatory extra user fields", "country"
Expand Down

0 comments on commit 07c8a7d

Please sign in to comment.