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

feat(newsletters): Update newsletter checkbox labels, add new newsletter checkbox w/two slugs #15482

Merged
merged 1 commit into from
Jun 29, 2023
Merged
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
4 changes: 3 additions & 1 deletion packages/fxa-auth-server/lib/routes/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,9 @@ module.exports.newsletters = isA
'knowledge-is-power',
'take-action-for-the-internet',
'test-pilot',
'mozilla-and-you'
'mozilla-and-you',
'security-privacy-news',
'mozilla-accounts'
)
)
.default([])
Expand Down
25 changes: 5 additions & 20 deletions packages/fxa-content-server/app/scripts/lib/newsletters.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,23 @@ const t = (msg) => msg;

export default {
CONSUMER_BETA: {
label: t('Test new Firefox products'),
label: t('Early access to test new products'),
slug: 'test-pilot',
},
FIREFOX_ACCOUNTS_JOURNEY: {
label: t('Get the latest news about Mozilla and Firefox'),
slug: 'firefox-accounts-journey',
},
HEALTHY_INTERNET: {
label: t('Take action to keep the internet healthy'),
label: t('Help keep the internet healthy'),
slug: 'take-action-for-the-internet',
},
ONLINE_SAFETY: {
label: t('Be safer and smarter online'),
slug: 'knowledge-is-power',
},
};

export const newsletterNewCopy = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this since it wasn't being used anywhere.

I was thinking of removing other unused newsletters like ONLINE_SAFETY and FIREFOX_ACCOUNTS_JOURNEY and updating auth-server's validity check for only these 3, happy to do that; I'd left them as-is since this way we've got a pool of available/valid newsletters and then we pull in the ones we want on the page 🤷‍♀️

CONSUMER_BETA: {
label: t('Testing Firefox products'),
slug: 'test-pilot',
},
FIREFOX_ACCOUNTS_JOURNEY: {
label: t('Get the latest news about Mozilla and Firefox'),
slug: 'firefox-accounts-journey',
},
HEALTHY_INTERNET: {
label: t('Taking action to keep the internet healthy'),
slug: 'take-action-for-the-internet',
},
ONLINE_SAFETY: {
label: t('Safety and privacy online with Firefox and Mozilla'),
slug: 'knowledge-is-power',
SECURITY_PRIVACY: {
label: t('Security & privacy news and updates'),
slug: ['security-privacy-news', 'mozilla-accounts'],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<section class="mb-5">
{{#isAnyNewsletterEnabled}}
<header>
<h2 class="mb-5 text-base text-start">{{#t}}Practical knowledge is coming to your inbox. Sign up for more:{{/t}}</h2>
<h2 class="mb-5 text-base text-start font-bold">{{#t}}Get more from Mozilla:{{/t}}</h2>
</header>
{{/isAnyNewsletterEnabled}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ const MARKETING_EMAIL_CHECKBOX_SELECTOR = '#newsletters-optin input';
*/

const NEWSLETTERS = [
Newsletters.ONLINE_SAFETY,
Newsletters.SECURITY_PRIVACY,
Newsletters.CONSUMER_BETA,
Newsletters.HEALTHY_INTERNET,
];

const UNESCAPED_NEWSLETTERS = [Newsletters.SECURITY_PRIVACY];

export default {
initialize(options = {}) {
this._experimentGroupingRules = options.experimentGroupingRules;
Expand All @@ -38,9 +40,12 @@ export default {

const newsletters = this._getNewsletters().map((newsletter) => {
// labels are untranslated, make sure to translate them
// before rendering.
// before rendering. Some newsletter labels should not be HTML escaped.
const label = UNESCAPED_NEWSLETTERS.includes(newsletter)
? this.unsafeTranslate(newsletter.label)
: this.translate(newsletter.label);
return {
label: this.translate(newsletter.label),
label,
slug: newsletter.slug,
};
});
Expand Down Expand Up @@ -85,9 +90,14 @@ export default {
* @returns {String[]} Array containing list of newsletters
*/
getOptedIntoNewsletters() {
return this._getNewsletters()
.filter((newsletter) => this._hasOptedIntoNewsletter(newsletter))
.map((newsletter) => newsletter.slug);
return (
this._getNewsletters()
.filter((newsletter) => this._hasOptedIntoNewsletter(newsletter))
.map((newsletter) => newsletter.slug)
// `newsletter.slug` can be an array of strings when one checkbox corresponds
// with multiple slugs. Flatten them here to send an array of strings.
.flat()
);
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,49 @@ describe('views/mixins/email-opt-in-mixin', () => {
.$(view._newsletterTypeToSelector(NEWSLETTERS.CONSUMER_BETA))
.attr('checked', 'checked');
view
.$(view._newsletterTypeToSelector(NEWSLETTERS.ONLINE_SAFETY))
.$(view._newsletterTypeToSelector(NEWSLETTERS.HEALTHY_INTERNET))
.attr('checked', 'checked');
view;
assert.sameMembers(view.getOptedIntoNewsletters(), [
'test-pilot',
'knowledge-is-power',
'take-action-for-the-internet',
]);
});

it('returns list of expected newsletters when newsletter is array of slugs', () => {
view
.$(view._newsletterTypeToSelector(NEWSLETTERS.SECURITY_PRIVACY))
.attr('checked', 'checked');
view
.$(view._newsletterTypeToSelector(NEWSLETTERS.HEALTHY_INTERNET))
.attr('checked', 'checked');
view;
assert.sameMembers(view.getOptedIntoNewsletters(), [
'take-action-for-the-internet',
'security-privacy-news',
'mozilla-accounts',
]);
});
});

describe('returns new copy for newsletter experiment', () => {
beforeEach(() => {
view.getExperimentGroup = () => true;
sinon.spy(view, 'getExperimentGroup');
sinon.stub(experimentGroupingRules, 'choose').callsFake(() => true);
return view.render();
});

it('returns list of newsletters', () => {
view
.$(view._newsletterTypeToSelector(NEWSLETTERS.CONSUMER_BETA))
.attr('label', 'Testing Firefox products');
assert.equal(
view.$(`label[for="${NEWSLETTERS.CONSUMER_BETA.slug}"]`).text(),
'Early access to test new products'
);
});

it('renders unescaped label as expected', () => {
assert.equal(
view.$(`label[for="${NEWSLETTERS.SECURITY_PRIVACY.slug}"]`).text(),
'Security & privacy news and updates'
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ describe('views/sign_up_password', () => {
return Promise.resolve(view.validateAndSubmit()).then(() => {
assert.isTrue(view.signUp.calledOnceWith(account, 'password123123'));
assert.sameMembers(account.get('newsletters'), [
'knowledge-is-power',
'security-privacy-news',
'mozilla-accounts',
'test-pilot',
'take-action-for-the-internet',
]);
Expand Down