Skip to content

视图测试ID#9543

Merged
chenshuai2144 merged 1 commit intomasterfrom
cursor/id-9646
Mar 11, 2026
Merged

视图测试ID#9543
chenshuai2144 merged 1 commit intomasterfrom
cursor/id-9646

Conversation

@chenshuai2144
Copy link
Contributor

@chenshuai2144 chenshuai2144 commented Mar 11, 2026

为主要视图组件添加 data-testid 属性,以方便自动化测试。

此PR为 ProListProLayout 及其子组件、ProTablePageContainer 等核心视图组件增加了 data-testid 属性,便于在测试中通过 screen.getByTestId 等方法定位元素。

组件 data-testid
ProListContainer / ListView pro-list-view
ProLayout pro-layout
Header pro-layout-header
SiderMenu (侧边栏 / Drawer) pro-layout-sider
WrapContent (主内容区) pro-layout-content
Footer pro-layout-footer
GlobalHeader pro-layout-global-header
TopNavHeader pro-layout-top-nav-header
PageContainer pro-page-container
PageHeader pro-page-header
GridContent pro-grid-content
GlobalFooter pro-global-footer
ProTable pro-table
Open in Web Open in Cursor 

Summary by CodeRabbit

发布说明

  • 测试
    • 为布局、页面、表格和列表组件添加了测试标识符,增强了自动化测试的可选择性和可维护性。

@cursor
Copy link

cursor bot commented Mar 11, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d2815339-c034-416b-8ade-8fbe52bd6dbf

📥 Commits

Reviewing files that changed from the base of the PR and between 08b7c3f and e8d0e99.

📒 Files selected for processing (14)
  • src/layout/ProLayout.tsx
  • src/layout/WrapContent.tsx
  • src/layout/components/Footer.tsx
  • src/layout/components/GlobalFooter/index.tsx
  • src/layout/components/GlobalHeader/index.tsx
  • src/layout/components/GridContent/index.tsx
  • src/layout/components/Header/index.tsx
  • src/layout/components/PageContainer/index.tsx
  • src/layout/components/PageHeader/index.tsx
  • src/layout/components/SiderMenu/SiderMenu.tsx
  • src/layout/components/SiderMenu/index.tsx
  • src/layout/components/TopNavHeader/index.tsx
  • src/list/ProListBase.tsx
  • src/table/Table.tsx

📝 Walkthrough

走查

本次变更为布局、表格和列表组件添加 data-testid 属性,以增强测试可选择性。涉及13个文件,每个文件都添加了对应的测试标识符属性,无逻辑变更或API签名修改。

变更

