[RNMobile] Tested the React Native <RichText/> component to ensure various expectations regarding font size.#35528
Conversation
…s expectations regarding font size. Previously, the `<RichText/>` component lacked test coverage in React Native altogether. This is my humble attempt at adding coverage for styling rich text displayed with font size derived from various sources, i.e., `fontSize` and `style.fontSize` component props, and global state selected from `__experimentalGlobalStylesBaseStyles.typography.fontSize`.
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @ttahmouch! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
mkevins
left a comment
There was a problem hiding this comment.
This looks great Tony! Thanks for adding these. I like the comments in each test for the functional test approach.
Code looks good, and I tested these via the steps described.
| // Arrange | ||
| const expectedFontSize = 32; | ||
| // Act | ||
| const { getByA11yLabel } = render( | ||
| <RichText | ||
| accessibilityLabel={ 'editor' } | ||
| fontSize={ 'min(2em, 3em)' } | ||
| /> | ||
| ); | ||
| // Assert | ||
| const actualFontSize = getByA11yLabel( 'editor' ).props.fontSize; | ||
| expect( actualFontSize ).toBe( expectedFontSize ); |
There was a problem hiding this comment.
I appreciate the comments here. 😄 👍 (as in the other tests)
There was a problem hiding this comment.
|
Nice work @ttahmouch ! |
Description
Previously, the
<RichText/>component lacked test coverage in React Native altogether.This is my humble attempt at adding coverage for styling rich text displayed with font size derived from various sources, i.e.,
fontSizeandstyle.fontSizecomponent props, and global state selected from__experimentalGlobalStylesBaseStyles.typography.fontSize.How has this been tested?
The tests were written as "black-box integration" tests. That's basically just my way of saying that I deliberately tried to abstain from mocking or stubbing implementation details of the
<RichText/>component itself and only mocked state provided to the component from the outer edges of the system, i.e., component props, global state selected from Redux. That means thatgetPxFromCssUnitandDimensions.get( 'window' )are "real."These tests are supposed to closely resemble "functional" testing in that they "display" the
<RichText/>component in various staged scenarios and attempt to assert the results from the "users' experience." I would have preferred to use the actualtextthat the user would see displayed in order to assert against, but for some reason ourtextprovided via component props is modified to be represented as HTML fragments and is wrapped in<div>which could lead to nondeterminism. I chose to useaccessibilityLabelinstead even though it's not ideal.Screenshots
The changes do not affect the actual UX implementation details. This just adds test coverage to existing implementation details.
Types of changes
Test Coverage.
ESLint
No issues found with the contents of this PR. All issues found are regarding existing skipped tests.
Checklist:
*.native.jsfiles for terms that need renaming or removal).