Skip to content

Commit

Permalink
feat: Add UT for DComboBox
Browse files Browse the repository at this point in the history
  Add UT.
  • Loading branch information
18202781743 committed Jul 28, 2023
1 parent 879a19c commit f556f22
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ set(WIDGET_TEST
testcases/widgets/ut_dwindowminbutton.cpp
testcases/widgets/ut_dwindowoptionbutton.cpp
testcases/widgets/ut_dwindowquitfullbutton.cpp
testcases/widgets/ut_dcombobox.cpp
)

include(${PROJECT_SOURCE_DIR}/src/util/util.cmake)
Expand Down
48 changes: 48 additions & 0 deletions tests/testcases/widgets/ut_dcombobox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <gtest/gtest.h>
#include <QTest>

#include "private/qcombobox_p.h"
#include "dcombobox.h"
DWIDGET_USE_NAMESPACE
class ut_DComboBox : public testing::Test
{
protected:
void SetUp() override
{
target = new DComboBox();
}
void TearDown() override
{
if (target)
delete target;
}
DComboBox *target = nullptr;
};

TEST_F(ut_DComboBox, maxVisibleItems)
{
// Add an additional item to display the arrow.
for (int i = 0; i < target->maxVisibleItems() + 1; i++) {
target->addItem(QString::number(i));
}
target->show();
QTest::qWaitForWindowExposed(target->windowHandle());

const QPoint arrowPos(target->rect().right() - 1, target->rect().center().y());
QTest::mouseClick(target, Qt::LeftButton, Qt::KeyboardModifiers(), arrowPos);

auto container = target->findChild<QComboBoxPrivateContainer *>();
ASSERT_TRUE(container);
const auto oldRect = container->rect();
target->hide();

target->addItem(QString("more"));
target->show();

QTest::mouseClick(target, Qt::LeftButton, Qt::KeyboardModifiers(), arrowPos);
ASSERT_EQ(container->rect().height(), oldRect.height());
}

0 comments on commit f556f22

Please sign in to comment.