Skip to content

Commit

Permalink
Font Library: Add 'No fonts installed' message on library tab when fo…
Browse files Browse the repository at this point in the history
…nts aren't available (#63740)

* Add message in library tab of font modal when fonts are not available

* Reset notice on font library modal open

* Add e2e test for no font installed state in font library modal

Co-authored-by: akasunil <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: richtabor <[email protected]>
  • Loading branch information
4 people authored Jul 24, 2024
1 parent 8a36fd4 commit 368d0ac
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/edit-site/src/components/global-styles/font-families.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { unlock } from '../../lock-unlock';
const { useGlobalSetting } = unlock( blockEditorPrivateApis );

function FontFamilies() {
const { baseCustomFonts, modalTabOpen, setModalTabOpen } =
const { baseCustomFonts, modalTabOpen, setModalTabOpen, setNotice } =
useContext( FontLibraryContext );
const [ fontFamilies ] = useGlobalSetting( 'typography.fontFamilies' );
const [ baseFontFamilies ] = useGlobalSetting(
Expand Down Expand Up @@ -111,13 +111,15 @@ function FontFamilies() {
className="edit-site-global-styles-font-families__manage-fonts"
variant="secondary"
__next40pxDefaultSize
onClick={ () =>
onClick={ () => {
// Reset notice when opening the modal.
setNotice( null );
setModalTabOpen(
hasInstalledFonts
? 'installed-fonts'
: 'upload-fonts'
)
}
);
} }
>
{ hasInstalledFonts
? __( 'Manage fonts' )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function InstalledFonts() {
refreshLibrary();
}, [] );

const hasFonts = baseThemeFonts.length > 0 || baseCustomFonts.length > 0;
return (
<div className="font-library-modal__tabpanel-layout">
{ isResolvingLibrary && (
Expand All @@ -173,6 +174,11 @@ function InstalledFonts() {
{ notice.message }
</Notice>
) }
{ ! hasFonts && (
<Text as="p">
{ __( 'No fonts installed.' ) }
</Text>
) }
{ baseThemeFonts.length > 0 && (
<VStack>
<h2 className="font-library-modal__fonts-title">
Expand Down
18 changes: 18 additions & 0 deletions test/e2e/specs/site-editor/font-library.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ test.describe( 'Font Library', () => {
await editor.canvas.locator( 'body' ).click();
} );

test( 'should display the "no font installed." message', async ( {
page,
} ) => {
await page.getByRole( 'button', { name: 'Styles' } ).click();
await page
.getByRole( 'button', { name: 'Typography Styles' } )
.click();
await page
.getByRole( 'button', {
name: 'Add fonts',
} )
.click();
await page.getByRole( 'tab', { name: 'Library' } ).click();
await expect(
page.getByLabel( 'library' ).getByText( 'No fonts installed.' )
).toBeVisible();
} );

test( 'should display the "Add fonts" button', async ( { page } ) => {
await page.getByRole( 'button', { name: 'Styles' } ).click();
await page
Expand Down

1 comment on commit 368d0ac

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 368d0ac.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10072069414
📝 Reported issues:

Please sign in to comment.