0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00

Added acceptance test for custom fonts and preview

This commit is contained in:
Aileen Booker 2024-10-23 15:00:21 +04:00
parent 34078f9582
commit 369b562cda
3 changed files with 59 additions and 2 deletions

View file

@ -327,6 +327,14 @@
{
"key": "support_email_address",
"value": "support@example.com"
},
{
"key": "heading_font",
"value": null
},
{
"key": "body_font",
"value": null
}
],
"meta": {

View file

@ -257,13 +257,14 @@ const GlobalSettings: React.FC<{ values: GlobalSettingValues, updateSetting: (ke
</div>
</Form>
<BehindFeatureFlag flag="customFonts">
<Form className='-mt-4' data-testid='custom-fonts-section' gap='sm' margins='lg' title='Typography'>
<Form className='-mt-4' gap='sm' margins='lg' title='Typography'>
<Select
className={selectFont(selectedHeadingFont.label, true)}
hint={''}
menuShouldScrollIntoView={true}
options={customHeadingFonts}
selectedOption={selectedHeadingFont}
testId='heading-font-select'
title={'Heading font'}
onSelect={(option) => {
if (option?.value === DEFAULT_FONT) {
@ -283,6 +284,7 @@ const GlobalSettings: React.FC<{ values: GlobalSettingValues, updateSetting: (ke
menuShouldScrollIntoView={true}
options={customBodyFonts}
selectedOption={selectedBodyFont}
testId='body-font-select'
title={'Body font'}
onSelect={(option) => {
if (option?.value === DEFAULT_FONT) {

View file

@ -1,4 +1,4 @@
import {chooseOptionInSelect, mockApi, mockSitePreview, responseFixtures} from '@tryghost/admin-x-framework/test/acceptance';
import {chooseOptionInSelect, mockApi, mockSitePreview, responseFixtures, toggleLabsFlag} from '@tryghost/admin-x-framework/test/acceptance';
import {expect, test} from '@playwright/test';
import {globalDataRequests} from '../../utils/acceptance';
@ -286,4 +286,51 @@ test.describe('Design settings', async () => {
]
});
});
test('Custom fonts', async ({page}) => {
toggleLabsFlag('customFonts', true);
await mockApi({page, requests: {
...globalDataRequests,
browseCustomThemeSettings: {method: 'GET', path: '/custom_theme_settings/', response: {
custom_theme_settings: []
}},
browseLatestPost: {method: 'GET', path: /^\/posts\/.+limit=1/, response: responseFixtures.latestPost}
}});
const lastPreviewRequest = await mockSitePreview({
page,
url: responseFixtures.site.site.url,
response: '<html><head><style></style></head><body><div>homepage preview</div></body></html>'
});
await page.goto('/');
const section = page.getByTestId('design');
await section.getByRole('button', {name: 'Customize'}).click();
const modal = page.getByTestId('design-modal');
const designSettingTabs = modal.getByTestId('design-setting-tabs');
await expect(designSettingTabs.getByTestId('accent-color-picker')).toBeVisible();
await expect(designSettingTabs.getByText('Typography')).toBeVisible();
await expect(designSettingTabs.getByTestId('heading-font-select')).toBeVisible();
await expect(designSettingTabs.getByTestId('body-font-select')).toBeVisible();
// select a different heading font
const headingFontSelect = designSettingTabs.getByTestId('heading-font-select');
await headingFontSelect.click();
await headingFontSelect.getByText('Cardo').click();
// select a different body font
const bodyFontSelect = designSettingTabs.getByTestId('body-font-select');
await bodyFontSelect.click();
await bodyFontSelect.getByText('Inter').click();
const expectedEncoded = new URLSearchParams([['bf', 'Inter'], ['hf', 'Cardo']]).toString();
// Preview should have the new fonts
await expect(lastPreviewRequest.previewHeader).toMatch(new RegExp(`&${expectedEncoded.replace(/\+/g, '\\+')}`));
});
});