-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2303 from alphagov/add-user-research-recruitment-…
…banner-v3 Add user research recruitment banner
- Loading branch information
Showing
11 changed files
with
235 additions
and
1 deletion.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
app/assets/stylesheets/_user_research_recruitment_banner.scss
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,22 @@ | ||
.user-research-recruitment-banner { | ||
background-color: $govuk-brand-colour; | ||
@include govuk-responsive-padding(8, "top"); | ||
} | ||
|
||
.user-research-recruitment-banner__divider { | ||
border-bottom: 1px solid govuk-colour("white"); | ||
} | ||
|
||
.user-research-recruitment-banner__title { | ||
color: govuk-colour("white"); | ||
@include govuk-responsive-margin(5, "bottom"); | ||
} | ||
|
||
.user-research-recruitment-banner__intro { | ||
color: govuk-colour("white"); | ||
} | ||
|
||
.user-research-recruitment-banner__buttons { | ||
@include govuk-responsive-padding(6, "bottom"); | ||
align-items: center; | ||
} |
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,17 @@ | ||
class UserResearchRecruitmentController < ApplicationController | ||
USER_RESEARCH_RECRUITMENT_FORM_URL = "https://docs.google.com/forms/d/1Bdu_GqOrSR4j6mbuzXkFTQg6FRktRMQc8Y-q879Mny8/viewform".freeze | ||
|
||
before_action :authenticate_user! | ||
skip_after_action :verify_authorized | ||
|
||
def update | ||
case params[:choice] | ||
when "participate" | ||
current_user.update!(user_research_recruitment_banner_hidden: true) | ||
redirect_to USER_RESEARCH_RECRUITMENT_FORM_URL, allow_other_host: true | ||
when "dismiss-banner" | ||
cookies[:dismiss_user_research_recruitment_banner] = true | ||
redirect_to root_path | ||
end | ||
end | ||
end |
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
5 changes: 5 additions & 0 deletions
5
db/migrate/20230804094159_add_user_research_recruitment_banner_hidden_to_users.rb
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,5 @@ | ||
class AddUserResearchRecruitmentBannerHiddenToUsers < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :users, :user_research_recruitment_banner_hidden, :boolean, default: false | ||
end | ||
end |
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
58 changes: 58 additions & 0 deletions
58
test/controllers/user_research_recruitment_controller_test.rb
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,58 @@ | ||
require "test_helper" | ||
|
||
class UserResearchRecruitmentControllerTest < ActionController::TestCase | ||
attr_reader :choice | ||
|
||
context "#update" do | ||
should "require users to be signed in" do | ||
put :update | ||
|
||
assert_redirected_to new_user_session_path | ||
end | ||
|
||
context "when user clicks the button to dismiss the banner" do | ||
setup do | ||
@choice = "dismiss-banner" | ||
end | ||
|
||
should "set session cookie" do | ||
sign_in create(:user) | ||
|
||
put :update, params: { choice: } | ||
|
||
assert cookies[:dismiss_user_research_recruitment_banner] | ||
end | ||
|
||
should "redirect to root path" do | ||
sign_in create(:user) | ||
|
||
put :update, params: { choice: } | ||
|
||
assert_redirected_to root_path | ||
end | ||
end | ||
|
||
context "when user clicks the button to participate in user research" do | ||
setup do | ||
@choice = "participate" | ||
end | ||
|
||
should "set user_research_recruitment_banner_hidden to true for the current_user" do | ||
user = create(:user) | ||
sign_in user | ||
|
||
put :update, params: { choice: } | ||
|
||
assert user.user_research_recruitment_banner_hidden? | ||
end | ||
|
||
should "redirect to the Google Form" do | ||
sign_in create(:user) | ||
|
||
put :update, params: { choice: } | ||
|
||
assert_redirected_to UserResearchRecruitmentController::USER_RESEARCH_RECRUITMENT_FORM_URL | ||
end | ||
end | ||
end | ||
end |
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,94 @@ | ||
require "test_helper" | ||
|
||
class UserResearchRecruitmentBannerTest < ActionDispatch::IntegrationTest | ||
should "not display the banner on the login page" do | ||
visit new_user_session_path | ||
|
||
assert_not has_content?(user_research_recruitment_banner_title) | ||
end | ||
|
||
should "display the banner on the dashboard" do | ||
user = create(:user, name: "user-name", email: "user@example.com") | ||
visit new_user_session_path | ||
signin_with(user) | ||
|
||
assert has_content?(user_research_recruitment_banner_title) | ||
assert has_css?("form[action='#{user_research_recruitment_update_path}']", text: "Find out more") | ||
end | ||
|
||
should "not display the banner on any page other than the dashboard" do | ||
user = create(:user, name: "user-name", email: "user@example.com") | ||
visit new_user_session_path | ||
signin_with(user) | ||
|
||
click_on "Change your email or password" | ||
|
||
assert_not has_content?(user_research_recruitment_banner_title) | ||
end | ||
|
||
should "hide the banner until the next session" do | ||
user = create(:user, name: "user-name", email: "user@example.com") | ||
|
||
using_session("Session 1") do | ||
visit new_user_session_path | ||
signin_with(user) | ||
|
||
assert has_content?(user_research_recruitment_banner_title) | ||
|
||
within ".user-research-recruitment-banner" do | ||
click_on "Hide this" | ||
end | ||
|
||
visit root_path | ||
|
||
assert_not has_content?(user_research_recruitment_banner_title) | ||
end | ||
|
||
using_session("Session 2") do | ||
visit new_user_session_path | ||
signin_with(user) | ||
|
||
assert has_content?(user_research_recruitment_banner_title) | ||
end | ||
end | ||
|
||
should "hide the banner permanently if the user clicks the button to participate in user research" do | ||
user = create(:user, name: "user-name", email: "user@example.com") | ||
|
||
using_session("Session 1") do | ||
visit new_user_session_path | ||
signin_with(user) | ||
|
||
assert has_content?(user_research_recruitment_banner_title) | ||
|
||
within ".user-research-recruitment-banner" do | ||
allowing_request_to_user_research_recruitment_google_form do | ||
click_on "Find out more" | ||
end | ||
end | ||
|
||
visit root_path | ||
|
||
assert_not has_content?(user_research_recruitment_banner_title) | ||
end | ||
|
||
using_session("Session 2") do | ||
visit new_user_session_path | ||
signin_with(user) | ||
|
||
assert_not has_content?(user_research_recruitment_banner_title) | ||
end | ||
end | ||
|
||
private | ||
|
||
def user_research_recruitment_banner_title | ||
"Help us improve GOV.UK Publishing" | ||
end | ||
|
||
def allowing_request_to_user_research_recruitment_google_form | ||
yield | ||
rescue ActionController::RoutingError | ||
raise unless current_url == UserResearchRecruitmentController::USER_RESEARCH_RECRUITMENT_FORM_URL | ||
end | ||
end |