Skip to content

Conversation

@re2zero
Copy link
Contributor

@re2zero re2zero commented Dec 4, 2025

All tests follow the Google Test framework and verify proper initialization, method execution, and error handling for the property dialog plugin components.

Log: add comprehensive unit tests for property dialog.

Summary by Sourcery

Expand automated test coverage for the property dialog plugin and trash core components, including dialogs, widgets, menu scenes, global enums, and event calls, to better validate construction, basic behavior, and error-handling paths.

Tests:

  • Add comprehensive unit tests for FilePropertyDialog, BasicWidget, PermissionManagerWidget, MultiFilePropertyDialog, ComputerPropertyDialog threading, and related UI/event methods in the property dialog plugin.
  • Introduce new tests for EditStackedWidget and NameTextEdit interactions, including focus, key handling, and text updates.
  • Add tests for property dialog global enums, meta-object registrations, static constants, and metatype declarations.
  • Add tests for PropertyMenuScene and PropertyMenuCreator behavior, including initialization, menu creation, and triggering paths.
  • Extend TrashFileInfo tests to cover additional initTarget branches, name/time/path accessors, and null-internal-state handling.
  • Extend TrashCore tests to cover followEvents, start branch behavior, and registration of custom property dialogs.

All tests follow the Google Test framework and verify proper initialization, method execution, and error handling for the property dialog plugin components.

Log: add comprehensive unit tests for property dialog.
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 4, 2025

Reviewer's Guide

Adds comprehensive Google Test-based unit tests for the dfmplugin-propertydialog plugin (dialogs, widgets, menu scene, events, and global enums) and extends trashcore plugin tests (TrashFileInfo and TrashCore) to cover previously untested branches and edge cases.

File-Level Changes

Change Details Files
Expand property dialog plugin unit tests to cover dialogs, widgets, threads, and permission handling behavior.
  • Add many new tests in the existing property dialog test file to exercise FilePropertyDialog, PermissionManagerWidget, ComputerPropertyDialog, ComputerInfoThread, and BasicWidget constructors, destructors, public methods, and event handlers, largely focusing on non-crashing behavior and basic return-value expectations.
  • Introduce additional Qt includes and dfm-base includes required by the new tests, such as event types, widgets, and FileInfo-related helpers.
autotests/plugins/dfmplugin-propertydialog/test_propertydialog.cpp
Add focused unit tests for EditStackedWidget and its NameTextEdit helper to verify editing, selection, and mouse-processing behavior.
  • Create a new gtest fixture for EditStackedWidget-related tests, including construction/destruction and simple interactions like initTextShowFrame, selectFile, showTextShowFrame, and mouseProcess.
  • Test NameTextEdit behavior including cancellation flag toggling, plain-text changes, text-changed slot, focus-out handling, and key-press handling for Escape/Enter/Return.
autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp
Introduce tests for the property dialog plugin global types, enums, meta-object registration, and metatypes.
  • Verify numeric values of PropertyFilterType, BasicFieldExpandEnum, BasicExpandType, and ComputerInfoItem enums to detect unintended changes.
  • Check Q_ENUM_NS registration via the static meta-object and ensure enumerators are discoverable at runtime.
  • Validate that key string constants used as option keys have expected literal values and that declared metatypes (CustomViewExtensionView, BasicViewFieldFunc, ViewIntiCallback) are registered.
autotests/plugins/dfmplugin-propertydialog/test_propertydialog_global.cpp
Add unit tests for the property menu scene implementation and its factory to verify construction, naming, and basic API behavior.
  • Test PropertyMenuCreator::create and ::name, ensuring it produces a scene instance and the expected name string.
  • Exercise PropertyMenuScene and PropertyMenuScenePrivate construction, name(), initialize() with empty params, scene(), create(), updateState(), and triggered() to verify default behaviors and non-crashing code paths.
autotests/plugins/dfmplugin-propertydialog/test_propertymenuscene.cpp
Add unit tests for the MultiFilePropertyDialog to validate construction and folder-size UI update logic.
  • Construct MultiFilePropertyDialog with multiple URLs and test destruction to ensure no leaks or crashes.
  • Call updateFolderSizeLabel with sample size/count values to ensure it executes without throwing.
autotests/plugins/dfmplugin-propertydialog/test_multifilepropertydialog.cpp
Add unit tests for PropertyEventCall static helpers and their metatype usage.
  • Test PropertyEventCall::sendSetPermissionManager and ::sendFileHide with sample window IDs, URLs, and permissions to ensure they can be invoked safely.
  • Verify that QFileDevice::Permissions is registered as a metatype by querying its meta-type ID.
autotests/plugins/dfmplugin-propertydialog/test_propertyeventcall.cpp
Extend TrashFileInfo unit tests to cover initTarget branch logic, name/time/path query variants, and robustness when internal DFileInfo is null.
  • Stub DFMIO::DFileInfo::attribute to simulate valid and empty target URIs and test TrashFileInfo construction paths that exercise initTarget, including ancestor URL resolution via UrlRoute::urlParent and TrashCoreHelper::rootUrl.
  • Add tests that call nameOf for different FileNameInfoType variants, timeOf for multiple FileTimeType values, and pathOf for sym-link targets, ensuring they execute without exceptions even when dFileInfo is effectively null or stubbed.
autotests/plugins/dfmplugin-trashcore/test_trashfileinfo.cpp
Expand TrashCore plugin tests to exercise additional public methods and start/followEvents/regCustomPropertyDialog behavior.
  • Add a test that calls TrashCore::followEvents to ensure it is callable and does not throw.
  • Add simple tests invoking TrashCore::start (including a dedicated case mentioning property-dialog-related behavior) and regCustomPropertyDialog, asserting non-throwing behavior and successful start where applicable.
autotests/plugins/dfmplugin-trashcore/test_trashcore.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

我来对这次代码变更进行详细审查:

  1. .gitignore变更:
  • 添加了新的忽略规则:.serena/、.kiro/、.promptx/、.qoder/、.qoderignore
  • 这些看起来是IDE或开发工具相关的目录,添加到.gitignore是合理的
  1. 新增测试文件:
    a) test_editstackedwidget.cpp:
  • 代码结构清晰,测试用例覆盖全面
  • 建议改进:
    • 添加对边界条件的测试,如空字符串、超长字符串等
    • 增加对异常输入的测试用例
    • 在NameTextEditKeyPressEvent测试中,可以添加对其他按键的测试

b) test_multifilepropertydialog.cpp:

  • 测试覆盖了基本功能
  • 建议改进:
    • 添加对空URL列表的测试
    • 增加对无效URL的测试
    • 添加对大文件列表的性能测试

c) test_propertydialog.cpp:

  • 测试用例非常全面,覆盖了多个类
  • 建议改进:
    • 部分被注释的测试用例(如FilePropertyDialogContentHeightTest)应该取消注释并完善
    • 添加对权限变更的边界条件测试
    • 增加对多媒体文件的具体测试

d) test_propertydialog_global.cpp:

  • 枚举值测试完整
  • 建议改进:
    • 可以添加对枚举值边界情况的测试
    • 增加对元对象注册失败情况的测试

e) test_propertyeventcall.cpp:

  • 基本功能测试完整
  • 建议改进:
    • 添加对无效权限组合的测试
    • 增加对权限变更失败情况的测试

f) test_propertymenuscene.cpp:

  • 测试覆盖了主要功能
  • 建议改进:
    • 添加对菜单项动态创建的测试
    • 增加对菜单项状态变化的测试
    • 补充对菜单项触发事件的测试
  1. 对现有测试文件的增强:
    a) test_trashcore.cpp:
  • 新增的测试用例合理
  • 建议改进:
    • 可以添加对插件依赖关系的测试
    • 增加对异常情况的处理测试

b) test_trashfileinfo.cpp:

  • 新增测试用例覆盖了更多边界情况
  • 建议改进:
    • 可以添加对并发访问的测试
    • 增加对文件系统错误的测试
    • 补充对特殊字符文件名的测试

总体评价:

  1. 代码质量:
  • 代码结构清晰,命名规范
  • 测试用例组织合理
  • 使用了合适的测试框架和工具
  1. 性能考虑:
  • 建议添加性能测试用例,特别是对大文件和大量文件的处理
  • 可以考虑添加内存使用情况的测试
  1. 安全性:
  • 建议增加对恶意输入的测试
  • 添加对权限提升尝试的测试
  • 补充对文件系统操作安全的测试
  1. 改进建议:
  • 增加更多的集成测试
  • 添加对错误恢复机制的测试
  • 考虑添加对UI响应性的测试
  • 增加对多语言支持的测试
  1. 其他建议:
  • 考虑添加测试文档,说明每个测试用例的目的
  • 可以增加测试覆盖率报告
  • 考虑添加自动化性能基准测试

