-
Notifications
You must be signed in to change notification settings - Fork 180
test: add comprehensive unit tests for property dialog plugin #3322
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
Conversation
Added complete test coverage for the dfmplugin-propertydialog module including: - PropertyDialog plugin lifecycle tests - PropertyEventReceiver event handling tests - PropertyDialogManager view registration and creation tests - PropertyDialogUtil dialog management tests - ComputerPropertyHelper and MediaInfoFetchWorker utility tests - PropertyMenuScene menu integration tests Tests cover core functionality like dialog creation, view extensions, custom views, basic field filters, and event handling with proper stubbing and mocking. Updated .gitignore to include .spec-workflow/ directory for AI workflow configurations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deepin pr auto review我来对这段代码进行审查,主要从以下几个方面进行分析:
具体改进建议:
class TestPropertyDialog : public testing::Test {
protected:
void SetUp() override {
tempDir.reset(new QTemporaryDir());
ASSERT_TRUE(tempDir->isValid());
stub.clear();
propertyDialog.stop();
}
void TearDown() override {
propertyDialog.stop();
stub.clear();
tempDir.reset();
}
QScopedPointer<QTemporaryDir> tempDir;
stub_ext::StubExt stub;
static PropertyDialog propertyDialog;
};
TEST_F(TestPropertyDialog, HandleShowPropertyDialogWithEmptyUrls)
{
PropertyEventReceiver receiver;
QList<QUrl> urls; // Empty URL list
QVariantHash option;
EXPECT_NO_THROW(receiver.handleShowPropertyDialog(urls, option));
}
TEST_F(TestPropertyDialog, HandleShowPropertyDialogWithInvalidUrls)
{
PropertyEventReceiver receiver;
QList<QUrl> urls;
urls << QUrl("invalid://url");
QVariantHash option;
EXPECT_NO_THROW(receiver.handleShowPropertyDialog(urls, option));
}
TEST_F(TestPropertyDialog, CreateExtensionViewTest)
{
PropertyDialogManager &manager = PropertyDialogManager::instance();
auto mockView = [](const QUrl &url) -> QWidget* {
return new QWidget();
};
manager.registerExtensionView(mockView, "test_name", 0);
QUrl url = QUrl::fromLocalFile(tempDir->path());
auto result = manager.createExtensionView(url);
EXPECT_FALSE(result.isEmpty());
// Use QScopedPointer for automatic cleanup
for (QWidget *widget : result) {
QScopedPointer<QWidget> guard(widget);
}
}
TEST_F(TestPropertyDialog, HandleShowPropertyDialogWithError)
{
PropertyEventReceiver receiver;
// Mock error condition
stub.set_lamda(&PropertyDialogUtil::showPropertyDialog,
[](PropertyDialogUtil *self, const QList<QUrl> &urls, const QVariantHash &option) {
throw std::runtime_error("Test error");
});
QList<QUrl> urls;
urls << QUrl::fromLocalFile(tempDir->path());
QVariantHash option;
EXPECT_THROW(receiver.handleShowPropertyDialog(urls, option), std::runtime_error);
}
class TestPropertyDialog : public testing::Test {
protected:
void setupMockView() {
mockView = [](const QUrl &url) -> QWidget* {
return new QWidget();
};
}
void cleanupWidget(QWidget* widget) {
if (widget) {
widget->deleteLater();
}
}
std::function<QWidget*(const QUrl&)> mockView;
};这些改进建议可以提高代码的健壮性、可维护性和测试覆盖率。 |
|
Note
详情{
"autotests/plugins/dfmplugin-propertydialog/test_propertydialogmanager.cpp": [
{
"line": " QWidget *result2 = manager.createCustomView(QUrl(\"ftp://example.com/test\"));",
"line_number": 200,
"rule": "S35",
"reason": "Url link | 20432f5d9e"
},
{
"line": " QUrl ftpUrl(\"ftp://example.com/test\");",
"line_number": 290,
"rule": "S35",
"reason": "Url link | 20432f5d9e"
}
]
} |
|
[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 |
|
/forcemerge |
|
This pr force merged! (status: behind) |
Added complete test coverage for the dfmplugin-propertydialog module including:
Tests cover core functionality like dialog creation, view extensions, custom views, basic field filters, and event handling with proper stubbing and mocking.
Updated .gitignore to include .spec-workflow/ directory for AI workflow configurations.