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 "sievescriptdebuggerdialogtest.h"
0008 #include "../sievescriptdebuggerdialog.h"
0009 #include "../sievescriptdebuggerfrontendwidget.h"
0010 #include "../sievescriptdebuggerwidget.h"
0011 #include <KUrlRequester>
0012 #include <QDialogButtonBox>
0013 #include <QPushButton>
0014 #include <QStandardPaths>
0015 #include <QTest>
0016 
0017 SieveScriptDebuggerDialogTest::SieveScriptDebuggerDialogTest(QObject *parent)
0018     : QObject(parent)
0019 {
0020     QStandardPaths::setTestModeEnabled(true);
0021 }
0022 
0023 SieveScriptDebuggerDialogTest::~SieveScriptDebuggerDialogTest() = default;
0024 
0025 void SieveScriptDebuggerDialogTest::shouldHaveDefaultValue()
0026 {
0027     KSieveUi::SieveScriptDebuggerDialog dlg;
0028     auto buttonBox = dlg.findChild<QDialogButtonBox *>(QStringLiteral("buttonbox"));
0029     QVERIFY(buttonBox);
0030 
0031     auto widget = dlg.findChild<KSieveUi::SieveScriptDebuggerWidget *>(QStringLiteral("sievescriptdebuggerwidget"));
0032     QVERIFY(widget);
0033 
0034     QVERIFY(dlg.script().isEmpty());
0035 
0036     auto mOkButton = dlg.findChild<QPushButton *>(QStringLiteral("okbutton"));
0037     QVERIFY(mOkButton);
0038     QVERIFY(!mOkButton->isEnabled());
0039 
0040     auto mDebugScriptButton = dlg.findChild<QPushButton *>(QStringLiteral("debug_button"));
0041     QVERIFY(mDebugScriptButton);
0042     QVERIFY(!mDebugScriptButton->isEnabled());
0043 }
0044 
0045 void SieveScriptDebuggerDialogTest::shouldChangeDebugButtonEnabledState()
0046 {
0047     KSieveUi::SieveScriptDebuggerDialog dlg;
0048     auto widget = dlg.findChild<KSieveUi::SieveScriptDebuggerWidget *>(QStringLiteral("sievescriptdebuggerwidget"));
0049 
0050     auto mSieveScriptFrontEnd = widget->findChild<KSieveUi::SieveScriptDebuggerFrontEndWidget *>(QStringLiteral("sievescriptfrontend"));
0051     QVERIFY(mSieveScriptFrontEnd);
0052 
0053     auto emailPath = mSieveScriptFrontEnd->findChild<KUrlRequester *>(QStringLiteral("emailpath"));
0054     QVERIFY(emailPath);
0055 
0056     auto mDebugScriptButton = dlg.findChild<QPushButton *>(QStringLiteral("debug_button"));
0057     QVERIFY(mDebugScriptButton);
0058     QVERIFY(!mDebugScriptButton->isEnabled());
0059 
0060     emailPath->setUrl(QUrl::fromLocalFile(QStringLiteral("/")));
0061     QVERIFY(!mDebugScriptButton->isEnabled());
0062 
0063     mSieveScriptFrontEnd->setScript(QStringLiteral("foo"));
0064     QVERIFY(mDebugScriptButton->isEnabled());
0065 
0066     emailPath->setUrl(QUrl::fromLocalFile(QStringLiteral("    ")));
0067     QVERIFY(!mDebugScriptButton->isEnabled());
0068 }
0069 
0070 QTEST_MAIN(SieveScriptDebuggerDialogTest)
0071 
0072 #include "moc_sievescriptdebuggerdialogtest.cpp"