File indexing completed on 2024-12-01 03:41:40

0001 /*
0002     SPDX-FileCopyrightText: 2011 Frank Reininghaus <frank78ac@googlemail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include <QTest>
0008 
0009 #include <klistwidgetsearchline.h>
0010 
0011 #include <QListWidget>
0012 
0013 class KListWidgetSearchLineTest : public QObject
0014 {
0015     Q_OBJECT
0016 
0017 private Q_SLOTS:
0018 
0019     void testAddItems();
0020 };
0021 
0022 /**
0023  * If items are added to the list view or modified, KListWidgetSearchLine
0024  * should hide them if they do not match the search string, see
0025  *
0026  * https://bugs.kde.org/show_bug.cgi?id=265709
0027  */
0028 
0029 void KListWidgetSearchLineTest::testAddItems()
0030 {
0031     QListWidget listWidget;
0032     listWidget.addItem(QStringLiteral("Matching test item"));
0033     listWidget.addItem(QStringLiteral("Another test item"));
0034 
0035     KListWidgetSearchLine searchLine(nullptr, &listWidget);
0036     searchLine.setText(QStringLiteral("match"));
0037 
0038     // The initial filtering is delayed; we have to wait
0039     while (!listWidget.item(1)->isHidden()) {
0040         QTest::qWait(50);
0041     }
0042 
0043     QVERIFY(!listWidget.item(0)->isHidden());
0044     QVERIFY(listWidget.item(1)->isHidden());
0045 
0046     // Add two items
0047     listWidget.addItem(QStringLiteral("Another item that matches the search pattern"));
0048     listWidget.addItem(QStringLiteral("This item should be hidden"));
0049 
0050     QVERIFY(!listWidget.item(0)->isHidden());
0051     QVERIFY(listWidget.item(1)->isHidden());
0052     QVERIFY(!listWidget.item(2)->isHidden());
0053     QVERIFY(listWidget.item(3)->isHidden());
0054 
0055     // Modify an item
0056     listWidget.item(3)->setText(QStringLiteral("Now this item matches"));
0057 
0058     QVERIFY(!listWidget.item(0)->isHidden());
0059     QVERIFY(listWidget.item(1)->isHidden());
0060     QVERIFY(!listWidget.item(2)->isHidden());
0061     QVERIFY(!listWidget.item(3)->isHidden());
0062 }
0063 
0064 QTEST_MAIN(KListWidgetSearchLineTest)
0065 
0066 #include "klistwidgetsearchlinetest.moc"