这些变更整体上是积极的,提高了代码的测试覆盖率,但还可以进一步完善测试用例,特别是边界条件和异常情况的处理。

Copy link

@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 there - I've reviewed your changes - here's some feedback:

  • Several tests (e.g., PermissionManagerWidgetCanChmodTest) use assertions like EXPECT_TRUE(canChmod || !canChmod), which are effectively no-ops; consider replacing these with more meaningful expectations or simply EXPECT_NO_THROW around the call if you only want to validate it doesn’t crash.
  • Many tests construct URLs pointing to hard-coded paths such as /tmp/test.txt; to avoid environment-dependent behavior and potential flakiness, consider using QTemporaryFile/QDir::tempPath() or local test fixtures instead of fixed absolute paths.
  • There are multiple commented-out test bodies (e.g., FilePropertyDialogContentHeightTest, FilePropertyDialogMousePressEventTest, EditStackedWidget::renameFile path) left in the suite; consider either fixing and enabling these tests or removing the commented code to keep the test files clean and focused.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Several tests (e.g., PermissionManagerWidgetCanChmodTest) use assertions like `EXPECT_TRUE(canChmod || !canChmod)`, which are effectively no-ops; consider replacing these with more meaningful expectations or simply `EXPECT_NO_THROW` around the call if you only want to validate it doesn’t crash.
- Many tests construct URLs pointing to hard-coded paths such as `/tmp/test.txt`; to avoid environment-dependent behavior and potential flakiness, consider using `QTemporaryFile`/`QDir::tempPath()` or local test fixtures instead of fixed absolute paths.
- There are multiple commented-out test bodies (e.g., FilePropertyDialogContentHeightTest, FilePropertyDialogMousePressEventTest, EditStackedWidget::renameFile path) left in the suite; consider either fixing and enabling these tests or removing the commented code to keep the test files clean and focused.

## Individual Comments

### Comment 1
<location> `autotests/plugins/dfmplugin-propertydialog/test_propertydialog.cpp:404-408` </location>
<code_context>
+    EXPECT_NO_THROW(delete dialog);
+}
+
+// TEST_F(TestPropertyDialog, FilePropertyDialogContentHeightTest)
+// {
+//     FilePropertyDialog dialog;
+//     int height = dialog.contentHeight();
+//     EXPECT_GE(height, 0);
+// }
+
</code_context>

<issue_to_address>
**suggestion (testing):** Commented‑out tests should be either fixed or removed to avoid dead code and confusion about intended coverage.

Given the commented‑out tests (e.g. `FilePropertyDialogContentHeightTest`, `FilePropertyDialogMousePressEventTest`, and the rename/mouse tests in `EditStackedWidget`), please either make them reliable (e.g. via `QSignalSpy`, proper event loop handling, or stubs) or remove them and record the missing coverage in a ticket. Keeping them commented out obscures which behaviors are actually tested.

Suggested implementation:

```cpp
TEST_F(TestPropertyDialog, FilePropertyDialogDestructorTest)
{
    FilePropertyDialog *dialog = new FilePropertyDialog();
    EXPECT_NO_THROW(delete dialog);
}

#include "dfmplugin_propertydialog_global.h"

```

```cpp

```

The snippet you provided only shows one commented-out test (`FilePropertyDialogContentHeightTest`). Your review comment also mentions other commented-out tests (`FilePropertyDialogMousePressEventTest`, and rename/mouse tests in `EditStackedWidget`) that are not visible in this excerpt.

To fully implement your suggestion and avoid dead code:
1. Locate each of those commented-out tests in `autotests/plugins/dfmplugin-propertydialog/test_propertydialog.cpp`.
2. For each one, either:
   - Remove the commented-out test block entirely (as done above), and create an external ticket documenting the missing coverage, or
   - Re-enable and fix the test (e.g. by:
     * Using `QSignalSpy` to wait for expected signals instead of manual sleeps,
     * Ensuring the dialog/widget is shown and an event loop is running (`QTest::qWaitForWindowExposed`, `QCoreApplication::processEvents`),
     * Using `QTest::mouseClick` / `QTest::mouseMove` / `QTest::keyClick` to drive interactions).
