File indexing completed on 2024-11-24 04:43:08

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "externalcomposerconfigurewidgettest.h"
0008 #include "../externalcomposerconfigurewidget.h"
0009 #include <KUrlRequester>
0010 #include <QCheckBox>
0011 #include <QLabel>
0012 #include <QStandardPaths>
0013 #include <QTest>
0014 #include <QVBoxLayout>
0015 
0016 ExternalComposerConfigureWidgetTest::ExternalComposerConfigureWidgetTest(QObject *parent)
0017     : QObject(parent)
0018 {
0019     QStandardPaths::setTestModeEnabled(true);
0020 }
0021 
0022 void ExternalComposerConfigureWidgetTest::shouldHaveDefaultValues()
0023 {
0024     ExternalComposerConfigureWidget w(nullptr);
0025     auto vboxlayout = w.findChild<QVBoxLayout *>(QStringLiteral("mainlayout"));
0026     QVERIFY(vboxlayout);
0027     QCOMPARE(vboxlayout->contentsMargins(), QMargins());
0028 
0029     auto mExternalEditorCheck = w.findChild<QCheckBox *>(QStringLiteral("enabled"));
0030     QVERIFY(mExternalEditorCheck);
0031     QVERIFY(!mExternalEditorCheck->text().isEmpty());
0032     QVERIFY(!mExternalEditorCheck->isChecked());
0033 
0034     auto urlrequesterlabel = w.findChild<QLabel *>(QStringLiteral("urlrequesterlabel"));
0035     QVERIFY(urlrequesterlabel);
0036     QVERIFY(!urlrequesterlabel->text().isEmpty());
0037 
0038     auto explanationlabel = w.findChild<QLabel *>(QStringLiteral("explanationlabel"));
0039     QVERIFY(explanationlabel);
0040     QVERIFY(!explanationlabel->text().isEmpty());
0041     QVERIFY(!explanationlabel->isEnabled());
0042 
0043     auto mEditorRequester = w.findChild<KUrlRequester *>(QStringLiteral("mEditorRequester"));
0044     QVERIFY(mEditorRequester);
0045     QVERIFY(!mEditorRequester->isEnabled());
0046 }
0047 
0048 void ExternalComposerConfigureWidgetTest::shouldEnableDisableElements()
0049 {
0050     ExternalComposerConfigureWidget w(nullptr);
0051 
0052     auto mExternalEditorCheck = w.findChild<QCheckBox *>(QStringLiteral("enabled"));
0053     QVERIFY(mExternalEditorCheck);
0054     QVERIFY(!mExternalEditorCheck->isChecked());
0055 
0056     auto mEditorRequester = w.findChild<KUrlRequester *>(QStringLiteral("mEditorRequester"));
0057     QVERIFY(mEditorRequester);
0058     QVERIFY(!mEditorRequester->isEnabled());
0059 
0060     auto urlrequesterlabel = w.findChild<QLabel *>(QStringLiteral("urlrequesterlabel"));
0061     QVERIFY(urlrequesterlabel);
0062     QVERIFY(urlrequesterlabel->isEnabled());
0063 
0064     auto explanationlabel = w.findChild<QLabel *>(QStringLiteral("explanationlabel"));
0065     QVERIFY(!explanationlabel->isEnabled());
0066 
0067     mExternalEditorCheck->toggle();
0068     QVERIFY(mExternalEditorCheck->isChecked());
0069     QVERIFY(mEditorRequester->isEnabled());
0070     QVERIFY(urlrequesterlabel->isEnabled());
0071     QVERIFY(explanationlabel->isEnabled());
0072 
0073     mExternalEditorCheck->toggle();
0074     QVERIFY(!mExternalEditorCheck->isChecked());
0075     QVERIFY(!mEditorRequester->isEnabled());
0076     QVERIFY(urlrequesterlabel->isEnabled());
0077     QVERIFY(!explanationlabel->isEnabled());
0078 }
0079 
0080 QTEST_MAIN(ExternalComposerConfigureWidgetTest)
0081 
0082 #include "moc_externalcomposerconfigurewidgettest.cpp"