组件分类 / 文件 变更摘要
布局主容器
src/layout/ProLayout.tsx, src/layout/WrapContent.tsx
为主布局和内容包装组件分别添加 data-testid="pro-layout"data-testid="pro-layout-content" 属性,扩展 WrapContent 的多行标签格式。
页面容器组件
src/layout/components/PageContainer/index.tsx, src/layout/components/PageHeader/index.tsx, src/layout/components/GridContent/index.tsx
分别为页面容器、页面头部和栅格内容组件添加 data-testid 属性,均以多行格式展开标签。
导航与菜单组件
src/layout/components/Header/index.tsx, src/layout/components/GlobalHeader/index.tsx, src/layout/components/TopNavHeader/index.tsx, src/layout/components/SiderMenu/*
为顶部头部、全局头部、导航头部及侧边栏菜单(含桌面和移动端)添加 data-testid 属性,标识分别对应各组件功能。
页脚组件
src/layout/components/Footer.tsx, src/layout/components/GlobalFooter/index.tsx
为默认页脚和全局页脚添加 data-testid="pro-layout-footer"data-testid="pro-global-footer" 属性。
数据展示组件
src/list/ProListBase.tsx, src/table/Table.tsx
分别为列表视图和表格根容器添加 data-testid="pro-list-view"data-testid="pro-table" 属性,无逻辑或行为变更。

估计代码审查工作量

🎯 2 (简单) | ⏱️ ~8 分钟

诗歌

🐰 测试之道添新标,
选择器成群现芳草,
布局表单列表捷,
无逻辑改,唯属性巧,
测试框架欢声笑。

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题「视图测试ID」准确总结了主要变更:为核心视图组件添加data-testid属性以支持自动化测试。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cursor/id-9646

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.

@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!

此拉取请求旨在通过向多个核心视图组件添加 data-testid 属性来显著增强项目的自动化测试能力。这些属性将允许测试工具更可靠、更高效地识别和交互 UI 元素,从而简化测试脚本的编写和维护,并提高测试的稳定性。这项改进对于确保应用程序的质量和可维护性至关重要。

Highlights

  • 自动化测试支持: 为 ProListProLayout 及其子组件、ProTablePageContainer 等核心视图组件添加了 data-testid 属性。
  • 元素定位: 通过引入 data-testid 属性,方便了在自动化测试中通过 screen.getByTestId 等方法精确地定位页面元素。
  • 组件覆盖: 此更改覆盖了多个关键布局和内容组件,包括 ProLayoutHeaderSiderMenuWrapContentFooterGlobalHeaderTopNavHeaderPageContainerPageHeaderGridContentGlobalFooterProListContainerProTable

🧠 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.

Changelog
  • src/layout/ProLayout.tsx
    • BaseProLayout 组件的根 div 元素上添加了 data-testid="pro-layout" 属性。
  • src/layout/WrapContent.tsx
    • Layout.Content 组件上添加了 data-testid="pro-layout-content" 属性,无论是否使用 ErrorBoundary
  • src/layout/components/Footer.tsx
    • DefaultFooter 组件的 Footer 元素上添加了 data-testid="pro-layout-footer" 属性。
  • src/layout/components/GlobalFooter/index.tsx
    • GlobalFooter 组件的根 div 元素上添加了 data-testid="pro-global-footer" 属性。
  • src/layout/components/GlobalHeader/index.tsx
    • GlobalHeader 组件的根 div 元素上添加了 data-testid="pro-layout-global-header" 属性。
  • src/layout/components/GridContent/index.tsx
    • GridContent 组件的根 div 元素上添加了 data-testid="pro-grid-content" 属性。
  • src/layout/components/Header/index.tsx
    • DefaultHeader 组件的 Header 元素上添加了 data-testid="pro-layout-header" 属性。
  • src/layout/components/PageContainer/index.tsx
    • PageContainerBase 组件的根 div 元素上添加了 data-testid="pro-page-container" 属性。
  • src/layout/components/PageHeader/index.tsx
    • PageHeader 组件的根 div 元素上添加了 data-testid="pro-page-header" 属性。
  • src/layout/components/SiderMenu/SiderMenu.tsx
    • SiderMenu 组件的 Sider 元素上添加了 data-testid="pro-layout-sider" 属性。
  • src/layout/components/SiderMenu/index.tsx
    • SiderMenuWrapper 组件的 Drawer 元素上添加了 data-testid="pro-layout-sider" 属性。
  • src/layout/components/TopNavHeader/index.tsx
    • TopNavHeader 组件的根 div 元素上添加了 data-testid="pro-layout-top-nav-header" 属性。
  • src/list/ProListBase.tsx
    • ProListContainerInner 组件的根 div 元素上添加了 data-testid="pro-list-view" 属性。
  • src/table/Table.tsx
    • ProTable 组件的根 div 元素上添加了 data-testid="pro-table" 属性。
Activity
  • 自创建以来,此拉取请求尚未有任何人工活动(例如评论或审查)。
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

此 PR 为多个核心视图组件添加了 data-testid 属性,以方便自动化测试。这是一个很好的改进,可以提高代码的可测试性。代码变更大部分是直接添加属性,实现正确。我只在 src/layout/WrapContent.tsx 中发现一处可以改进的地方,即通过提取重复的 Layout.Content 组件来提高代码的可维护性。

Comment on lines 28 to 45
return props.ErrorBoundary === false ? (
<Layout.Content className={contentClassName} style={style}>
<Layout.Content
className={contentClassName}
style={style}
data-testid="pro-layout-content"
>
{children}
</Layout.Content>
) : (
<ErrorComponent>
<Layout.Content className={contentClassName} style={style}>
<Layout.Content
className={contentClassName}
style={style}
data-testid="pro-layout-content"
>
{children}
</Layout.Content>
</ErrorComponent>
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

这部分代码存在重复。Layout.Content 组件在三元运算符的两个分支中都出现了。为了提高代码的可维护性并减少重复,建议将其提取到一个变量中。

  (() => {
    const contentNode = (
      <Layout.Content
        className={contentClassName}
        style={style}
        data-testid="pro-layout-content"
      >
        {children}
      </Layout.Content>
    );
    return props.ErrorBoundary === false ? (
      contentNode
    ) : (
      <ErrorComponent>{contentNode}</ErrorComponent>
    );
  })()

@chenshuai2144 chenshuai2144 marked this pull request as ready for review March 11, 2026 03:58
Copilot AI review requested due to automatic review settings March 11, 2026 03:58
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 11, 2026
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

该 PR 为核心视图组件补充稳定的 data-testid 属性,便于应用侧在自动化测试中使用 Testing Library(如 screen.getByTestId)定位关键结构节点。

Changes:

  • ProTableProList 根节点增加固定 data-testid
  • ProLayout 及其关键区域组件(Header/Sider/Content/Footer 等)增加固定 data-testid
  • PageContainerPageHeaderGridContentGlobalFooter/GlobalHeader 等增加固定 data-testid

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/table/Table.tsx 为 ProTable 根容器增加 data-testid="pro-table"
src/list/ProListBase.tsx 为 ProList 视图根节点增加 data-testid="pro-list-view"
src/layout/ProLayout.tsx 为 ProLayout 根节点增加 data-testid="pro-layout"
src/layout/WrapContent.tsx 为主内容区增加 data-testid="pro-layout-content"
src/layout/components/Header/index.tsx 为布局 Header 增加 data-testid="pro-layout-header"
src/layout/components/Footer.tsx 为布局 Footer 增加 data-testid="pro-layout-footer"
src/layout/components/GlobalHeader/index.tsx 为 GlobalHeader 增加 data-testid="pro-layout-global-header"
src/layout/components/TopNavHeader/index.tsx 为 TopNavHeader 增加 data-testid="pro-layout-top-nav-header"
src/layout/components/SiderMenu/index.tsx 为移动端 Drawer 侧边栏容器增加 data-testid="pro-layout-sider"
src/layout/components/SiderMenu/SiderMenu.tsx 为 Sider(侧边栏)增加 data-testid="pro-layout-sider"
src/layout/components/PageContainer/index.tsx 为 PageContainer 增加 data-testid="pro-page-container"
src/layout/components/PageHeader/index.tsx 为 PageHeader 增加 data-testid="pro-page-header"
src/layout/components/GridContent/index.tsx 为 GridContent 增加 data-testid="pro-grid-content"
src/layout/components/GlobalFooter/index.tsx 为 GlobalFooter 增加 data-testid="pro-global-footer"

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

<Drawer
placement={direction === 'rtl' ? 'right' : 'left'}
className={clsx(`${prefixCls}-drawer-sider`, className)}
data-testid="pro-layout-sider"
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

SiderMenu 在移动端渲染时这里给 Drawer 设置了 data-testid="pro-layout-sider",同时 Drawer 内部会渲染 SiderMenu 组件本身(其 Sider 也设置了相同的 data-testid)。这会导致页面上同时出现两个相同的 test id,screen.getByTestId('pro-layout-sider') 会因匹配到多个元素而报错。建议仅在移动端给 Drawer 设置该 test id(并在 Sider 上移除/条件禁用),或为 Drawer/Sider 使用不同的 id。

Suggested change
data-testid="pro-layout-sider"
data-testid="pro-layout-sider-drawer"

Copilot uses AI. Check for mistakes.
onCollapse?.(collapse);
}}
collapsedWidth={collapsedWidth}
data-testid="pro-layout-sider"
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

这里的 Sider 设置了 data-testid="pro-layout-sider",但在移动端该组件会被包在 SiderMenuWrapperDrawer 内部,而 Drawer 也设置了同样的 data-testid,从而产生重复的 test id。建议根据 isMobile 条件化该属性(例如仅在非移动端设置在 Sider 上),或与 Drawer 使用不同的 test id。

Suggested change
data-testid="pro-layout-sider"
data-testid={!isMobile ? 'pro-layout-sider' : undefined}

Copilot uses AI. Check for mistakes.
Comment on lines 1009 to 1016
<div
className={clsx(className, {
[`${defaultClassName}-polling`]: action.pollingLoading,
})}
style={style}
ref={counter.rootDomRef}
data-testid="pro-table"
>
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

此处新增 data-testid="pro-table" 是该 PR 的关键行为之一,但目前看不到对应的单测覆盖(例如渲染 ProTable 后断言根节点存在该 test id)。建议在现有 tests/table/* 中补一条回归测试,避免后续重构/包装 DOM 时意外移除该属性。

Copilot uses AI. Check for mistakes.
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Free Tier Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Duplicate data-testid on sider in mobile mode
    • Removed the duplicate data-testid from the mobile Drawer so only the inner Sider exposes pro-layout-sider in all modes.

Create PR

Or push these changes by commenting:

@cursor push 8f941c9825
Preview (8f941c9825)
diff --git a/src/layout/components/SiderMenu/index.tsx b/src/layout/components/SiderMenu/index.tsx
--- a/src/layout/components/SiderMenu/index.tsx
+++ b/src/layout/components/SiderMenu/index.tsx
@@ -52,7 +52,6 @@
       <Drawer
         placement={direction === 'rtl' ? 'right' : 'left'}
         className={clsx(`${prefixCls}-drawer-sider`, className)}
-        data-testid="pro-layout-sider"
         open={!collapsed}
         afterOpenChange={(open) => {
           if (!open) {

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

@chenshuai2144 chenshuai2144 merged commit ee5976d into master Mar 11, 2026
15 of 17 checks passed
@chenshuai2144 chenshuai2144 deleted the cursor/id-9646 branch March 11, 2026 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants