Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add resize support to box when changing font-face on display/edit mode (
#1275) * Add resize support to box when changing font-face on display/edit mode * Cover unicode chars, font-weight, font-style * Add ((MULTIPLE)) support proposal * Improve docs. * Fix problematic rest approach. * Add fontSize support. Remove content support. Add a better support for MULTIPLE. Improve useLoadFontFiles.js * Update textStyle tests * Force display=auto on @font-face declaration while loading fonts from Google Fonts. * Fix typo * Add codecov to useLoadFontFiles * Update tests to match new APIs proposed after merge. * Address PR reviews * Address some PR reviews. * Adjustments after #1323 merge. Revert content as parameter to load font (To address #923). * Address recent PR review * Improve code performance/reusability. Thanks @dvoytenko * Clean up promise logic a bit Co-authored-by: Pascal Birchler <pascalb@google.com> Co-authored-by: Morten Barklund <morten.barklund@xwp.co>
- Loading branch information
1 parent
d2a9a76
commit bc47950
Showing
8 changed files
with
268 additions
and
54 deletions.
There are no files selected for viewing
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
83 changes: 83 additions & 0 deletions
83
assets/src/edit-story/app/font/test/actions/useLoadFontFiles.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,83 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useLoadFontFiles from '../../actions/useLoadFontFiles'; | ||
|
||
const DEFAULT_FONT = { | ||
font: { | ||
family: 'Font', | ||
service: 'fonts.google.com', | ||
}, | ||
fontWeight: 400, | ||
fontStyle: 'normal', | ||
content: 'Fill in some text', | ||
}; | ||
|
||
describe('useLoadFontFiles', () => { | ||
beforeEach(() => { | ||
const el = document.getElementById('font-css'); | ||
if (el) { | ||
el.remove(); | ||
} | ||
}); | ||
|
||
it('maybeEnqueueFontStyle', () => { | ||
expect(document.getElementById('font-css')).toBeNull(); | ||
|
||
renderHook(async () => { | ||
const maybeEnqueueFontStyle = useLoadFontFiles(); | ||
|
||
await maybeEnqueueFontStyle([DEFAULT_FONT]); | ||
}); | ||
|
||
expect(document.getElementById('font-css')).toBeDefined(); | ||
}); | ||
|
||
it('maybeEnqueueFontStyle skip', () => { | ||
expect(document.getElementById('font-css')).toBeNull(); | ||
|
||
renderHook(async () => { | ||
const maybeEnqueueFontStyle = useLoadFontFiles(); | ||
|
||
await maybeEnqueueFontStyle([ | ||
{ ...DEFAULT_FONT, font: { ...DEFAULT_FONT.font, service: 'abcd' } }, | ||
]); | ||
}); | ||
|
||
expect(document.getElementById('font-css')).toBeNull(); | ||
}); | ||
|
||
it('maybeEnqueueFontStyle reflect', () => { | ||
expect(document.getElementById('font-css')).toBeNull(); | ||
|
||
renderHook(async () => { | ||
const maybeEnqueueFontStyle = useLoadFontFiles(); | ||
|
||
await maybeEnqueueFontStyle([{}, DEFAULT_FONT]); | ||
}); | ||
|
||
expect(document.querySelectorAll('link')).toHaveLength(1); | ||
expect(document.getElementById('font-css')).toBeDefined(); | ||
}); | ||
}); |
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
Oops, something went wrong.