Skip to content

fix(tests): update scanUsedIcons tests to include required radio icons#6894

Merged
Soulter merged 1 commit intoAstrBotDevs:masterfrom
Vorest3679:debug-for-tests
Mar 24, 2026
Merged

fix(tests): update scanUsedIcons tests to include required radio icons#6894
Soulter merged 1 commit intoAstrBotDevs:masterfrom
Vorest3679:debug-for-tests

Conversation

@Vorest3679
Copy link
Contributor

@Vorest3679 Vorest3679 commented Mar 24, 2026

Motivation / 动机

修复 dashboard/scripts/subset-mdi-font.mjs 在图标子集化后遗漏 Vuetify v-radio 间接依赖图标的问题。

在 fix(ui): include vuetify radiobox icons #6892 中,已通过 REQUIRED_ICONSmdi-radiobox-blankmdi-radiobox-marked 加入 usedIcons 的初始化,解决了 Radio 按钮无法正确渲染的问题;但这也改变了 scanUsedIcons() 的行为,使其在源码中没有任何 mdi-* 图标时也会返回这两个必需图标,导致原有单元测试中关于“返回空集”或“集合大小”的断言不再准确。

本 PR 仅更新对应单元测试,使测试行为与当前实现保持一致,确保测试套件能够准确反映 REQUIRED_ICONS 的新逻辑并稳定通过。

Modifications / 改动点

  • 更新 dashboard/tests/subsetMdiFont.test.mjs

  • 调整 scanUsedIcons 相关测试断言,使其适配 REQUIRED_ICONS 默认注入的行为

  • 将“无图标时返回空集”的旧测试更新为“至少包含两个 Radio 必需图标”

  • 更新已有集合大小断言,计入 mdi-radiobox-blankmdi-radiobox-marked

  • 新增去重测试,验证当源码中已包含 mdi-radiobox-marked 时不会重复加入

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

已执行以下测试命令:

node --test --experimental-test-isolation=none dashboard/tests/subsetMdiFont.test.mjs

测试结果:

text

1..18
# tests 18
# pass 18
# fail 0

本次修改后,subsetMdiFont.test.mjs 全部测试通过,测试行为已与 REQUIRED_ICONS 新逻辑保持一致。

Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。

🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
/ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txt 和 pyproject.toml 文件相应位置。

😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。

Summary by Sourcery

Align scanUsedIcons unit tests with the updated behavior that always includes required Vuetify radio icons.

Tests:

  • Update scanUsedIcons extraction tests to expect required radio icons in addition to source-referenced icons.
  • Adjust the no-icons-found test to assert that the required radio icons are still present by default.
  • Add a new test ensuring required radio icons are not duplicated when already referenced in source files.

@auto-assign auto-assign bot requested review from Soulter and advent259141 March 24, 2026 08:43
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 24, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

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

此拉取请求旨在修复 dashboard/scripts/subset-mdi-font.mjs 模块的单元测试,使其与最近引入的 REQUIRED_ICONS 逻辑保持一致。由于 v-radio 组件所需的图标现在会被强制包含在 usedIcons 集合中,即使源码中未直接引用,原有的测试断言已不再准确。本次更新通过调整现有测试和引入新测试,确保测试套件能够正确反映这一新行为,从而提高测试的稳定性和准确性。

Highlights

  • 更新测试断言: 调整了 scanUsedIcons 的测试断言,以适应 REQUIRED_ICONS 默认注入 mdi-radiobox-blankmdi-radiobox-marked 的行为。
  • 修改空集测试: 将原有的“无图标时返回空集”测试更新为“至少包含两个 Radio 必需图标”的断言。
  • 新增去重测试: 增加了新的测试用例,验证当源码中已包含 mdi-radiobox-marked 时,必需图标不会重复加入。
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.

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

这个 PR 修复了 scanUsedIcons 的单元测试,使其与包含 REQUIRED_ICONS 的新逻辑保持一致。改动是正确的,并且新增了测试来验证去重逻辑。我有一个关于如何改进新增测试用例的建议,使其更简洁、更直接地利用 Set 数据结构的特性。

Comment on lines +122 to +125
const icons = [...scanUsedIcons(collectFiles(tmp, ['.vue']))];
assert.equal(icons.filter(icon => icon === 'mdi-radiobox-marked').length, 1);
assert.ok(icons.includes('mdi-radiobox-blank'));
assert.ok(icons.includes('mdi-home'));
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

这个测试用例的断言是正确的,但可以通过直接操作 scanUsedIcons 返回的 Set 对象来简化和增强。

Set 转换为数组并使用 filterincludes 来检查成员资格和唯一性,在语法上有些繁琐,而且效率低于直接使用 Sethas 方法和 size 属性。

建议直接在 Set 对象上进行断言,这样代码更简洁,也更能体现测试的意图——验证集合的内容和大小。

Suggested change
const icons = [...scanUsedIcons(collectFiles(tmp, ['.vue']))];
assert.equal(icons.filter(icon => icon === 'mdi-radiobox-marked').length, 1);
assert.ok(icons.includes('mdi-radiobox-blank'));
assert.ok(icons.includes('mdi-home'));
const icons = scanUsedIcons(collectFiles(tmp, ['.vue']));
assert.ok(icons.has('mdi-radiobox-marked'));
assert.ok(icons.has('mdi-radiobox-blank'));
assert.ok(icons.has('mdi-home'));
assert.equal(icons.size, 3);

@dosubot dosubot bot added the area:webui The bug / feature is about webui(dashboard) of astrbot. label Mar 24, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In the deduplication test you convert the Set to an array and use filter/includes; consider asserting via Set APIs and icons.size directly to better express the deduplication contract and avoid unnecessary transformations.
  • The three tests that create temporary directories each duplicate the makeTmpDir/writeFileSync/rmSync pattern; consider extracting a small helper or using try/finally around rmSync to reduce repetition and make cleanup more robust if an assertion fails.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the deduplication test you convert the Set to an array and use `filter`/`includes`; consider asserting via Set APIs and `icons.size` directly to better express the deduplication contract and avoid unnecessary transformations.
- The three tests that create temporary directories each duplicate the `makeTmpDir`/`writeFileSync`/`rmSync` pattern; consider extracting a small helper or using `try/finally` around `rmSync` to reduce repetition and make cleanup more robust if an assertion fails.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Soulter Soulter requested a review from RC-CHN March 24, 2026 09:14
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 24, 2026
@Soulter Soulter merged commit c6f4dd1 into AstrBotDevs:master Mar 24, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants