-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |