-
Notifications
You must be signed in to change notification settings - Fork 76
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
fix: use built in provider declaration for previewContext in render function for mocks #14525
fix: use built in provider declaration for previewContext in render function for mocks #14525
Conversation
📝 WalkthroughWalkthroughThe pull request modifies the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
frontend/app-development/test/mocks.tsx (1)
46-50
: Consider reducing code duplication.The context value computation is identical in both the initial render and rerender. Consider extracting the provider wrapper into a separate component to maintain DRY principles.
+ const PreviewContextWrapper = ({ children, previewContextProps }) => ( + <PreviewContext.Provider + value={{ ...defaultPreviewContextProps, ...previewContextProps }} + > + <BrowserRouter>{children}</BrowserRouter> + </PreviewContext.Provider> + ); export const renderWithProviders = ( queries: Partial<ServicesContextProps> = {}, queryClient?: QueryClient, previewContextProps: Partial<PreviewContextProps> = {}, ) => (component: ReactNode) => { const renderResult = render( <ServicesContextProvider {...queriesMock} {...queries} client={queryClient} clientConfig={queryClientConfigMock} > <PreviewConnectionContextProvider> - <PreviewContext.Provider - value={{ ...defaultPreviewContextProps, ...previewContextProps }} - > - <BrowserRouter>{component}</BrowserRouter> - </PreviewContext.Provider> + <PreviewContextWrapper previewContextProps={previewContextProps}> + {component} + </PreviewContextWrapper> </PreviewConnectionContextProvider> </ServicesContextProvider>, );
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
frontend/app-development/test/mocks.tsx
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Build environment and run e2e test
- GitHub Check: Testing
🔇 Additional comments (2)
frontend/app-development/test/mocks.tsx (2)
12-12
: LGTM! Import statement updated correctly.The import now includes both the PreviewContext and its type, which is necessary for using the built-in context provider.
29-33
: Great improvement using the built-in context provider!The implementation is now more flexible as it:
- Uses React's built-in context provider mechanism
- Correctly merges default and custom props
- Allows external control of context values
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #14525 +/- ##
=======================================
Coverage 95.70% 95.70%
=======================================
Files 1901 1901
Lines 24739 24739
Branches 2833 2833
=======================================
Hits 23676 23676
Misses 802 802
Partials 261 261 ☔ View full report in Codecov by Sentry. |
Description
Use built in provider declaration for previewContext in render function for mocks, instead of the custom prover component. The custom provider component does not allow setting the context-value from outside.
Related Issue(s)
Verification
Summary by CodeRabbit