File indexing completed on 2024-04-28 05:45:19
0001 /* 0002 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "search/dolphinsearchbox.h" 0008 0009 #include <QStandardPaths> 0010 #include <QTest> 0011 0012 class DolphinSearchBoxTest : public QObject 0013 { 0014 Q_OBJECT 0015 0016 private Q_SLOTS: 0017 void initTestCase(); 0018 void init(); 0019 void cleanup(); 0020 0021 void testTextClearing(); 0022 0023 private: 0024 DolphinSearchBox *m_searchBox; 0025 }; 0026 0027 void DolphinSearchBoxTest::initTestCase() 0028 { 0029 QStandardPaths::setTestModeEnabled(true); 0030 } 0031 0032 void DolphinSearchBoxTest::init() 0033 { 0034 m_searchBox = new DolphinSearchBox(); 0035 } 0036 0037 void DolphinSearchBoxTest::cleanup() 0038 { 0039 delete m_searchBox; 0040 } 0041 0042 /** 0043 * The test verifies whether the automatic clearing of the text works correctly. 0044 * The text may not get cleared when the searchbox gets visible or invisible, 0045 * as this would clear the text when switching between tabs. 0046 */ 0047 void DolphinSearchBoxTest::testTextClearing() 0048 { 0049 m_searchBox->show(); 0050 QVERIFY(m_searchBox->text().isEmpty()); 0051 0052 m_searchBox->setText("xyz"); 0053 m_searchBox->hide(); 0054 m_searchBox->show(); 0055 QCOMPARE(m_searchBox->text(), QString("xyz")); 0056 0057 QTest::keyClick(m_searchBox, Qt::Key_Escape); 0058 QVERIFY(m_searchBox->text().isEmpty()); 0059 } 0060 0061 QTEST_MAIN(DolphinSearchBoxTest) 0062 0063 #include "dolphinsearchboxtest.moc"