Skip to content

test: Add unit test for projects/app/src/web/core/chat/context/useChatStore.ts #4812

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gru-agent[bot]
Copy link
Contributor

@gru-agent gru-agent bot commented May 14, 2025

Trigger Info

Trigger Type Triggered By Source Pull Request Assignment
PR Created LOUSANPANG 4811 Detail

Summary

PR Summary

Changes Introduced:

  1. Enhancements to useChatStore:

    • Added unit tests for useChatStore to validate its functionality, including:

      • Setting and restoring the source and lastChat values.

      • Generating new chatId when the source changes.

      • Setting appId and lastChatAppId.

      • Ensuring appId is not set to an empty value.

      • Setting chatId and lastChatId.

      • Generating new chatId if none is provided.

      • Setting outLinkAuthData.

  2. Introduction of createCustomStorage:

    • Exported the createCustomStorage function from useChatStore.

    • Added unit tests for createCustomStorage to validate:

      • Storage creation with appId embedded in the key.

      • Proper segregation of session and local storage data.

      • Removal of items from both storages.

  3. Mocking Utilities:

    • Mocked getNanoid function to return a consistent value (test-nanoid) for predictable testing.

    • Created mock implementations for sessionStorage and localStorage to simulate browser storage behavior during tests.

  4. Testing Framework Setup:

    • Utilized vitest for unit testing.

    • Added comprehensive test cases to ensure robustness of the useChatStore and createCustomStorage functionalities.

Additional Files:

  • Added new test file: useChatStore.test.ts for unit testing.

  • Binary and map files related to corepack were introduced, likely for dependency management or build tooling.

Impact:

  • Improved code reliability and maintainability by introducing unit tests for critical functionalities.

  • Enhanced storage handling with createCustomStorage, ensuring better data management and isolation.

  • Facilitated future development and debugging with robust test coverage.

Coverage

The change in coverage value, such as: 0% -> 50%, indicates that the coverage was 0% before writing the tests and 50% after writing them.

https://web.dev/articles/ta-code-coverage

Type Change
lines 0% -> 96.15% 🔺
functions 0% -> 90.9% 🔺
statements 0% -> 96.15% 🔺
branches 0% -> 90.32% 🔺
source program

Test Statuses

Status Change
passed 0 -> 9 🔺
failed 0 -> 0
skipped 0 -> 0
source program

Tip

You can @gru-agent and leave your feedback. TestGru will make adjustments based on your input

Tip

You can @gru-agent rebase to rebase the PR.

Tip

You can @gru-agent redo to reset or rebase before redoing the PR.

Tip

To modify the test code yourself, click here Edit Test Code

Copy link

Preview mcp_server Image: ghcr.io/labring/fastgpt-pr:fatsgpt_mcp_server_74be2169e4f68b10922b9d970090f0fd452288e9

Copy link

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 22.41% 11512 / 51349
🔵 Statements 22.41% 11512 / 51349
🔵 Functions 29.85% 312 / 1045
🔵 Branches 66.44% 804 / 1210
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
projects/app/src/web/core/chat/context/useChatStore.ts 96.15% 90.32% 90.9% 96.15% 116-119
Generated in workflow #847 for commit 74be216 by the Vitest Coverage Report Action

Copy link

Preview sandbox Image: ghcr.io/labring/fastgpt-pr:fatsgpt_sandbox_74be2169e4f68b10922b9d970090f0fd452288e9

Copy link

Preview fastgpt Image: ghcr.io/labring/fastgpt-pr:fatsgpt_74be2169e4f68b10922b9d970090f0fd452288e9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants