test: Allow mockAppRoot().withSetting() to mock setting structure#37162
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
WalkthroughAdds unit tests for the useSettingStructure hook and updates MockedAppRootBuilder.withSetting to accept an optional Partial that is merged into constructed settings, causing querySettings to return settings including any provided extra fields. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Test
participant Builder as MockedAppRootBuilder
participant RenderHook as renderHook
participant Hook as useSettingStructure
participant Ctx as SettingsContext
Test->>Builder: withSetting(id, value, settingStructure?)
Builder-->>Ctx: store merged ISetting (includes _id, value, ...settingStructure)
Test->>RenderHook: renderHook(useSettingStructure, wrapper=mockAppRoot)
RenderHook->>Hook: call with setting id
Hook->>Ctx: query setting by id
Ctx-->>Hook: return ISetting or undefined
Hook-->>RenderHook: provide result
RenderHook-->>Test: assert result matches expected or is undefined
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #37162 +/- ##
===========================================
- Coverage 67.43% 67.38% -0.06%
===========================================
Files 3288 3288
Lines 111814 111814
Branches 20424 20428 +4
===========================================
- Hits 75406 75342 -64
- Misses 33724 33786 +62
- Partials 2684 2686 +2
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
apps/meteor/client/views/admin/settings/useSettingStructure.spec.ts(1 hunks)packages/mock-providers/src/MockedAppRootBuilder.tsx(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/meteor/client/views/admin/settings/useSettingStructure.spec.ts (2)
packages/ui-contexts/src/index.ts (1)
useSettingStructure(73-73)packages/mock-providers/src/index.ts (1)
mockAppRoot(3-3)
🔇 Additional comments (3)
apps/meteor/client/views/admin/settings/useSettingStructure.spec.ts (2)
1-4: LGTM on imports.The imports are appropriate for testing a hook with mocked app context.
35-41: LGTM on negative test case.The test correctly verifies that
undefinedis returned when a setting doesn't exist in the mocked context.packages/mock-providers/src/MockedAppRootBuilder.tsx (1)
471-476: LGTM! The implementation correctly extends withSetting to accept setting structure.The changes enable mocking of complete setting structures for testing components that rely on setting metadata beyond just key/value pairs. The implementation is sound:
- Backward compatible: The third parameter
settingStructureis optional, so existing test code continues to work.- Correct merge order: Spreading
settingStructurefirst (line 473), then explicitly setting_idandvalue(lines 474-475) ensures that the method parameters always take precedence over any conflicting fields insettingStructure.- Type safety: The cast to
ISettingat line 476 is acceptable for test infrastructure code, though callers are responsible for providing sufficient fields to matchISettingrequirements for their specific test scenarios.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/mock-providers/src/MockedAppRootBuilder.tsx (1)
471-476: LGTM! The implementation correctly merges the setting structure.The method signature change and spread operator implementation look good. The spread order ensures that
_idandvaluealways take precedence over any values provided insettingStructure, which is the correct behavior.Consider adding JSDoc documentation to clarify the new parameter's purpose:
+ /** + * Adds a mock setting with the given ID and value. + * @param id - The setting ID + * @param value - The setting value + * @param settingStructure - Optional partial setting structure to merge (e.g., type, section, i18nLabel) + */ withSetting(id: string, value: SettingValue, settingStructure?: Partial<ISetting>): this {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/mock-providers/src/MockedAppRootBuilder.tsx(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: 🔨 Test Unit / Unit Tests
- GitHub Check: 🔎 Code Check / Code Lint
- GitHub Check: 🔎 Code Check / TypeScript
- GitHub Check: 🔨 Test Storybook / Test Storybook
- GitHub Check: 📦 Meteor Build - coverage
- GitHub Check: CodeQL-Build
- GitHub Check: CodeQL-Build
Proposed changes (including videos or screenshots)
This allows the testing of components that use structure data from the settings, like
useEditableSettingoruseSettingStructure, as currentlywithSetting()only returns the key/value pair when using any of these hooksSummary by CodeRabbit
New Features
Tests
Chores
Impact