Skip to content

Commit

Permalink
show welcome banner after dinopark sign up
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA committed Jul 9, 2019
1 parent 948fd1c commit 84a785e
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 1 deletion.
@@ -0,0 +1,29 @@
export default {
setupComponent(args, component) {
if ($.cookie("show_dinopark_banner")) {
component.set("visible", true)
}
},

actions: {
dismiss() {
this.set("visible", false)
$.removeCookie("show_dinopark_banner")
},

click(e) {
if ($(e.target).is('a')) {
$.removeCookie("show_dinopark_banner")
}
}
},

shouldRender(args, component) {
if (component.currentUser) {
return $.cookie("show_dinopark_banner")
} else {
$.removeCookie("show_dinopark_banner")
return false
}
}
}
@@ -0,0 +1,8 @@
{{#if visible}}
<div class="row">
<div class="alert alert-info dinopark-welcome-banner" role="alert">
<button type="button" class="close" aria-label="Close" {{action "dismiss"}}><span aria-hidden="true">&times;</span></button>
<span onclick={{action "click"}}>{{{i18n 'dinopark.welcome_banner' a_tag='<a href="/my/preferences/account">'}}}</span>
</div>
</div>
{{/if}}
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Expand Up @@ -13,6 +13,7 @@ en:
auth0:
name: "Mozilla"
dinopark:
welcome_banner: "Welcome to Mozilla Discourse! Complete your profile setup at any time in %{a_tag}your preferences</a>."
profile_url_title: "Mozilla People Directory Profile"
edit_short: "Edit"
edit_long: "Edit on people.mozilla.org"
Expand Down
1 change: 1 addition & 0 deletions lib/mozilla_iam/users_controller_extensions.rb
Expand Up @@ -7,6 +7,7 @@ def create
session[:authentication] = {} unless session[:authentication]
session[:authentication][:dinopark_enabled] = dinopark_enabled
params[:username] = UserNameSuggester.find_available_username_based_on(params[:username])
cookies["show_dinopark_banner"] = 1
end
super
end
Expand Down
2 changes: 1 addition & 1 deletion plugin.rb
@@ -1,6 +1,6 @@
# name: mozilla-iam
# about: A plugin to integrate Discourse with Mozilla's Identity and Access Management (IAM) system
# version: 1.2.2
# version: 1.2.3
# authors: Leo McArdle
# url: https://github.com/mozilla/discourse-mozilla-iam

Expand Down
16 changes: 16 additions & 0 deletions spec/requests/users_controller_spec.rb
Expand Up @@ -29,6 +29,14 @@
expect(User.find(JSON.parse(response.body)["user_id"]).username).to eq "jillbloggs"
expect(session[:authentication]&.[](:dinopark_enabled)).to be_nil
end

it "doesn't set show_dinopark_banner cookie" do
post "/u.json", params: create_params.merge({
dinopark_enabled: false
})
expect(response.status).to eq 200
expect(cookies["show_dinopark_banner"]).to be_nil
end
end

context "with dinopark_enabled" do
Expand All @@ -50,6 +58,14 @@
expect(User.find(JSON.parse(response.body)["user_id"]).username).to eq "jillbloggs1"
expect(session[:authentication]&.[](:dinopark_enabled)).to eq true
end

it "sets show_dinopark_banner cookie" do
post "/u.json", params: create_params.merge({
dinopark_enabled: true
})
expect(response.status).to eq 200
expect(cookies["show_dinopark_banner"]).to be
end
end
end

Expand Down
83 changes: 83 additions & 0 deletions test/javascripts/acceptance/dinopark-welcome-banner-test.js.es6
@@ -0,0 +1,83 @@
import { acceptance } from "helpers/qunit-helpers"

acceptance("Mozilla IAM - Dinopark Welcome Banner", {
loggedIn: true
})

QUnit.test("loading page without show_dinopark_banner cookie set", async assert => {
$.removeCookie("show_dinopark_banner")
await visit("/")

assert.notOk(
exists(".dinopark-welcome-banner"),
"dinopark welcome banner is not shown"
)
})

QUnit.test("loading page with show_dinopark_banner cookie set and clicking close", async assert => {
$.cookie("show_dinopark_banner", 1)
await visit("/")

assert.ok(
exists(".dinopark-welcome-banner"),
"dinopark welcome banner is shown"
)

await click(".dinopark-welcome-banner .close")

assert.notOk(
exists(".dinopark-welcome-banner"),
"clicking close buttons closes banner"
)
assert.equal(
$.cookie("show_dinopark_banner"),
null,
"clicking close buttons removes cookie"
)

$.removeCookie("show_dinopark_banner")
})

QUnit.skip("loading page with show_dinopark_banner cookie set and clicking link", async assert => {
$.cookie("show_dinopark_banner", 1)
await visit("/")

assert.ok(
exists(".dinopark-welcome-banner"),
"dinopark welcome banner is shown"
)

await click(".dinopark-welcome-banner a") // navigates qunit away

assert.equal(
$.cookie("show_dinopark_banner"),
null,
"clicking link removes cookie"
)
assert.equal(
currentRouteName(),
"preferences.account",
"clicking link navigates to user preferences"
)

$.removeCookie("show_dinopark_banner")
})

acceptance("Mozilla IAM - Dinopark Welcome Banner - Logged Out")

QUnit.test("logged out user with cookie", async assert => {
$.cookie("show_dinopark_banner", 1)
await visit("/")

assert.notOk(
exists(".dinopark-welcome-banner"),
"dinopark welcome banner isn't shown"
)
assert.equal(
$.cookie("show_dinopark_banner"),
null,
"cookie is removed"
)

$.removeCookie("show_dinopark_banner")
})

0 comments on commit 84a785e

Please sign in to comment.