Skip to content

test: Allow mockAppRoot().withSetting() to mock setting structure#37162

Merged
kodiakhq[bot] merged 5 commits into
developfrom
test/extend-withsetting
Oct 10, 2025
Merged

test: Allow mockAppRoot().withSetting() to mock setting structure#37162
kodiakhq[bot] merged 5 commits into
developfrom
test/extend-withsetting

Conversation

@MartinSchoeler

@MartinSchoeler MartinSchoeler commented Oct 7, 2025

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

This allows the testing of components that use structure data from the settings, like useEditableSetting or useSettingStructure, as currently withSetting() only returns the key/value pair when using any of these hooks

Summary by CodeRabbit

  • New Features

    • None.
  • Tests

    • Added unit tests for the admin settings hook, covering both present and missing settings to validate correct behavior.
  • Chores

    • Enhanced test utilities to allow richer mocked setting metadata for more realistic test scenarios.
  • Impact

    • No user-facing changes; improvements increase test coverage and developer tooling flexibility.

@dionisio-bot

dionisio-bot Bot commented Oct 7, 2025

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is targeting the wrong base branch. It should target 7.12.0, but it targets 7.11.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Oct 7, 2025

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 180887c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Oct 7, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds 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

Cohort / File(s) Summary
Admin settings hook tests
apps/meteor/client/views/admin/settings/useSettingStructure.spec.ts
Added unit tests verifying useSettingStructure returns the expected ISetting-derived object when present and undefined when absent; tests use renderHook with a mocked app root wrapper.
Mock app root builder API update
packages/mock-providers/src/MockedAppRootBuilder.tsx
Changed withSetting(id: string, value: SettingValue)withSetting(id: string, value: SettingValue, settingStructure?: Partial<ISetting>); the builder now spreads settingStructure into the constructed ISetting so stored/query results include any extra fields provided.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

In a burrow of mocks where settings sprout,
I spread extra fields and hop about.
Hooks peek in corners, tests give a cheer,
Present or absent — the answer is clear.
Thump-thump, the builder added structure here. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and succinctly conveys that the mockAppRoot().withSetting() helper has been extended to mock setting structure in tests, accurately reflecting the PR’s primary change.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/extend-withsetting

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Oct 7, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.38%. Comparing base (7c1f5d2) to head (180887c).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             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     
Flag Coverage Δ
e2e 57.32% <ø> (-0.01%) ⬇️
unit 71.39% <ø> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MartinSchoeler MartinSchoeler marked this pull request as ready for review October 9, 2025 18:43
@MartinSchoeler MartinSchoeler requested a review from a team as a code owner October 9, 2025 18:43

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between fd4f9b2 and d0dcb9e.

📒 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 undefined is 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:

  1. Backward compatible: The third parameter settingStructure is optional, so existing test code continues to work.
  2. Correct merge order: Spreading settingStructure first (line 473), then explicitly setting _id and value (lines 474-475) ensures that the method parameters always take precedence over any conflicting fields in settingStructure.
  3. Type safety: The cast to ISetting at line 476 is acceptable for test infrastructure code, though callers are responsible for providing sufficient fields to match ISetting requirements for their specific test scenarios.

Comment thread apps/meteor/client/views/admin/settings/useSettingStructure.spec.ts
@tassoevan tassoevan added the stat: QA assured Means it has been tested and approved by a company insider label Oct 10, 2025
@MartinSchoeler MartinSchoeler added this to the 7.12.0 milestone Oct 10, 2025
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Oct 10, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
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 _id and value always take precedence over any values provided in settingStructure, 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 2646138 and 93398b4.

📒 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

@kodiakhq kodiakhq Bot merged commit 16da6b3 into develop Oct 10, 2025
49 checks passed
@kodiakhq kodiakhq Bot deleted the test/extend-withsetting branch October 10, 2025 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants