]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/dolphinsearchboxtest.cpp
56420e56e9f1fafe1b18954b3287360060623a3f
[dolphin.git] / src / tests / dolphinsearchboxtest.cpp
1 /*
2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "search/dolphinsearchbox.h"
8
9 #include <QStandardPaths>
10 #include <QTest>
11
12 class DolphinSearchBoxTest : public QObject
13 {
14 Q_OBJECT
15
16 private Q_SLOTS:
17 void initTestCase();
18 void init();
19 void cleanup();
20
21 void testTextClearing();
22
23 private:
24 DolphinSearchBox* m_searchBox;
25 };
26
27 void DolphinSearchBoxTest::initTestCase()
28 {
29 QStandardPaths::setTestModeEnabled(true);
30 }
31
32 void DolphinSearchBoxTest::init()
33 {
34 m_searchBox = new DolphinSearchBox();
35 }
36
37 void DolphinSearchBoxTest::cleanup()
38 {
39 delete m_searchBox;
40 }
41
42 /**
43 * The test verifies whether the automatic clearing of the text works correctly.
44 * The text may not get cleared when the searchbox gets visible or invisible,
45 * as this would clear the text when switching between tabs.
46 */
47 void DolphinSearchBoxTest::testTextClearing()
48 {
49 m_searchBox->show();
50 QVERIFY(m_searchBox->text().isEmpty());
51
52 m_searchBox->setText("xyz");
53 m_searchBox->hide();
54 m_searchBox->show();
55 QCOMPARE(m_searchBox->text(), QString("xyz"));
56
57 QTest::keyClick(m_searchBox, Qt::Key_Escape);
58 QVERIFY(m_searchBox->text().isEmpty());
59 }
60
61 QTEST_MAIN(DolphinSearchBoxTest)
62
63 #include "dolphinsearchboxtest.moc"