diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index 70ea029f4..d0d9ecab4 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -14,4 +14,11 @@ def index def signin_required @application = ::Doorkeeper::Application.find_by(id: session.delete(:signin_missing_for_application)) end + +private + + def show_user_research_recruitment_banner? + !cookies[:dismiss_user_research_recruitment_banner] + end + helper_method :show_user_research_recruitment_banner? end diff --git a/app/controllers/user_research_recruitment_controller.rb b/app/controllers/user_research_recruitment_controller.rb new file mode 100644 index 000000000..67abc19a7 --- /dev/null +++ b/app/controllers/user_research_recruitment_controller.rb @@ -0,0 +1,11 @@ +class UserResearchRecruitmentController < ApplicationController + before_action :authenticate_user! + skip_after_action :verify_authorized + + def update + if params[:choice] == "dismiss-banner" + cookies[:dismiss_user_research_recruitment_banner] = true + redirect_to root_path + end + end +end diff --git a/app/views/root/index.html.erb b/app/views/root/index.html.erb index 0de36a672..89b09ab94 100644 --- a/app/views/root/index.html.erb +++ b/app/views/root/index.html.erb @@ -1,12 +1,13 @@ <% content_for :title, "Your applications" %> +<% if show_user_research_recruitment_banner? %> <% content_for :user_research_recruitment_banner do %>

Help us improve GOV.UK Publishing

We're holding research sessions to make Publishing work better.

- <%= form_tag "#" do %> + <%= form_tag user_research_recruitment_update_path, method: :put do %>
-
@@ -22,6 +23,7 @@
<% end %> +<% end %>
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/test/controllers/user_research_recruitment_controller_test.rb b/test/controllers/user_research_recruitment_controller_test.rb new file mode 100644 index 000000000..afc07d3b5 --- /dev/null +++ b/test/controllers/user_research_recruitment_controller_test.rb @@ -0,0 +1,35 @@ +require "test_helper" + +class UserResearchRecruitmentControllerTest < ActionController::TestCase + attr_reader :choice + + context "#update" do + context "when user clicks the button to dismiss the banner" do + setup do + @choice = "dismiss-banner" + end + + should "require signed in users" do + put :update, params: { choice: } + + assert_redirected_to new_user_session_path + 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 + end +end diff --git a/test/integration/user_research_recruitment_banner_test.rb b/test/integration/user_research_recruitment_banner_test.rb index 9e8a20699..5c3195717 100644 --- a/test/integration/user_research_recruitment_banner_test.rb +++ b/test/integration/user_research_recruitment_banner_test.rb @@ -26,6 +26,32 @@ class UserResearchRecruitmentBannerTest < ActionDispatch::IntegrationTest 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 + private def user_research_recruitment_banner_title