Hide site-wide messaging for opted-out users (#8409) [deploy]

This commit is contained in:
Vaidehi Joshi 2020-06-11 11:34:04 -07:00 committed by GitHub
parent 7d58818efa
commit a3665406d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View file

@ -80,14 +80,20 @@ function renderBroadcast(broadcastElement, data) {
}
/**
* A function to determine if a broadcast should render
* Does not render broadcast it has already been inserted,
* or if the key for the broadcast's title exists in localStorage.
* A function to determine if a broadcast should render.
* Does not render a broadcast if the current user has opted-out.
* Does not render a broadcast it has already been inserted, or
* if the key for the broadcast's title exists in localStorage.
*
* @function initializeBroadcast
*/
function initializeBroadcast() {
const user = userData();
const data = broadcastData();
if (user && !user.display_announcements) {
return;
}
if (!data) {
return;
}

View file

@ -19,6 +19,7 @@ FactoryBot.define do
saw_onboarding { true }
checked_code_of_conduct { true }
checked_terms_and_conditions { true }
display_announcements { true }
signup_cta_variant { "navbar_basic" }
email_digest_periodic { false }
bg_color_hex { Faker::Color.hex_color }

View file

@ -86,5 +86,18 @@ RSpec.describe "User visits a homepage", type: :system do
expect_no_broadcast_data(page)
end
end
context "when opting-out of announcements" do
before do
user.update!(display_announcements: false)
create(:announcement_broadcast, active: true)
get "/async_info/base_data" # Explicitly ensure broadcast data is loaded before doing any checks
visit "/"
end
it "does not render the broadcast", js: true do
expect_no_broadcast_data(page)
end
end
end
end