Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Newsletter checkbox unchecked by default (#3488)
* [FEAT] Registration newsletter checkbox unchecked by default * [FEAT] Added Modal to show message and action to user. Tests updated * [FIX] Corrections to pass tests
- Loading branch information
Showing
11 changed files
with
165 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
decidim-core/app/views/decidim/devise/shared/_newsletter_modal.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<div class="reveal" id="sign-up-newsletter-modal" data-reveal> | ||
<div class="reveal__header"> | ||
<h3 class="reveal__title"><%= t(".title") %></h3> | ||
<button class="close-button" data-close aria-label="Close modal" | ||
type="button"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="columns medium-10 medium-centered"> | ||
<p><%= t(".notice") %></p> | ||
</div> | ||
<div class="columns medium-10 medium-centered"> | ||
<div class="row"> | ||
<div class="columns medium-6"> | ||
<button type="buton" class="check-newsletter clear button secondary expanded" data-check=false><%= t(".buttons.uncheck") %></button> | ||
</div> | ||
<div class="columns medium-6"> | ||
<button type="buton" class="check-newsletter button expanded" data-check=true><%= t(".buttons.check") %></button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
def fill_registration_form | ||
fill_in :user_name, with: "Nikola Tesla" | ||
fill_in :user_nickname, with: "the-greatest-genius-in-history" | ||
fill_in :user_email, with: "nikola.tesla@example.org" | ||
fill_in :user_password, with: "sekritpass123" | ||
fill_in :user_password_confirmation, with: "sekritpass123" | ||
end | ||
|
||
describe "Registration", type: :system do | ||
let(:organization) { create(:organization) } | ||
let!(:terms_and_conditions_page) { create(:static_page, slug: "terms-and-conditions", organization: organization) } | ||
|
||
before do | ||
switch_to_host(organization.host) | ||
visit decidim.new_user_registration_path | ||
end | ||
|
||
context "when signing up" do | ||
describe "on first sight" do | ||
it "shows fields empty" do | ||
expect(page).to have_content("Sign up as") | ||
expect(page).to have_field("user_name", with: "") | ||
expect(page).to have_field("user_nickname", with: "") | ||
expect(page).to have_field("user_email", with: "") | ||
expect(page).to have_field("user_password", with: "") | ||
expect(page).to have_field("user_password_confirmation", with: "") | ||
expect(page).to have_field("user_newsletter", checked: false) | ||
end | ||
end | ||
end | ||
|
||
context "when newsletter checkbox is unchecked" do | ||
it "opens modal on submit" do | ||
within "form.new_user" do | ||
find("*[type=submit]").click | ||
end | ||
expect(page).to have_css("#sign-up-newsletter-modal", visible: true) | ||
expect(page).to have_current_path decidim.new_user_registration_path | ||
end | ||
|
||
it "checks when clicking the checking button" do | ||
within "form.new_user" do | ||
find("*[type=submit]").click | ||
end | ||
click_button "Check and continue" | ||
expect(page).to have_current_path decidim.new_user_registration_path | ||
expect(page).to have_css("#sign-up-newsletter-modal", visible: false) | ||
expect(page).to have_field("user_newsletter", checked: true) | ||
end | ||
|
||
it "submit after modal has been opened and selected an option" do | ||
within "form.new_user" do | ||
find("*[type=submit]").click | ||
end | ||
click_button "Keep uncheck" | ||
expect(page).to have_css("#sign-up-newsletter-modal", visible: false) | ||
fill_registration_form | ||
within "form.new_user" do | ||
find("*[type=submit]").click | ||
end | ||
expect(page).to have_current_path decidim.user_registration_path | ||
expect(page).to have_field("user_newsletter", checked: false) | ||
end | ||
end | ||
|
||
context "when newsletter checkbox is checked but submit fails" do | ||
before do | ||
fill_registration_form | ||
page.check("user_newsletter") | ||
end | ||
|
||
it "keeps the user newsletter checkbox true value" do | ||
within "form.new_user" do | ||
find("*[type=submit]").click | ||
end | ||
expect(page).to have_current_path decidim.user_registration_path | ||
expect(page).to have_field("user_newsletter", checked: true) | ||
end | ||
end | ||
end |