-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore: Mobile: Add NoteBodyViewer tests
#10747
Chore: Mobile: Add NoteBodyViewer tests
#10747
Conversation
…to pr/mobile/webview-testing
NoteBodyViewer testsNoteBodyViewer tests
| // eslint-disable-next-line @typescript-eslint/no-explicit-any -- HACK: Allow wrapper testing logic to access the DOM. | ||
| const additionalProps: any = { document: dom?.window?.document }; | ||
| return ( | ||
| <View style={props.style} testID={props.testID} {...additionalProps}/> | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the virtual DOM for this mock is accessed with code similar to the following:
// Gets the <View></View> that is assigned a testID above:
const webviewContent = await screen.findByTestId('NoteBodyViewer');
// Get the `document` prop provided to the <View> through `additionalProps`:
const doc = webviewContent.props.document;
// Use the `document`
expect(doc.querySelector('h1').textContent).toBe('something'));Above, document is retrieved through the props passed to the <View> object.
Previously, I was trying to access document through the ref passed to the parent of the ExtendedWebView. This, however, 1) seems to involve tree navigation and 2) (await screen.findByTestId('id')).parent.props.ref does not seem to contain the ref forwarded to the WebView's parent.
|
There is now a conflict on shim-init-react.ts |
Summary
This pull request allows testing code that includes communication with a WebView. At present, it includes tests for
NoteBodyViewer.Note
This pull request includes code from #10731 and a version #10748. As such, #10731 and #10748 should be reviewed and merged first.
Motivation
The goal of this pull request is to prevent regressions by increasing the code coverage of the mobile app.
This pull request was motivated, in particular, by these two issues:
Although this pull request currently only includes tests for
NoteBodyViewer, it should allow writing tests forNote.tsxand additional tests forNoteEditor.tsx. It should also allow more complete testing of the plugin logic on mobile.Changes made
ExtendedWebviewusingJSDOM.jsdomfor certain tests for code intended to run in a WebView, rather than for all tests. TheJSDOMconstructor doesn't seem to work in ajsdomenvironment (it fails with aTextEncoder is undefinederror).sharpas a development dependency ofapp-mobile-- it's used byshim-init-nodewhen attaching pictures to notes during testing.Manual testing
Android 13: