Skip to content

feat: add comprehensive unit tests#37

Open
XinyueDu wants to merge 6 commits intomasterfrom
dev/add-test
Open

feat: add comprehensive unit tests#37
XinyueDu wants to merge 6 commits intomasterfrom
dev/add-test

Conversation

@XinyueDu
Copy link

@XinyueDu XinyueDu commented Jan 9, 2026

增加单测,提升测试覆盖率至 100%
image

Copilot AI review requested due to automatic review settings January 9, 2026 08:10
@gemini-code-assist
Copy link

Summary of Changes

Hello @XinyueDu, 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!

此拉取请求通过引入一套全面的单元测试和样式化 SVG 快照测试,显著提升了项目代码的测试覆盖率和健壮性。这些新增的测试用例旨在验证各种树布局算法在不同场景下的正确性和一致性,包括边界条件、性能以及视觉输出,从而确保代码质量和稳定性。

Highlights

  • 全面新增单元测试: 新增了 __tests__/basic.test.ts 文件,其中包含了对边界情况、坐标完整性、遍历方法、包围盒、数据保留、方向特定行为、性能基线、算法一致性、错误处理、缩进算法选项、方向变体、固定根选项、思维导图边缘情况、节点构造函数边缘情况以及复杂树结构等方面的全面单元测试。
  • 引入样式化 SVG 快照测试: 修改了 compact-box.test.tsdendrogram.test.tsindented.test.tsmindmap.test.ts 文件,以引入新的样式化 SVG 快照测试。这些测试涵盖了不同节点类型(圆形、方形、矩形)和颜色方案(按深度、按分支、单一颜色)的复杂树布局,确保视觉输出的一致性。
  • 新增复杂树结构测试数据: 添加了 __tests__/fixtures/complex-tree.json 文件,提供了一个用于测试各种布局算法的复杂树结构数据。
  • SVG 生成器功能增强: 更新了 __tests__/utils/svg-generator.ts,增加了对样式化 SVG 生成的支持,包括定义节点类型和颜色方案。引入了 assignParent 辅助函数用于分支着色,以及 getNodeColor 函数来根据不同方案获取节点颜色。同时,重构了快照比较逻辑,并新增了 expectStyledSVGToMatchSnapshot 函数。
  • 更新项目配置: 修改了 package.json 文件,新增了 test:coverage 脚本,并添加了 @vitest/coverage-v8 依赖,以支持测试覆盖率报告的生成。
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

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 pull request adds comprehensive unit tests to achieve 100% test coverage. The changes introduce styled SVG generation capabilities for visual regression testing, along with new test cases that cover different node types (circle, square, rect) and color schemes (depth, branch, single) for both mindmap and indented layouts.

Key changes:

  • Added @vitest/coverage-v8 dependency and test:coverage npm script
  • Enhanced SVG generator utility with styled rendering options
  • Added comprehensive visual snapshot tests covering 18 different layout combinations
  • Generated complete pnpm lockfile

Reviewed changes

Copilot reviewed 8 out of 45 changed files in this pull request and generated no comments.

Show a summary per file
File Description
package.json Added coverage dependency and test script
pnpm-lock.yaml New complete lockfile with all dependencies
tests/utils/svg-generator.ts Enhanced with styled SVG generation functions supporting node types and color schemes
tests/mindmap.test.ts Added comprehensive styled snapshot tests
tests/indented.test.ts Added comprehensive styled snapshot tests
tests/snapshots/*.svg 18 new SVG snapshot files for visual regression testing

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

Copy link

@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

这个 PR 增加了非常全面的单元测试,极大地提升了代码库的测试覆盖率,做得很好。测试覆盖了边界情况、多种算法配置和复杂树结构,这将大大提高代码的稳定性和可维护性。

我发现了一些可以改进的地方,主要集中在提高测试代码的类型安全性和可读性方面,例如避免使用 as any 类型断言。此外,package.json 中的一些依赖版本似乎不正确,可能会导致安装问题。我还对 SVG 生成工具函数提出了一些重构建议,以提高其通用性和鲁棒性。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant