Skip to content

Commit bf64591

Browse files
authored
✅Added new tests for email encoding related to i18n (#23145)
ref #23121 * Added additional tests to cover the newly-translated paywall and bugfix. * Apostrophes in strings are worth explicitly testing, because double-encoding is too easy to do.
1 parent 1ec2509 commit bf64591

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

ghost/email-service/test/email-renderer.test.js

+177
Original file line numberDiff line numberDiff line change
@@ -2690,4 +2690,181 @@ describe('Email renderer', function () {
26902690
assert.equal(response.href, 'https://example.com/image.png');
26912691
});
26922692
});
2693+
describe('additional i18n tests', function () {
2694+
let renderedPost;
2695+
let postUrl = 'http://example.com';
2696+
let customSettings = {};
2697+
let emailRenderer;
2698+
let addTrackingToUrlStub;
2699+
let labsEnabled;
2700+
2701+
beforeEach(function () {
2702+
renderedPost = '<p>Lexical Test</p><img class="is-light-background" src="test-dark" /><img class="is-dark-background" src="test-light" />';
2703+
labsEnabled = true; // TODO: odd default because it means we're testing the unused email-customization template
2704+
2705+
postUrl = 'http://example.com';
2706+
customSettings = {
2707+
locale: 'fr',
2708+
site_title: 'Cathy\'s Blog'
2709+
};
2710+
addTrackingToUrlStub = sinon.stub();
2711+
addTrackingToUrlStub.callsFake((u, _post, uuid) => {
2712+
return new URL('http://tracked-link.com/?m=' + encodeURIComponent(uuid) + '&url=' + encodeURIComponent(u.href));
2713+
});
2714+
emailRenderer = new EmailRenderer({
2715+
audienceFeedbackService: {
2716+
buildLink: (_uuid, _postId, score, key) => {
2717+
return new URL('http://feedback-link.com/?score=' + encodeURIComponent(score) + '&uuid=' + encodeURIComponent(_uuid) + '&key=' + encodeURIComponent(key));
2718+
}
2719+
},
2720+
urlUtils: {
2721+
urlFor: (type) => {
2722+
if (type === 'image') {
2723+
return 'http://icon.example.com';
2724+
}
2725+
return 'http://example.com/subdirectory';
2726+
},
2727+
isSiteUrl: (u) => {
2728+
return u.hostname === 'example.com';
2729+
}
2730+
},
2731+
settingsCache: {
2732+
get: (key) => {
2733+
if (customSettings[key]) {
2734+
return customSettings[key];
2735+
}
2736+
if (key === 'accent_color') {
2737+
return '#ffffff';
2738+
}
2739+
if (key === 'timezone') {
2740+
return 'Etc/UTC';
2741+
}
2742+
if (key === 'icon') {
2743+
return 'ICON';
2744+
}
2745+
if (key === 'visibility') {
2746+
return 'paid';
2747+
}
2748+
if (key === 'title') {
2749+
return 'Cathy\'s Blog';
2750+
}
2751+
}
2752+
},
2753+
getPostUrl: () => {
2754+
return postUrl;
2755+
},
2756+
renderers: {
2757+
lexical: {
2758+
render: () => {
2759+
return renderedPost;
2760+
}
2761+
},
2762+
mobiledoc: {
2763+
render: () => {
2764+
return '<p> Mobiledoc Test</p>';
2765+
}
2766+
}
2767+
},
2768+
linkReplacer,
2769+
memberAttributionService: {
2770+
addPostAttributionTracking: (u) => {
2771+
u.searchParams.append('post_tracking', 'added');
2772+
return u;
2773+
}
2774+
},
2775+
linkTracking: {
2776+
service: {
2777+
addTrackingToUrl: addTrackingToUrlStub
2778+
}
2779+
},
2780+
outboundLinkTagger: {
2781+
addToUrl: (u, newsletter) => {
2782+
u.searchParams.append('source_tracking', newsletter?.get('name') ?? 'site');
2783+
return u;
2784+
}
2785+
},
2786+
labs: {
2787+
isSet: (key) => {
2788+
if (typeof labsEnabled === 'object') {
2789+
return labsEnabled[key] || false;
2790+
}
2791+
2792+
return labsEnabled;
2793+
}
2794+
},
2795+
t: tFr
2796+
});
2797+
});
2798+
it('correctly include the site name in the paywall (in French)', async function () {
2799+
renderedPost = '<div> Lexical Test </div> <div data-gh-segment="status:-free"> members only section</div> some text for both <!--members-only--> finishing part only for members';
2800+
let post = {
2801+
related: () => {
2802+
return null;
2803+
},
2804+
get: (key) => {
2805+
if (key === 'lexical') {
2806+
return '{}';
2807+
}
2808+
2809+
if (key === 'visibility') {
2810+
return 'paid';
2811+
}
2812+
2813+
if (key === 'title') {
2814+
return 'Test Post';
2815+
}
2816+
},
2817+
getLazyRelation: () => {
2818+
return {
2819+
models: [{
2820+
get: (key) => {
2821+
if (key === 'name') {
2822+
return 'Test Author';
2823+
}
2824+
}
2825+
}]
2826+
};
2827+
}
2828+
};
2829+
let newsletter = {
2830+
get: (key) => {
2831+
if (key === 'header_image') {
2832+
return null;
2833+
}
2834+
2835+
if (key === 'name') {
2836+
return 'Test Newsletter';
2837+
}
2838+
2839+
if (key === 'badge') {
2840+
return false;
2841+
}
2842+
2843+
if (key === 'feedback_enabled') {
2844+
return true;
2845+
}
2846+
2847+
if (key === 'show_post_title_section') {
2848+
return true;
2849+
}
2850+
2851+
return false;
2852+
}
2853+
};
2854+
let options = {};
2855+
2856+
let response = await emailRenderer.renderBody(
2857+
post,
2858+
newsletter,
2859+
'status:free',
2860+
options
2861+
);
2862+
2863+
response.html.should.not.containEql('members only section');
2864+
response.html.should.containEql('some text for both');
2865+
response.html.should.not.containEql('finishing part only for members');
2866+
response.html.should.containEql('Devenez un abonn&#xE9; payant de Cathy&#39;s Blog pour acc&#xE9;der &#xE0; du contenu exclusif');
2867+
response.plaintext.should.containEql('Devenez un abonné payant de Cathy\'s Blog pour accéder à du contenu exclusif');
2868+
});
2869+
});
26932870
});

0 commit comments

Comments
 (0)