[RNMobile] Use BlockEdit component when testing component rendering#29569
[RNMobile] Use BlockEdit component when testing component rendering#29569
Conversation
BlockEdit adds the block edit context, which could be required by some parts of an edit component when it's rendered in a unit test.
|
Size Change: 0 B Total Size: 1.4 MB ℹ️ View Unchanged
|
|
I've just pushed a couple of changes to debug the |
Looks like the changes have fixed the workflow so I'm going to make a separate PR for those and then update this one. |
Looks good. Can we merge this one and follow up with anything else? |
I'd rather merge the changes in the e2e tests in another PR I've just created to prevent confusion. Once it's approved I'll merge all of them and then we can update your branch. |
|
@guarani I assigned you as a reviewer of the PR I had to create to fix the e2e tests oft this one. Let me know if you have some time to check it, if not we could find someone else to take a look, thanks 🙇 ! |
Description
Fixes #29442.
Add extra logic to some of the native unit tests that renders blocks:
BlockEditcomponent that will render the block that we want to testThis way, by rendering the edit components from the
BlockEditcomponent, we add the block edit context that could be required by other components when they're rendered.In fact, this is the case when the incoming changes from this PR would be merged, the
RichTexteditor component will require theclientIDproperty that is exposed from a new context that is rendered inBlockEditcomponent.Caveats
My initial approach was to apply this change to all the native unit tests that render edit components but didn't work.
For example in the
Fileblock, one of the tests triggers theonLayouthandler. If we render theBlockEditcomponent, we don't have access to the instance required to trigger that handler so the test fails.I spent some time on finding an alternative but I didn't find any that fits easily. One option I tried was using the
enzymelibrary but when rendering the component via themountfunction,AztecViewgenerates multiple errors. Shallow rendering is not enough because the required handler that we want to trigger is in the children.Probably the best option would be to integrate a more complete library like
@testing-library/react-native, that provides a lot interesting functionality that would make easier to do native unit tests.How has this been tested?
Test with latest changes from
trunkbranchnpm run native test.Test with changes from PR
try/block-context-cleanupfrom the PR.git cherry-pick -n 742eb696556f87707aca0517656d7464ab543bdc.npm run native test.Screenshots
N/A
Types of changes
Bug fix
Checklist: