0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Added tests for ghost_head to verify custom fonts CSS output

This commit is contained in:
Aileen Booker 2024-10-10 15:16:46 +01:00
parent d0afa2d0a1
commit 60a9c00663
2 changed files with 394 additions and 0 deletions

View file

@ -959,6 +959,304 @@ Object {
}
`;
exports[`{{ghost_head}} helper custom fonts does not include custom font when invalid 1 1`] = `
Object {
"rendered": "<meta name=\\"description\\" content=\\"all about our site\\">
<link rel=\\"canonical\\" href=\\"http://127.0.0.1:2369/post/\\">
<meta name=\\"referrer\\" content=\\"no-referrer-when-downgrade\\">
<link rel=\\"amphtml\\" href=\\"http://127.0.0.1:2369/post/amp/\\">
<meta property=\\"og:site_name\\" content=\\"Ghost\\">
<meta property=\\"og:type\\" content=\\"article\\">
<meta property=\\"og:title\\" content=\\"Custom Facebook title\\">
<meta property=\\"og:description\\" content=\\"Custom Facebook description\\">
<meta property=\\"og:url\\" content=\\"http://127.0.0.1:2369/post/\\">
<meta property=\\"og:image\\" content=\\"http://127.0.0.1:2369/content/images/test-og-image.png\\">
<meta property=\\"article:published_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
<meta property=\\"article:modified_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
<meta property=\\"article:author\\" content=\\"https://www.facebook.com/testuser\\">
<meta name=\\"twitter:card\\" content=\\"summary_large_image\\">
<meta name=\\"twitter:title\\" content=\\"Custom Twitter title\\">
<meta name=\\"twitter:description\\" content=\\"Custom Twitter description\\">
<meta name=\\"twitter:url\\" content=\\"http://127.0.0.1:2369/post/\\">
<meta name=\\"twitter:image\\" content=\\"http://127.0.0.1:2369/content/images/test-twitter-image.png\\">
<meta name=\\"twitter:label1\\" content=\\"Written by\\">
<meta name=\\"twitter:data1\\" content=\\"name\\">
<meta name=\\"twitter:creator\\" content=\\"@testuser\\">
<script type=\\"application/ld+json\\">
{
\\"@context\\": \\"https://schema.org\\",
\\"@type\\": \\"Article\\",
\\"publisher\\": {
\\"@type\\": \\"Organization\\",
\\"name\\": \\"Ghost\\",
\\"url\\": \\"http://127.0.0.1:2369/\\",
\\"logo\\": {
\\"@type\\": \\"ImageObject\\",
\\"url\\": \\"http://127.0.0.1:2369/favicon.ico\\"
}
},
\\"author\\": {
\\"@type\\": \\"Person\\",
\\"name\\": \\"name\\",
\\"image\\": {
\\"@type\\": \\"ImageObject\\",
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-author-image.png\\"
},
\\"url\\": \\"https://mysite.com/fakeauthor/\\",
\\"sameAs\\": [
\\"http://authorwebsite.com\\",
\\"https://www.facebook.com/testuser\\",
\\"https://twitter.com/testuser\\"
]
},
\\"headline\\": \\"About\\",
\\"url\\": \\"http://127.0.0.1:2369/post/\\",
\\"datePublished\\": \\"1970-01-01T00:00:00.000Z\\",
\\"dateModified\\": \\"1970-01-01T00:00:00.000Z\\",
\\"image\\": {
\\"@type\\": \\"ImageObject\\",
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-image-about.png\\"
},
\\"description\\": \\"all about our site\\",
\\"mainEntityOfPage\\": \\"http://127.0.0.1:2369/post/\\"
}
</script>
<meta name=\\"generator\\" content=\\"Ghost 0.3\\">
<link rel=\\"alternate\\" type=\\"application/rss+xml\\" title=\\"Ghost\\" href=\\"http://localhost:65530/rss/\\">
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">",
}
`;
exports[`{{ghost_head}} helper custom fonts does not include custom font when not set 1 1`] = `
Object {
"rendered": "<meta name=\\"description\\" content=\\"all about our site\\">
<link rel=\\"canonical\\" href=\\"http://127.0.0.1:2369/post/\\">
<meta name=\\"referrer\\" content=\\"no-referrer-when-downgrade\\">
<link rel=\\"amphtml\\" href=\\"http://127.0.0.1:2369/post/amp/\\">
<meta property=\\"og:site_name\\" content=\\"Ghost\\">
<meta property=\\"og:type\\" content=\\"article\\">
<meta property=\\"og:title\\" content=\\"Custom Facebook title\\">
<meta property=\\"og:description\\" content=\\"Custom Facebook description\\">
<meta property=\\"og:url\\" content=\\"http://127.0.0.1:2369/post/\\">
<meta property=\\"og:image\\" content=\\"http://127.0.0.1:2369/content/images/test-og-image.png\\">
<meta property=\\"article:published_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
<meta property=\\"article:modified_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
<meta property=\\"article:author\\" content=\\"https://www.facebook.com/testuser\\">
<meta name=\\"twitter:card\\" content=\\"summary_large_image\\">
<meta name=\\"twitter:title\\" content=\\"Custom Twitter title\\">
<meta name=\\"twitter:description\\" content=\\"Custom Twitter description\\">
<meta name=\\"twitter:url\\" content=\\"http://127.0.0.1:2369/post/\\">
<meta name=\\"twitter:image\\" content=\\"http://127.0.0.1:2369/content/images/test-twitter-image.png\\">
<meta name=\\"twitter:label1\\" content=\\"Written by\\">
<meta name=\\"twitter:data1\\" content=\\"name\\">
<meta name=\\"twitter:creator\\" content=\\"@testuser\\">
<script type=\\"application/ld+json\\">
{
\\"@context\\": \\"https://schema.org\\",
\\"@type\\": \\"Article\\",
\\"publisher\\": {
\\"@type\\": \\"Organization\\",
\\"name\\": \\"Ghost\\",
\\"url\\": \\"http://127.0.0.1:2369/\\",
\\"logo\\": {
\\"@type\\": \\"ImageObject\\",
\\"url\\": \\"http://127.0.0.1:2369/favicon.ico\\"
}
},
\\"author\\": {
\\"@type\\": \\"Person\\",
\\"name\\": \\"name\\",
\\"image\\": {
\\"@type\\": \\"ImageObject\\",
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-author-image.png\\"
},
\\"url\\": \\"https://mysite.com/fakeauthor/\\",
\\"sameAs\\": [
\\"http://authorwebsite.com\\",
\\"https://www.facebook.com/testuser\\",
\\"https://twitter.com/testuser\\"
]
},
\\"headline\\": \\"About\\",
\\"url\\": \\"http://127.0.0.1:2369/post/\\",
\\"datePublished\\": \\"1970-01-01T00:00:00.000Z\\",
\\"dateModified\\": \\"1970-01-01T00:00:00.000Z\\",
\\"image\\": {
\\"@type\\": \\"ImageObject\\",
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-image-about.png\\"
},
\\"description\\": \\"all about our site\\",
\\"mainEntityOfPage\\": \\"http://127.0.0.1:2369/post/\\"
}
</script>
<meta name=\\"generator\\" content=\\"Ghost 0.3\\">
<link rel=\\"alternate\\" type=\\"application/rss+xml\\" title=\\"Ghost\\" href=\\"http://localhost:65530/rss/\\">
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">",
}
`;
exports[`{{ghost_head}} helper custom fonts includes custom font when set in options data object 1 1`] = `
Object {
"rendered": "<meta name=\\"description\\" content=\\"all about our site\\">
<link rel=\\"canonical\\" href=\\"http://127.0.0.1:2369/post/\\">
<meta name=\\"referrer\\" content=\\"no-referrer-when-downgrade\\">
<link rel=\\"amphtml\\" href=\\"http://127.0.0.1:2369/post/amp/\\">
<meta property=\\"og:site_name\\" content=\\"Ghost\\">
<meta property=\\"og:type\\" content=\\"article\\">
<meta property=\\"og:title\\" content=\\"Custom Facebook title\\">
<meta property=\\"og:description\\" content=\\"Custom Facebook description\\">
<meta property=\\"og:url\\" content=\\"http://127.0.0.1:2369/post/\\">
<meta property=\\"og:image\\" content=\\"http://127.0.0.1:2369/content/images/test-og-image.png\\">
<meta property=\\"article:published_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
<meta property=\\"article:modified_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
<meta property=\\"article:author\\" content=\\"https://www.facebook.com/testuser\\">
<meta name=\\"twitter:card\\" content=\\"summary_large_image\\">
<meta name=\\"twitter:title\\" content=\\"Custom Twitter title\\">
<meta name=\\"twitter:description\\" content=\\"Custom Twitter description\\">
<meta name=\\"twitter:url\\" content=\\"http://127.0.0.1:2369/post/\\">
<meta name=\\"twitter:image\\" content=\\"http://127.0.0.1:2369/content/images/test-twitter-image.png\\">
<meta name=\\"twitter:label1\\" content=\\"Written by\\">
<meta name=\\"twitter:data1\\" content=\\"name\\">
<meta name=\\"twitter:creator\\" content=\\"@testuser\\">
<script type=\\"application/ld+json\\">
{
\\"@context\\": \\"https://schema.org\\",
\\"@type\\": \\"Article\\",
\\"publisher\\": {
\\"@type\\": \\"Organization\\",
\\"name\\": \\"Ghost\\",
\\"url\\": \\"http://127.0.0.1:2369/\\",
\\"logo\\": {
\\"@type\\": \\"ImageObject\\",
\\"url\\": \\"http://127.0.0.1:2369/favicon.ico\\"
}
},
\\"author\\": {
\\"@type\\": \\"Person\\",
\\"name\\": \\"name\\",
\\"image\\": {
\\"@type\\": \\"ImageObject\\",
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-author-image.png\\"
},
\\"url\\": \\"https://mysite.com/fakeauthor/\\",
\\"sameAs\\": [
\\"http://authorwebsite.com\\",
\\"https://www.facebook.com/testuser\\",
\\"https://twitter.com/testuser\\"
]
},
\\"headline\\": \\"About\\",
\\"url\\": \\"http://127.0.0.1:2369/post/\\",
\\"datePublished\\": \\"1970-01-01T00:00:00.000Z\\",
\\"dateModified\\": \\"1970-01-01T00:00:00.000Z\\",
\\"image\\": {
\\"@type\\": \\"ImageObject\\",
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-image-about.png\\"
},
\\"description\\": \\"all about our site\\",
\\"mainEntityOfPage\\": \\"http://127.0.0.1:2369/post/\\"
}
</script>
<meta name=\\"generator\\" content=\\"Ghost 0.3\\">
<link rel=\\"alternate\\" type=\\"application/rss+xml\\" title=\\"Ghost\\" href=\\"http://localhost:65530/rss/\\">
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">
<style>@import url(https://fonts.bunny.net/css?family=space-grotesk:700);@import url(https://fonts.bunny.net/css?family=poppins:400,700);.is-body {font-family: Poppins !important;}.is-title, .gh-content [id] {font-family: Space Grotesk !important;}</style>",
}
`;
exports[`{{ghost_head}} helper custom fonts includes custom font when set in settings cache 1 1`] = `
Object {
"rendered": "<meta name=\\"description\\" content=\\"all about our site\\">
<link rel=\\"canonical\\" href=\\"http://127.0.0.1:2369/post/\\">
<meta name=\\"referrer\\" content=\\"no-referrer-when-downgrade\\">
<link rel=\\"amphtml\\" href=\\"http://127.0.0.1:2369/post/amp/\\">
<meta property=\\"og:site_name\\" content=\\"Ghost\\">
<meta property=\\"og:type\\" content=\\"article\\">
<meta property=\\"og:title\\" content=\\"Custom Facebook title\\">
<meta property=\\"og:description\\" content=\\"Custom Facebook description\\">
<meta property=\\"og:url\\" content=\\"http://127.0.0.1:2369/post/\\">
<meta property=\\"og:image\\" content=\\"http://127.0.0.1:2369/content/images/test-og-image.png\\">
<meta property=\\"article:published_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
<meta property=\\"article:modified_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
<meta property=\\"article:author\\" content=\\"https://www.facebook.com/testuser\\">
<meta name=\\"twitter:card\\" content=\\"summary_large_image\\">
<meta name=\\"twitter:title\\" content=\\"Custom Twitter title\\">
<meta name=\\"twitter:description\\" content=\\"Custom Twitter description\\">
<meta name=\\"twitter:url\\" content=\\"http://127.0.0.1:2369/post/\\">
<meta name=\\"twitter:image\\" content=\\"http://127.0.0.1:2369/content/images/test-twitter-image.png\\">
<meta name=\\"twitter:label1\\" content=\\"Written by\\">
<meta name=\\"twitter:data1\\" content=\\"name\\">
<meta name=\\"twitter:creator\\" content=\\"@testuser\\">
<script type=\\"application/ld+json\\">
{
\\"@context\\": \\"https://schema.org\\",
\\"@type\\": \\"Article\\",
\\"publisher\\": {
\\"@type\\": \\"Organization\\",
\\"name\\": \\"Ghost\\",
\\"url\\": \\"http://127.0.0.1:2369/\\",
\\"logo\\": {
\\"@type\\": \\"ImageObject\\",
\\"url\\": \\"http://127.0.0.1:2369/favicon.ico\\"
}
},
\\"author\\": {
\\"@type\\": \\"Person\\",
\\"name\\": \\"name\\",
\\"image\\": {
\\"@type\\": \\"ImageObject\\",
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-author-image.png\\"
},
\\"url\\": \\"https://mysite.com/fakeauthor/\\",
\\"sameAs\\": [
\\"http://authorwebsite.com\\",
\\"https://www.facebook.com/testuser\\",
\\"https://twitter.com/testuser\\"
]
},
\\"headline\\": \\"About\\",
\\"url\\": \\"http://127.0.0.1:2369/post/\\",
\\"datePublished\\": \\"1970-01-01T00:00:00.000Z\\",
\\"dateModified\\": \\"1970-01-01T00:00:00.000Z\\",
\\"image\\": {
\\"@type\\": \\"ImageObject\\",
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-image-about.png\\"
},
\\"description\\": \\"all about our site\\",
\\"mainEntityOfPage\\": \\"http://127.0.0.1:2369/post/\\"
}
</script>
<meta name=\\"generator\\" content=\\"Ghost 0.3\\">
<link rel=\\"alternate\\" type=\\"application/rss+xml\\" title=\\"Ghost\\" href=\\"http://localhost:65530/rss/\\">
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">
<style>@import url(https://fonts.bunny.net/css?family=playfair-display:400);@import url(https://fonts.bunny.net/css?family=lora:400,700);.is-body {font-family: Lora !important;}.is-title, .gh-content [id] {font-family: Playfair Display !important;}</style>",
}
`;
exports[`{{ghost_head}} helper includes tinybird tracker script when config is set Sets tb_post_uuid on post page 1 1`] = `
Object {
"rendered": "<link rel=\\"canonical\\" href=\\"http://127.0.0.1:2369/post/\\">

View file

@ -1125,6 +1125,102 @@ describe('{{ghost_head}} helper', function () {
});
});
describe('custom fonts', function () {
it('includes custom font when set in options data object', async function () {
sinon.stub(labs, 'isSet').withArgs('customFonts').returns(true);
const renderObject = {
post: posts[1]
};
const templateOptions = {
site: {
heading_font: 'Space Grotesk',
body_font: 'Poppins'
}
};
await testGhostHead(testUtils.createHbsResponse({
templateOptions,
renderObject: renderObject,
locals: {
relativeUrl: '/post/',
context: ['post'],
safeVersion: '0.3'
}
}));
});
it('includes custom font when set in settings cache', async function () {
sinon.stub(labs, 'isSet').withArgs('customFonts').returns(true);
settingsCache.get.withArgs('heading_font').returns('Playfair Display');
settingsCache.get.withArgs('body_font').returns('Lora');
const renderObject = {
post: posts[1]
};
await testGhostHead(testUtils.createHbsResponse({
templateOptions: {site: {}},
renderObject: renderObject,
locals: {
relativeUrl: '/post/',
context: ['post'],
safeVersion: '0.3'
}
}));
});
it('does not include custom font when not set', async function () {
sinon.stub(labs, 'isSet').withArgs('customFonts').returns(true);
settingsCache.get.withArgs('heading_font').returns(null);
settingsCache.get.withArgs('body_font').returns('');
const renderObject = {
post: posts[1]
};
await testGhostHead(testUtils.createHbsResponse({
templateOptions: {site: {}},
renderObject,
locals: {
relativeUrl: '/post/',
context: ['post'],
safeVersion: '0.3'
}
}));
});
it('does not include custom font when invalid', async function () {
sinon.stub(labs, 'isSet').withArgs('customFonts').returns(true);
settingsCache.get.withArgs('heading_font').returns(null);
settingsCache.get.withArgs('body_font').returns('Wendy Sans');
const templateOptions = {
site: {
heading_font: 'Comic Sans',
body_font: ''
}
};
const renderObject = {
post: posts[1]
};
await testGhostHead(testUtils.createHbsResponse({
templateOptions,
renderObject,
locals: {
relativeUrl: '/post/',
context: ['post'],
safeVersion: '0.3'
}
}));
});
});
describe('members scripts', function () {
it('includes portal when members enabled', async function () {
settingsCache.get.withArgs('members_enabled').returns(true);