<% if yield(:back_link).present? %>
<%= render "govuk_publishing_components/components/back_link", href: yield(:back_link) %>
diff --git a/app/views/root/index.html.erb b/app/views/root/index.html.erb
index 5af694e18..4ef59d895 100644
--- a/app/views/root/index.html.erb
+++ b/app/views/root/index.html.erb
@@ -1,5 +1,30 @@
<% content_for :title, "Your applications" %>
+<% if show_user_research_recruitment_banner? %>
+ <% content_for :user_research_recruitment_banner do %>
+
diff --git a/config/routes.rb b/config/routes.rb
index 7103862cb..97a0b5e86 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -77,4 +77,6 @@
get "/signin-required" => "root#signin_required"
root to: "root#index"
+
+ put "/user-research-recruitment/update" => "user_research_recruitment#update"
end
diff --git a/db/migrate/20230804094159_add_user_research_recruitment_banner_hidden_to_users.rb b/db/migrate/20230804094159_add_user_research_recruitment_banner_hidden_to_users.rb
new file mode 100644
index 000000000..fa15027a5
--- /dev/null
+++ b/db/migrate/20230804094159_add_user_research_recruitment_banner_hidden_to_users.rb
@@ -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
diff --git a/db/schema.rb b/db/schema.rb
index fd8029a12..23ce30460 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.0].define(version: 2023_08_02_095323) do
+ActiveRecord::Schema[7.0].define(version: 2023_08_04_094159) do
create_table "batch_invitation_application_permissions", id: :integer, charset: "utf8mb3", force: :cascade do |t|
t.integer "batch_invitation_id", null: false
t.integer "supported_permission_id", null: false
@@ -209,6 +209,7 @@
t.boolean "require_2sv", default: false, null: false
t.string "reason_for_2sv_exemption"
t.date "expiry_date_for_2sv_exemption"
+ t.boolean "user_research_recruitment_banner_hidden", default: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["invitation_token"], name: "index_users_on_invitation_token"
t.index ["invited_by_id"], name: "index_users_on_invited_by_id"
diff --git a/test/controllers/user_research_recruitment_controller_test.rb b/test/controllers/user_research_recruitment_controller_test.rb
new file mode 100644
index 000000000..91d7e7a3b
--- /dev/null
+++ b/test/controllers/user_research_recruitment_controller_test.rb
@@ -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
diff --git a/test/integration/user_research_recruitment_banner_test.rb b/test/integration/user_research_recruitment_banner_test.rb
new file mode 100644
index 000000000..f8559c626
--- /dev/null
+++ b/test/integration/user_research_recruitment_banner_test.rb
@@ -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