3. Ensure no `// TEST_F(...` or similarly commented-out test macros remain in the file so that the active test suite clearly represents current coverage.

If you share the rest of the file, I can provide concrete SEARCH/REPLACE blocks for each of the other commented-out tests as well.
</issue_to_address>

### Comment 2
<location> `autotests/plugins/dfmplugin-propertydialog/test_propertydialog.cpp:514-519` </location>
<code_context>
+    EXPECT_NO_THROW(widget.toggleFileExecutable(false));
+}
+
+TEST_F(TestPropertyDialog, PermissionManagerWidgetCanChmodTest)
+{
+    PermissionManagerWidget widget;
+    FileInfoPointer info = DFMBASE_NAMESPACE::InfoFactory::create<DFMBASE_NAMESPACE::FileInfo>(QUrl::fromLocalFile("/tmp/test"));
+    bool canChmod = widget.canChmod(info);
+    EXPECT_TRUE(canChmod || !canChmod); // Just test it doesn't crash
+}
+
</code_context>

<issue_to_address>
**issue (testing):** The assertion `EXPECT_TRUE(canChmod || !canChmod)` is a tautology and doesn’t provide any behavioral checking.

This is effectively just calling `widget.canChmod(info);` and discarding the result. If you only want to assert it doesn’t crash, `EXPECT_NO_THROW(widget.canChmod(info));` is clearer. Ideally, if you can control `FileInfoPointer` via stubs, add tests that expect both `true` and `false` under specific permission/ownership conditions to capture the intended behavior.
</issue_to_address>

### Comment 3
<location> `autotests/plugins/dfmplugin-trashcore/test_trashfileinfo.cpp:454-461` </location>
<code_context>
+    });
+}
+
+// 新增测试用例:测试 fileName 方法中 dFileInfo 为空的情况
+TEST_F(TrashFileInfoTest, FileName_WithNullDFileInfo)
+{
+    QUrl url("trash:///test.txt");
+    TrashFileInfo info(url);
+
+    // Mock dFileInfo to be null (this is difficult to achieve in practice, but we can test the method)
+    EXPECT_NO_THROW(info.nameOf(DFMBASE_NAMESPACE::FileInfo::FileNameInfoType::kFileName));
+}
+
</code_context>

<issue_to_address>
**issue (testing):** The test claims to cover the `dFileInfo == nullptr` case, but the internal state is not actually forced to null.

The test currently just constructs `TrashFileInfo info(url);` and calls `nameOf(...)`, without actually forcing `dFileInfo` to `nullptr`. Depending on the constructor, `dFileInfo` may still be valid, so the null edge case isn’t really exercised. To test this accurately, you’d need a way to ensure `dFileInfo` is null (e.g., via a stubbed factory/internal initializer or a dedicated injection point). As written, the test name/comment overstate what’s covered.
</issue_to_address>

### Comment 4
<location> `autotests/plugins/dfmplugin-trashcore/test_trashfileinfo.cpp:391-400` </location>
<code_context>
+    QUrl url("trash:///test.txt");
+    TrashFileInfo info(url);
+
+    // Mock DFileInfo::attribute to return a valid target URI
+    stub.set_lamda(&DFMIO::DFileInfo::attribute, [](DFMIO::DFileInfo *self, DFMIO::DFileInfo::AttributeID id, bool *outSuccess) -> QVariant {
+        Q_UNUSED(self);
+        if (id == DFMIO::DFileInfo::AttributeID::kStandardTargetUri) {
+            if (outSuccess) *outSuccess = true;
+            return QVariant::fromValue<QUrl>(QUrl("file:///home/user/test.txt"));
+        }
+        if (outSuccess) *outSuccess = false;
+        return QVariant();
+    });
+
+    // 确保不会抛出异常
+    EXPECT_NO_THROW({
+        // 注意:我们无法直接调用私有的 initTarget 方法,但可以通过构造函数间接测试
+        TrashFileInfo info2(url);
+    });
+}
</code_context>

<issue_to_address>
**suggestion (testing):** For the `initTarget` branch tests, you stub `attribute` but never assert on the resulting target state.

These tests currently only verify that constructing `TrashFileInfo info2(url);` doesn’t throw, so they don’t confirm the new `initTarget` branches actually ran or produced the correct state. Please add assertions that validate the resolved target URL/path and any flags or state `initTarget()` is supposed to set (or some observable derived from those, like `pathOf(...)`/`nameOf(...)`), rather than relying solely on crash‑free execution.

