File indexing completed on 2024-12-15 04:54:35

0001 /*
0002   SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 #include "searchlinestatustest.h"
0008 #include "../src/core/widgets/searchlinestatus.h"
0009 #include <QCompleter>
0010 #include <QMenu>
0011 #include <QTest>
0012 
0013 SearchLineStatusTest::SearchLineStatusTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 SearchLineStatusTest::~SearchLineStatusTest() = default;
0019 
0020 void SearchLineStatusTest::shouldHaveDefaultValue()
0021 {
0022     MessageList::Core::SearchLineStatus w;
0023     QVERIFY(!w.containsOutboundMessages());
0024     QVERIFY(!w.locked());
0025     auto filterMenu = w.findChild<QMenu *>(QStringLiteral("filtermenu"));
0026     QVERIFY(filterMenu);
0027     QVERIFY(!filterMenu->actions().isEmpty());
0028 
0029     QVERIFY(w.completer());
0030     QVERIFY(w.completer()->model());
0031     QCOMPARE(w.completer()->model()->rowCount(), 0);
0032 
0033     // Verify if qt qlineedit name changed
0034     auto act = w.findChild<QAction *>(QStringLiteral("_q_qlineeditclearaction"));
0035     QVERIFY(act);
0036 }
0037 
0038 void SearchLineStatusTest::shouldAddCompletionItem()
0039 {
0040     MessageList::Core::SearchLineStatus w;
0041     w.addCompletionItem(QStringLiteral("ff"));
0042     QCOMPARE(w.completer()->model()->rowCount(), 1);
0043 
0044     // Don't add same element
0045     w.addCompletionItem(QStringLiteral("ff"));
0046     QCOMPARE(w.completer()->model()->rowCount(), 1);
0047 
0048     w.addCompletionItem(QStringLiteral("ffss"));
0049     QCOMPARE(w.completer()->model()->rowCount(), 2);
0050 }
0051 
0052 void SearchLineStatusTest::shouldClearCompleter()
0053 {
0054     MessageList::Core::SearchLineStatus w;
0055     for (int i = 0; i < 10; ++i) {
0056         w.addCompletionItem(QStringLiteral("ff%1").arg(i));
0057     }
0058     QCOMPARE(w.completer()->model()->rowCount(), 10);
0059     w.slotClearHistory();
0060     QCOMPARE(w.completer()->model()->rowCount(), 0);
0061 }
0062 
0063 QTEST_MAIN(SearchLineStatusTest)
0064 
0065 #include "moc_searchlinestatustest.cpp"