File indexing completed on 2025-01-26 04:57:23

0001 /*
0002    SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "findbarbasetest.h"
0008 #include "../findbarbase.h"
0009 
0010 #include <PimCommon/LineEditWithCompleterNg>
0011 #include <QLabel>
0012 #include <QPushButton>
0013 #include <QSignalSpy>
0014 #include <QTest>
0015 #include <QToolButton>
0016 
0017 FindBarBaseTest::FindBarBaseTest(QObject *parent)
0018     : QObject(parent)
0019 {
0020 }
0021 
0022 FindBarBaseTest::~FindBarBaseTest() = default;
0023 
0024 void FindBarBaseTest::shouldHaveDefaultValue()
0025 {
0026     WebEngineViewer::FindBarBase bar;
0027     auto status = bar.findChild<QLabel *>(QStringLiteral("status"));
0028     QVERIFY(status);
0029     QVERIFY(status->text().isEmpty());
0030 
0031     auto previous = bar.findChild<QPushButton *>(QStringLiteral("findprevious"));
0032     QVERIFY(previous);
0033     QVERIFY(!previous->isEnabled());
0034 
0035     auto next = bar.findChild<QPushButton *>(QStringLiteral("findnext"));
0036     QVERIFY(next);
0037     QVERIFY(!next->isEnabled());
0038 
0039     auto close = bar.findChild<QToolButton *>(QStringLiteral("close"));
0040     QVERIFY(close);
0041 
0042     auto lineedit = bar.findChild<PimCommon::LineEditWithCompleterNg *>(QStringLiteral("searchline"));
0043     QVERIFY(lineedit);
0044     QVERIFY(lineedit->text().isEmpty());
0045 }
0046 
0047 void FindBarBaseTest::shouldClearLineWhenClose()
0048 {
0049     WebEngineViewer::FindBarBase bar;
0050     bar.show();
0051     bar.activateWindow();
0052     QSignalSpy spy(&bar, &WebEngineViewer::FindBarBase::hideFindBar);
0053     QVERIFY(QTest::qWaitForWindowExposed(&bar));
0054     QVERIFY(bar.isVisible());
0055     bar.focusAndSetCursor();
0056     auto lineedit = bar.findChild<PimCommon::LineEditWithCompleterNg *>(QStringLiteral("searchline"));
0057     lineedit->setText(QStringLiteral("FOO"));
0058     QVERIFY(!lineedit->text().isEmpty());
0059     QVERIFY(lineedit->hasFocus());
0060     bar.closeBar();
0061     QVERIFY(lineedit->text().isEmpty());
0062     QVERIFY(!lineedit->hasFocus());
0063     QCOMPARE(spy.count(), 1);
0064 }
0065 
0066 void FindBarBaseTest::shouldEnableDisableNextPreviousButton()
0067 {
0068     WebEngineViewer::FindBarBase bar;
0069     bar.show();
0070     bar.activateWindow();
0071     QVERIFY(QTest::qWaitForWindowExposed(&bar));
0072     auto previous = bar.findChild<QPushButton *>(QStringLiteral("findprevious"));
0073 
0074     auto next = bar.findChild<QPushButton *>(QStringLiteral("findnext"));
0075 
0076     bar.autoSearch(QStringLiteral("FOO"));
0077     QVERIFY(next->isEnabled());
0078     QVERIFY(previous->isEnabled());
0079 
0080     bar.autoSearch(QString());
0081     QVERIFY(!next->isEnabled());
0082     QVERIFY(!previous->isEnabled());
0083 }
0084 
0085 void FindBarBaseTest::shouldClearAllWhenShowBar()
0086 {
0087     WebEngineViewer::FindBarBase bar;
0088     bar.show();
0089     QVERIFY(QTest::qWaitForWindowExposed(&bar));
0090     auto status = bar.findChild<QLabel *>(QStringLiteral("status"));
0091     status->setText(QStringLiteral("FOO"));
0092     bar.closeBar();
0093 
0094     bar.show();
0095     bar.focusAndSetCursor();
0096     auto lineedit = bar.findChild<PimCommon::LineEditWithCompleterNg *>(QStringLiteral("searchline"));
0097     QVERIFY(lineedit->hasFocus());
0098     QVERIFY(status->text().isEmpty());
0099 }
0100 
0101 QTEST_MAIN(FindBarBaseTest)
0102 
0103 #include "moc_findbarbasetest.cpp"