Suggested implementation:

```cpp
 // 新增测试用例:测试 initTarget 方法中的未覆盖分支
TEST_F(TrashFileInfoTest, InitTarget_WithValidTargetUri)
{
    QUrl url("trash:///test.txt");
    QUrl expectedTargetUrl("file:///home/user/test.txt");

    // 先构造 TrashFileInfo 对象,确保 initTarget 在构造过程中被调用
    TrashFileInfo info(url);

    // Mock DFileInfo::attribute to return a valid target URI
    stub.set_lamda(&DFMIO::DFileInfo::attribute,
                   [](DFMIO::DFileInfo *self,
                      DFMIO::DFileInfo::AttributeID id,
                      bool *outSuccess) -> QVariant {
        Q_UNUSED(self);
        if (id == DFMIO::DFileInfo::AttributeID::kStandardTargetUri) {
            if (outSuccess) {
                *outSuccess = true;
            }
            return QVariant::fromValue<QUrl>(QUrl("file:///home/user/test.txt"));
        }
        if (outSuccess) {
            *outSuccess = false;
        }
        return QVariant();
    });

    // 确保不会抛出异常,并验证 initTarget 解析出的目标信息是否正确
    EXPECT_NO_THROW({
        // 注意:我们无法直接调用私有的 initTarget 方法,但可以通过构造函数间接测试
        TrashFileInfo info2(url);

        // 验证 initTarget 解析出的目标 URL 是否与 stub 返回的一致
        EXPECT_EQ(info2.targetUrl(), expectedTargetUrl);

        // 如果 TrashFileInfo 暴露了用于获取目标路径 / 文件名的接口,这里也一并验证
        EXPECT_EQ(info2.targetUrl().toLocalFile(), QStringLiteral("/home/user/test.txt"));
    });
}

```

The snippet above assumes that:
1. `TrashFileInfo` exposes a `targetUrl()` accessor that reflects the state set by `initTarget()`.
2. `targetUrl().toLocalFile()` is a valid way to obtain the resolved file system path.

If your actual API differs, you should adjust the assertions accordingly, for example:
- Replace `info2.targetUrl()` with whatever accessor is used to expose the resolved target (e.g. `info2.resolvedUrl()`, `info2.targetFileInfo().url()`, etc.).
- If there are dedicated helpers like `pathOf(...)` / `nameOf(...)` or specific flags that `initTarget()` is supposed to set, add `EXPECT_*` checks on those instead of (or in addition to) the `targetUrl()` assertions.
- If `TrashFileInfo` does not provide direct access to the URL but exposes only a path, adapt the `EXPECT_EQ` to compare that path with `"/home/user/test.txt"` (or the appropriate representation) instead.
</issue_to_address>

### Comment 5
<location> `autotests/plugins/dfmplugin-trashcore/test_trashcore.cpp:65-52` </location>
<code_context>
+}
+
+// 新增测试用例:测试 start 方法中的不同分支路径
+TEST_F(TrashCoreTest, Start_WithPropertyDialogPlugin)
+{
+    TrashCore plugin;
+    
+    // 目前只测试基本的 start 方法
+    EXPECT_TRUE(plugin.start());
+}
+
</code_context>

<issue_to_address>
**suggestion (testing):** `Start_WithPropertyDialogPlugin` doesn’t currently differentiate from `Start_Basic` or assert the property‑dialog‑plugin specific behavior.

This test currently mirrors `Start_Basic`, so it doesn’t validate any plugin-specific behavior. If `start()` branches based on a property dialog plugin being registered, please stub/mock the relevant registry/factory so you can: (1) simulate the plugin’s presence and assert the expected registration/callback, and (2) optionally cover the absence case. If there’s no such branch yet, consider renaming the test to reflect its current scope instead of implying plugin-specific behavior.

Suggested implementation:

```cpp
 // 新增测试用例:测试 start 方法:未注册属性对话框插件时的基础启动路径
TEST_F(TrashCoreTest, Start_NoPropertyDialogPlugin)
{
    TrashCore plugin;

    // 当前测试仅覆盖未注册属性对话框插件时的基础启动路径
    EXPECT_TRUE(plugin.start());
}

// 新增测试用例:测试 followEvents 方法
TEST_F(TrashCoreTest, FollowEvents_Basic)
{
    TrashCore plugin;

    // 只需确保方法不抛出异常
    EXPECT_NO_THROW(plugin.followEvents());
}

```

If `TrashCore::start()` later gains branching logic based on a property-dialog plugin registry/factory, you can extend `Start_NoPropertyDialogPlugin` and add a `Start_WithPropertyDialogPlugin` test by:
1. Stubbing/mocking the registry or factory in `TrashCoreTest` to simulate a registered property-dialog plugin.
2. Asserting that the expected registration/callback specific to that plugin is invoked (e.g., via mock expectations or state changes).
3. Optionally adding a test to cover the “plugin absent” case explicitly if behavior diverges from the default path.
</issue_to_address>

### Comment 6
<location> `autotests/plugins/dfmplugin-propertydialog/test_propertymenuscene.cpp:74-80` </location>
<code_context>
+    EXPECT_EQ(name, "PropertyMenu");
+}
+
+TEST_F(TestPropertyMenuScene, PropertyMenuSceneInitialize)
+{
+    PropertyMenuScene scene;
+    QVariantHash params;
+    // Test with empty params
+    bool result = scene.initialize(params);
+    EXPECT_FALSE(result); // Should fail with empty params
+}
+
</code_context>

<issue_to_address>
**suggestion (testing):** PropertyMenuScene is only tested for failure paths; a successful initialize/create/trigger flow isn’t covered.

Right now we only assert that `initialize` fails with empty params and that `create`/`triggered` don’t succeed in invalid scenarios. To exercise the intended behavior, please add at least one positive test that:
- builds a realistic `QVariantHash` for `initialize` and asserts it returns `true`,
- calls `create(&menu)` and confirms the expected property actions are added,
- invokes `triggered` on a known action and checks it returns `true` or produces the expected side effect.
This will ensure the success path is covered, not just error handling.

Suggested implementation:

```cpp
TEST_F(TestPropertyMenuScene, PropertyMenuSceneName)
{
    PropertyMenuScene scene;
    QString name = scene.name();
    EXPECT_EQ(name, "PropertyMenu");
}

TEST_F(TestPropertyMenuScene, PropertyMenuSceneInitializeCreateTriggerSuccess)
{
    PropertyMenuScene scene;

    // Build a realistic parameter set for a successful initialization.
    QVariantHash params;
    params.insert(QStringLiteral("url"), QUrl::fromLocalFile(QStringLiteral("/tmp")));

    bool initResult = scene.initialize(params);
    EXPECT_TRUE(initResult);

    // After successful initialization, create should populate the menu.
    QMenu menu;
    bool createResult = scene.create(&menu);
    EXPECT_TRUE(createResult);
    ASSERT_FALSE(menu.actions().isEmpty());

    // Trigger a known action from the created menu and verify the success path.
    QAction *action = menu.actions().first();
    ASSERT_NE(action, nullptr);

    bool triggerResult = scene.triggered(action);
    EXPECT_TRUE(triggerResult);
}

```

The positive-flow test assumes:
1. `initialize` succeeds when given a `QVariantHash` containing a `"url"` key with a `QUrl` value. If `PropertyMenuScene` expects different or additional keys (e.g. `"windowId"`, `"selectUrls"`, etc.), update the `params.insert(...)` calls accordingly so that `initialize` returns `true`.
2. `create(&menu)` returns `true` and populates `menu.actions()` when initialization was successful. If the contract is slightly different (e.g. it always returns `true` but may leave the menu empty for some parameter sets), tighten the expectations to match the actual behavior (for example, assert a specific action count or specific action text).
3. `triggered(action)` returns `true` for at least one of the actions added by `create`. If the function instead reports success via side effects (signals, state changes) rather than the return value, replace the `EXPECT_TRUE(triggerResult);` check with assertions on those side effects (e.g. checking a mock, a spy, or scene-internal state exposed for testing).
You may also want to choose a more specific action than `menu.actions().first()` (e.g. by matching on `action->text()` or `objectName()`) once you know which property action should be present for the given parameters.
</issue_to_address>

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.

@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs, re2zero

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Johnson-zs
Copy link
Contributor

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 4, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit b3ed727 into linuxdeepin:master Dec 4, 2025
19 of 21 checks passed
@re2zero re2zero deleted the unitest branch December 4, 2025 13:14
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.

3 participants