File indexing completed on 2024-12-15 04:44:00

0001 /*
0002   SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "akonadisearchdebugwidgettest.h"
0008 #include "../akonadisearchdebugsearchpathcombobox.h"
0009 #include "../akonadisearchdebugwidget.h"
0010 #include <KLineEdit>
0011 #include <QPlainTextEdit>
0012 #include <QPushButton>
0013 #include <QTest>
0014 
0015 AkonadiSearchDebugWidgetTest::AkonadiSearchDebugWidgetTest(QObject *parent)
0016     : QObject(parent)
0017 {
0018 }
0019 
0020 AkonadiSearchDebugWidgetTest::~AkonadiSearchDebugWidgetTest() = default;
0021 
0022 void AkonadiSearchDebugWidgetTest::shouldHaveDefaultValue()
0023 {
0024     Akonadi::Search::AkonadiSearchDebugWidget widget;
0025     auto button = widget.findChild<QPushButton *>(QStringLiteral("searchbutton"));
0026     QVERIFY(button);
0027     QVERIFY(!button->isEnabled());
0028     auto lineEdit = widget.findChild<KLineEdit *>(QStringLiteral("lineedit"));
0029     QVERIFY(lineEdit);
0030     QVERIFY(lineEdit->text().isEmpty());
0031     QVERIFY(lineEdit->trapReturnKey());
0032     QVERIFY(lineEdit->isClearButtonEnabled());
0033     auto editorWidget = widget.findChild<QPlainTextEdit *>(QStringLiteral("plaintexteditor"));
0034     QVERIFY(editorWidget->isReadOnly());
0035     QVERIFY(editorWidget);
0036     QVERIFY(editorWidget->toPlainText().isEmpty());
0037     auto searchCombo = widget.findChild<Akonadi::Search::AkonadiSearchDebugSearchPathComboBox *>(QStringLiteral("searchpathcombo"));
0038     QVERIFY(searchCombo);
0039 }
0040 
0041 void AkonadiSearchDebugWidgetTest::shouldFillLineEditWhenWeWantToSearchItem()
0042 {
0043     Akonadi::Search::AkonadiSearchDebugWidget widget;
0044     auto lineEdit = widget.findChild<KLineEdit *>(QStringLiteral("lineedit"));
0045     const int value = 42;
0046     const QString akonadiItem = QString::number(value);
0047     widget.setAkonadiId(value);
0048     QCOMPARE(lineEdit->text(), akonadiItem);
0049 }
0050 
0051 void AkonadiSearchDebugWidgetTest::shouldEnabledPushButtonWhenLineEditIsNotEmpty()
0052 {
0053     Akonadi::Search::AkonadiSearchDebugWidget widget;
0054     const int value = 42;
0055     widget.setAkonadiId(value);
0056     auto button = widget.findChild<QPushButton *>(QStringLiteral("searchbutton"));
0057     QVERIFY(button->isEnabled());
0058 
0059     auto lineEdit = widget.findChild<KLineEdit *>(QStringLiteral("lineedit"));
0060     lineEdit->setText(QString());
0061     QVERIFY(!button->isEnabled());
0062 
0063     // trimmed string
0064     lineEdit->setText(QStringLiteral(" "));
0065     QVERIFY(!button->isEnabled());
0066 }
0067 
0068 void AkonadiSearchDebugWidgetTest::shouldChangeSearchType()
0069 {
0070     Akonadi::Search::AkonadiSearchDebugWidget widget;
0071     Akonadi::Search::AkonadiSearchDebugSearchPathComboBox::SearchType type = Akonadi::Search::AkonadiSearchDebugSearchPathComboBox::Emails;
0072     widget.setSearchType(type);
0073     auto searchCombo = widget.findChild<Akonadi::Search::AkonadiSearchDebugSearchPathComboBox *>(QStringLiteral("searchpathcombo"));
0074     const QString path = searchCombo->pathFromEnum(type);
0075     QCOMPARE(searchCombo->searchPath(), path);
0076 }
0077 
0078 QTEST_MAIN(AkonadiSearchDebugWidgetTest)
0079 
0080 #include "moc_akonadisearchdebugwidgettest.cpp"