-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quotes to font family names (#476)
* Add quotes to families ending in number on gfonts * Add quotes to uploaded font family name * Check for special characters on form upload * Trim font names * Avoid re-rendering due to function definitions Moves the definition of onFormDataChange inside the effect where it's used so that it won't be re defined on render. Also, wraps isFormValid on useCallback for the same reason. * Add quotes to all font name strings #476 (comment) * Add tests Add dependencies required for test and linting as well: - @wordpress/scripts - @wordpress/eslint-plugin * Temporarily disable eslint rule Out of scope for this PR; follow-up to come. * Add quotes to demo style font name
- Loading branch information
Showing
8 changed files
with
7,820 additions
and
5,021 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { addQuotesToName } from '../utils'; | ||
|
||
describe( 'addQuotesToName', () => { | ||
const easyFonts = [ 'Roboto' ]; | ||
const complicatedFonts = [ | ||
'Roboto Mono', | ||
'Open Sans Condensed', | ||
'Exo 2', | ||
'Libre Barcode 128 Text', | ||
'Press Start 2P', | ||
'Rock 3D', | ||
'Rubik 80s Fade', | ||
]; | ||
|
||
it( 'should add quotes to all font names', () => { | ||
[ ...easyFonts, ...complicatedFonts ].forEach( ( font ) => { | ||
expect( addQuotesToName( font ) ).toEqual( `'${ font }'` ); | ||
} ); | ||
} ); | ||
|
||
it( 'should avoid FontFace objects with empty font name', () => { | ||
complicatedFonts.forEach( ( font ) => { | ||
const quoted = addQuotesToName( font ); | ||
const fontObject = new FontFace( quoted, {} ); | ||
|
||
expect( fontObject ).toBeInstanceOf( FontFace ); | ||
expect( fontObject.family ).toEqual( quoted ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
testEnvironment: 'jsdom', | ||
rootDir: '../../', | ||
testMatch: [ '<rootDir>/src/test/**/*.js' ], | ||
moduleFileExtensions: [ 'js' ], | ||
moduleNameMapper: { | ||
'^@/(.*)$': '<rootDir>/src/$1', | ||
}, | ||
setupFiles: [ '<rootDir>/test/unit/setup.js' ], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Stub out the FontFace class for tests. | ||
global.FontFace = class { | ||
constructor( family, source ) { | ||
this.family = family; | ||
this.source = source; | ||
} | ||
}; |