Skip to content
This repository was archived by the owner on Mar 15, 2018. It is now read-only.

Commit 595c876

Browse files
author
Rob Hudson
committed
Only show recommended tab for opt-in users (bug 1097332)
1 parent 752c2cf commit 595c876

File tree

7 files changed

+69
-9
lines changed

7 files changed

+69
-9
lines changed

src/media/css/navbar.styl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
width: fit-content;
2222
}
2323

24+
// We hide the recommendations tab by default and enable it via JS if user is
25+
// logged in and opted in to recommendations.
26+
.tab-item.recommended {
27+
display: none;
28+
}
29+
.show-recommendations .tab-item.recommended {
30+
display: inline-block;
31+
}
32+
2433
.tab-link {
2534
border-bottom: 3px solid transparent;
2635
color: $navbar-text;

src/media/js/consumer_info.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ define('consumer_info',
1818
// by consumerInfo is coming from geoip, store it.
1919
user_helpers.set_region_geoip(data.region);
2020
}
21-
if (user.logged_in() && data.apps !== undefined) {
22-
user.update_apps(data.apps);
21+
if (user.logged_in()) {
22+
if (data.apps !== undefined) {
23+
user.update_apps(data.apps);
24+
}
25+
user.update_settings({
26+
enable_recommendations: data.enable_recommendations
27+
});
2328
}
2429
}
2530

@@ -41,7 +46,7 @@ define('consumer_info',
4146
// - User is logged out and we don't know the region already, or it's
4247
// not valid (we need the region to do all other API calls)
4348
// - User is logged in (we need the installed/purchased/developed apps
44-
// list, possibly region as well)
49+
// list, recommendation opt-out, possibly region as well)
4550
// - The caller is forcing us
4651
if (force || !already_had_region || user.logged_in()) {
4752
requests.get(urls.api.url('consumer_info')).then(

src/media/js/main.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ function(_) {
183183

184184
var logged_in = user.logged_in();
185185

186+
if (!logged_in) {
187+
z.body.removeClass('show-recommendations');
188+
}
189+
186190
siteConfig.promise.then(function () {
187191
if (capabilities.nativeFxA()) {
188192
// We might want to style things differently for native FxA users,
@@ -201,12 +205,20 @@ function(_) {
201205
nunjucks.env.render('fx-accounts-banner.html',
202206
{logged_in: logged_in}));
203207
}
208+
});
204209

210+
// TODO: Move this to the consumer-info callback when the waffle is
211+
// removed as we no longer require siteConfig for the waffle switch.
212+
$.when(siteConfig, consumer_info).then(function() {
205213
// To show or not to show the recommendations nav.
206-
if (logged_in && settings.switches.indexOf('recommendations') !== -1) {
214+
if (logged_in && user.get_setting('enable_recommendations') &&
215+
// TODO: Remove when waffle removed (bug 1083942).
216+
settings.switches.indexOf('recommendations') !== -1) {
207217
z.body.addClass('show-recommendations');
208218
}
219+
});
209220

221+
consumer_info.promise.then(function() {
210222
// Re-render footer region if necessary.
211223
var current_region = user_helpers.region('restofworld');
212224
if (current_region !== context.region) {

src/media/js/views/settings.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,17 @@ define('views/settings',
3131
};
3232

3333
user.update_settings(data);
34+
3435
requests.patch(
3536
urls.api.url('settings'),
3637
data
3738
).done(function() {
39+
// Add/Remove recommended nav item depending on what was checked.
40+
if (data.enable_recommendations) {
41+
z.body.addClass('show-recommendations');
42+
} else {
43+
z.body.removeClass('show-recommendations');
44+
}
3845
update_settings();
3946
notify({message: gettext('Settings saved')});
4047
}).fail(function() {

src/templates/nav.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{% include "_macros/act_tray.html" %}
22

33
{% macro navtab(code, name, url) %}
4-
<li class="tab-item {{ code }}{{ ' initial-active' if path == url }}"
5-
data-tab="{{ code }}">
4+
<li class="tab-item {{ code }}{{ ' initial-active' if path == url }}" data-tab="{{ code }}">
65
<a class="tab-link" href="{{ url }}">{{ name }}</a>
76
</li>
87
{% endmacro %}
@@ -17,9 +16,7 @@
1716
{{ navtab('homepage', _('Home'), url('homepage')) }}
1817
{{ navtab('new', _('New'), url('new')) }}
1918
{{ navtab('popular', _('Popular'), url('popular')) }}
20-
{% if logged_in and recommendations %}
21-
{{ navtab('recommended', _('Recommended'), url('recommended')) }}
22-
{% endif %}
19+
{{ navtab('recommended', _('Recommended'), url('recommended')) }}
2320
<li class="tab-item tab-categories{{ ' initial-active' if path == url('categories') }}"
2421
data-tab="categories">
2522
<a class="tab-link mobile-cat-link" href="{{ url('categories') }}">{{ _('Categories') }}</a>

tests/ui/account_settings.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ casper.test.begin('Test account settings', {
3939
casper.click('#enable_recommendations');
4040
casper.click('.account-settings button[type="submit"]');
4141

42+
// Test submitting with recommendations off removes the body class.
4243
test.assertEqual(
4344
casper.getFormValues('.account-settings').display_name,
4445
'hello my name is rob hudson'
@@ -47,6 +48,28 @@ casper.test.begin('Test account settings', {
4748
casper.getFormValues('.account-settings').enable_recommendations,
4849
false
4950
);
51+
});
52+
53+
casper.waitUntilVisible('#notification', function() {
54+
test.assertNotExists('body.show-recommendations');
55+
});
56+
57+
casper.waitWhileVisible('#notification', function() {
58+
// Now test enabling recommendations.
59+
casper.click('#enable_recommendations');
60+
casper.click('.account-settings button[type="submit"]');
61+
}, function() {
62+
this.echo('[TIMEOUT] Waiting for #notification timed out.');
63+
}, 7500);
64+
65+
casper.waitUntilVisible('#notification', function() {
66+
// Test submitting with recommendations on adds the body class.
67+
test.assertExists('body.show-recommendations');
68+
test.assertEqual(
69+
casper.getFormValues('.account-settings').enable_recommendations,
70+
true
71+
);
72+
5073
casper.click('.logout');
5174
});
5275

@@ -57,6 +80,7 @@ casper.test.begin('Test account settings', {
5780
test.assertSelectorHasText('.account-settings .persona', 'Register');
5881
test.assertNotVisible('.account-settings .logout');
5982
test.assertNotVisible('.account-settings footer p:first-child button');
83+
test.assertNotExists('body.show-recommendations');
6084
});
6185

6286
casper.run(function() {

tests/ui/navbar.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ casper.test.begin('Test navbar', {
1717

1818
casper.waitForSelector('[data-page-type~="categories"]', function() {
1919
test.assertExists('[data-page-type~=categories]', 'Check navigate to category');
20+
casper.click('.nav-mkt li[data-tab="recommended"] a');
21+
});
22+
23+
// Recommended exists but may or may not be visible depending on login state.
24+
casper.waitForSelector('[data-page-type~="recommended"]', function() {
25+
test.assertExists('[data-page-type~=recommended]', 'Check navigate to recommended');
2026
casper.click('.act-tray.mobile');
2127
});
2228

0 commit comments

Comments
 (0)