File indexing completed on 2024-12-29 04:54:49

0001 /*
0002    SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "sievescriptdebuggerfrontendwidgettest.h"
0008 #include "../sievescriptdebuggerfrontendwidget.h"
0009 #ifdef HAVE_KTEXTADDONS_TEXT_TO_SPEECH_SUPPORT
0010 #include <TextEditTextToSpeech/TextToSpeechContainerWidget>
0011 #endif
0012 #include "sievescriptdebugger/sievescriptdebuggerwarning.h"
0013 #include <KUrlRequester>
0014 #include <QLabel>
0015 #include <QLineEdit>
0016 #include <QSplitter>
0017 #include <QTest>
0018 
0019 SieveScriptDebuggerFrontEndWidgetTest::SieveScriptDebuggerFrontEndWidgetTest(QObject *parent)
0020     : QObject(parent)
0021 {
0022 }
0023 
0024 SieveScriptDebuggerFrontEndWidgetTest::~SieveScriptDebuggerFrontEndWidgetTest() = default;
0025 
0026 void SieveScriptDebuggerFrontEndWidgetTest::shouldHaveDefaultValue()
0027 {
0028     KSieveUi::SieveScriptDebuggerFrontEndWidget w;
0029     QVERIFY(w.script().isEmpty());
0030 
0031     auto splitter = w.findChild<QSplitter *>(QStringLiteral("splitter"));
0032     QVERIFY(splitter);
0033     QCOMPARE(splitter->count(), 2);
0034 
0035     auto warning = w.findChild<KSieveUi::SieveScriptDebuggerWarning *>(QStringLiteral("sievescriptdebuggerwarning"));
0036     QVERIFY(warning);
0037 
0038     auto emailLab = w.findChild<QLabel *>(QStringLiteral("emaillab"));
0039     QVERIFY(emailLab);
0040 
0041     auto emailPath = w.findChild<KUrlRequester *>(QStringLiteral("emailpath"));
0042     QVERIFY(emailPath);
0043 
0044     auto extensionLab = w.findChild<QLabel *>(QStringLiteral("extensionlab"));
0045     QVERIFY(extensionLab);
0046 
0047     auto extension = w.findChild<QLineEdit *>(QStringLiteral("extension"));
0048     QVERIFY(extension);
0049     QVERIFY(extension->text().isEmpty());
0050     QVERIFY(extension->isClearButtonEnabled());
0051 #ifdef HAVE_KTEXTADDONS_TEXT_TO_SPEECH_SUPPORT
0052     auto textToSpeechWidget = w.findChild<TextEditTextToSpeech::TextToSpeechContainerWidget *>(QStringLiteral("texttospeechwidget"));
0053     QVERIFY(textToSpeechWidget);
0054 #endif
0055 }
0056 
0057 void SieveScriptDebuggerFrontEndWidgetTest::shouldChangeButtonEnabledState()
0058 {
0059     KSieveUi::SieveScriptDebuggerFrontEndWidget w;
0060     QVERIFY(w.script().isEmpty());
0061 
0062     auto emailPath = w.findChild<KUrlRequester *>(QStringLiteral("emailpath"));
0063     emailPath->setUrl(QUrl::fromLocalFile(QStringLiteral("/")));
0064     //    QPushButton *debugScriptButton = w.findChild<QPushButton *>(QStringLiteral("debugbutton"));
0065 
0066     //    QVERIFY(!debugScriptButton->isEnabled());
0067 
0068     //    w.setScript(QStringLiteral("foo"));
0069     //    QVERIFY(debugScriptButton->isEnabled());
0070 
0071     //    emailPath->setUrl(QUrl::fromLocalFile(QStringLiteral("    ")));
0072     //    QVERIFY(!debugScriptButton->isEnabled());
0073 }
0074 
0075 void SieveScriptDebuggerFrontEndWidgetTest::shouldAddScript()
0076 {
0077     KSieveUi::SieveScriptDebuggerFrontEndWidget w;
0078     const QString script = QStringLiteral("foo foo \n bla bla");
0079     w.setScript(script);
0080     QCOMPARE(w.script(), script);
0081 }
0082 
0083 void SieveScriptDebuggerFrontEndWidgetTest::shouldNotAccept()
0084 {
0085     KSieveUi::SieveScriptDebuggerFrontEndWidget w;
0086     w.show();
0087     w.setScript(QStringLiteral("debug_log"));
0088     auto warning = w.findChild<KSieveUi::SieveScriptDebuggerWarning *>(QStringLiteral("sievescriptdebuggerwarning"));
0089 
0090     QVERIFY(!w.canAccept());
0091     QVERIFY(warning->isVisible());
0092     w.setScript(QStringLiteral("foo foo \n bla bla"));
0093     QVERIFY(w.canAccept());
0094     QVERIFY(!warning->isVisible());
0095 
0096     w.setScript(QStringLiteral("require \"vnd.dovecot.debug\""));
0097     QVERIFY(!w.canAccept());
0098     QVERIFY(warning->isVisible());
0099 }
0100 
0101 QTEST_MAIN(SieveScriptDebuggerFrontEndWidgetTest)
0102 
0103 #include "moc_sievescriptdebuggerfrontendwidgettest.cpp"