Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user research recruitment banner #2301

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/assets/stylesheets/_user_research_recruitment_banner.scss
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;
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "govuk_publishing_components/all_components";
@import "user_research_recruitment_banner";

// TODO: move into component
.gem-c-success-alert,
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/root_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] && !current_user.user_research_recruitment_banner_hidden?
end
helper_method :show_user_research_recruitment_banner?
end
16 changes: 16 additions & 0 deletions app/controllers/user_research_recruitment_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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 dismiss_banner
cookies[:dismiss_user_research_recruitment_banner] = true
redirect_to root_path
end

def participate
current_user.update!(user_research_recruitment_banner_hidden: true)
redirect_to USER_RESEARCH_RECRUITMENT_FORM_URL, allow_other_host: true
end
end
2 changes: 2 additions & 0 deletions app/views/layouts/admin_layout.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
navigation_items: navigation_items,
}%>

<%= yield(:user_research_recruitment_banner) %>

<div class="govuk-width-container">
<% if yield(:back_link).present? %>
<%= render "govuk_publishing_components/components/back_link", href: yield(:back_link) %>
Expand Down
26 changes: 26 additions & 0 deletions app/views/root/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
<% content_for :title, "Your applications" %>

<% if show_user_research_recruitment_banner? %>
<% content_for :user_research_recruitment_banner do %>
<section class="user-research-recruitment-banner">
<div class="govuk-width-container">
<hr class="user-research-recruitment-banner__divider govuk-section-break govuk-section-break--l govuk-!-margin-top-0">
<h1 class="user-research-recruitment-banner__title govuk-heading-xl">Help us improve GOV.UK Publishing</h1>
<p class="user-research-recruitment-banner__intro govuk-body">We're holding research sessions to make Publishing work better.</p>
<%= form_tag user_research_recruitment_participate_path do %>
<div class="user-research-recruitment-banner__buttons govuk-button-group">
<button class="govuk-!-font-size-24 govuk-!-font-weight-bold govuk-button govuk-button--start govuk-button--inverse" type="submit" formtarget="_blank">
<span>Find out more</span>
<svg class="govuk-button__start-icon govuk-!-display-none-print" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" focusable="false" aria-hidden="true">
<path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path>
</svg>
</button>

<button class="govuk-button govuk-button--secondary govuk-button--inverse" type="submit" formaction="<%= user_research_recruitment_dismiss_banner_path %>">
Hide this
</button>
</div>
<% end %>
</div>
</section>
<% end %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,7 @@
get "/signin-required" => "root#signin_required"

root to: "root#index"

post "/user-research-recruitment/dismiss-banner" => "user_research_recruitment#dismiss_banner"
post "/user-research-recruitment/participate" => "user_research_recruitment#participate"
end
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
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
48 changes: 48 additions & 0 deletions test/controllers/user_research_recruitment_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "test_helper"

class UserResearchRecruitmentControllerTest < ActionController::TestCase
test "#dismiss_banner requires signed in users" do
post :dismiss_banner

assert_redirected_to new_user_session_path
end

test "#dismiss_banner sets session cookie" do
sign_in create(:user)

post :dismiss_banner

assert cookies[:dismiss_user_research_recruitment_banner]
end

test "#dismiss_banner redirects to root path" do
sign_in create(:user)

post :dismiss_banner

assert_redirected_to root_path
end

test "#participate requires users to be signed in" do
post :participate

assert_redirected_to new_user_session_path
end

test "#participate sets user_research_recruitment_banner_hidden to true for the current_user" do
user = create(:user)
sign_in user

post :participate

assert user.user_research_recruitment_banner_hidden?
end

test "#participate redirects to the google form" do
sign_in create(:user)

post :participate

assert_redirected_to UserResearchRecruitmentController::USER_RESEARCH_RECRUITMENT_FORM_URL
end
end
94 changes: 94 additions & 0 deletions test/integration/user_research_recruitment_banner_test.rb
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_participate_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
Loading