Skip to content

test: unify i18next mocks into centralized helpers#30376

Merged
asukaminato0721 merged 5 commits intomainfrom
12-30-i18n-mock
Dec 31, 2025
Merged

test: unify i18next mocks into centralized helpers#30376
asukaminato0721 merged 5 commits intomainfrom
12-30-i18n-mock

Conversation

@hyoban
Copy link
Member

@hyoban hyoban commented Dec 30, 2025

Consolidate scattered i18next mock implementations across test files into a single source of truth. This reduces duplication and ensures consistent mock behavior.

  • Create test/i18n-mock.ts with reusable factory functions
  • Update vitest.setup.ts to use the centralized helpers
  • Remove redundant mock definitions from 8 test files
  • Update testing.md documentation

🤖 Generated with Claude Code

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

fixes #30304

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

Consolidate scattered i18next mock implementations across test files into
a single source of truth. This reduces duplication and ensures consistent
mock behavior.

- Create test/i18n-mock.ts with reusable factory functions
- Update vitest.setup.ts to use the centralized helpers
- Remove redundant mock definitions from 8 test files
- Update testing.md documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hyoban, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the i18next mocking strategy within the test suite. By centralizing react-i18next mock implementations into a dedicated helper module, it eliminates duplication, ensures consistent mock behavior across tests, and simplifies the process of setting up translation mocks. This change enhances the maintainability and reliability of the testing environment by providing a single source of truth for i18n test utilities.

Highlights

  • Centralized i18next Mocks: Consolidated scattered react-i18next mock implementations across test files into a single, reusable module to reduce duplication and ensure consistent mock behavior.
  • New Helper Module: Introduced web/test/i18n-mock.ts which provides factory functions like createReactI18nextMock for standardized i18next mocking in tests.
  • Streamlined Test Files: Removed redundant and custom react-i18next mock definitions from 8 individual test files, simplifying their structure and improving maintainability.
  • Updated Global Setup: Modified web/vitest.setup.ts to leverage the new centralized createReactI18nextMock helper for global i18next mocking, ensuring consistent default behavior.
  • Documentation Update: The web/testing/testing.md file has been updated to guide developers on the new centralized i18next mocking approach and how to use the helper functions for custom translations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request does a great job of centralizing the i18next mock logic into a reusable helper file, test/i18n-mock.ts. This significantly reduces code duplication across numerous test files and improves maintainability. The changes in the test files to adopt the new helper are clean, and the documentation update in testing.md is clear and helpful. I've left one comment on the new i18n-mock.ts file to suggest improvements that would make the mock more robust by handling a couple of edge cases (returnObjects option and array-based namespaces) that were either supported in the previous implementation or are part of the i18next API. Overall, this is a solid and valuable refactoring.

@hyoban hyoban marked this pull request as ready for review December 31, 2025 06:31
Copilot AI review requested due to automatic review settings December 31, 2025 06:31
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Dec 31, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR consolidates scattered i18next mock implementations into a centralized test/i18n-mock.ts module with reusable factory functions. The changes reduce duplication across test files and provide a single source of truth for i18n mocking.

Key changes:

  • Created test/i18n-mock.ts with createTFunction, createUseTranslationMock, createTransMock, and createReactI18nextMock helper functions
  • Updated vitest.setup.ts to use the new centralized mock
  • Removed redundant i18n mock definitions from 15+ test files across plugins, datasets, billing, and base components
  • Updated testing.md documentation with usage examples

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
web/test/i18n-mock.ts New centralized mock factory functions for i18n testing - provides reusable helpers for creating translation mocks
web/vitest.setup.ts Updated to use centralized createReactI18nextMock() instead of inline mock definition
web/testing/testing.md Added documentation about global mock behavior and usage examples for custom translations
web/app/components/plugins/plugin-mutation-model/index.spec.tsx Removed redundant i18n mocks (now uses global mock)
web/app/components/plugins/plugin-detail-panel/subscription-list/edit/index.spec.tsx Removed redundant react-i18next mock
web/app/components/plugins/plugin-detail-panel/subscription-list/create/oauth-client.spec.tsx Removed redundant react-i18next mock
web/app/components/plugins/plugin-detail-panel/subscription-list/create/common-modal.spec.tsx Removed redundant react-i18next mock
web/app/components/plugins/marketplace/index.spec.tsx Updated i18next-config mock and test assertions to match new global mock behavior (namespace prefixes)
web/app/components/plugins/install-plugin/install-from-local-package/steps/uploading.spec.tsx Removed redundant react-i18next mock
web/app/components/plugins/install-plugin/install-from-local-package/steps/install.spec.tsx Uses centralized mock with custom Trans override for components prop handling
web/app/components/plugins/card/index.spec.tsx Removed redundant i18n mocks
web/app/components/datasets/documents/create-from-pipeline/processing/index.spec.tsx Removed redundant react-i18next mock
web/app/components/datasets/create/index.spec.tsx Removed redundant react-i18next mock
web/app/components/billing/pricing/footer.spec.tsx Removed custom translation map and mock
web/app/components/base/input/index.spec.tsx Updated to import and use createReactI18nextMock with custom translations
web/app/components/base/input-with-copy/index.spec.tsx Updated to import and use createReactI18nextMock with custom translations
web/app/components/base/inline-delete-confirm/index.spec.tsx Updated to import and use createReactI18nextMock with custom translations
web/app/components/app/configuration/config/config-audio.spec.tsx Removed redundant react-i18next mock
web/app/components/app/configuration/config/agent-setting-button.spec.tsx Removed redundant react-i18next mock

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…eateReactI18nextMock` and detail global mock provisions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor/Chore] Improve how we mock for i18n in tests

3 participants

Comments