File indexing completed on 2025-02-23 05:24:03

0001 /*
0002     SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 
0006 */
0007 
0008 #include "configurecustomsettingwidgettest.h"
0009 #include "configurecustomsettingwidget.h"
0010 #include <KLineEdit>
0011 #include <QCheckBox>
0012 #include <QComboBox>
0013 #include <QLabel>
0014 #include <QSignalSpy>
0015 #include <QTest>
0016 
0017 ConfigureCustomSettingWidgetTest::ConfigureCustomSettingWidgetTest(QObject *parent)
0018     : QObject(parent)
0019 {
0020 }
0021 
0022 ConfigureCustomSettingWidgetTest::~ConfigureCustomSettingWidgetTest() = default;
0023 
0024 void ConfigureCustomSettingWidgetTest::shouldHaveDefaultValue()
0025 {
0026     ConfigureCustomSettingWidget w;
0027     auto lab = w.findChild<QLabel *>(QStringLiteral("category_label"));
0028     QVERIFY(lab);
0029 
0030     auto categoryLineEdit = w.findChild<KLineEdit *>(QStringLiteral("category_lineedit"));
0031     QVERIFY(categoryLineEdit);
0032     QVERIFY(categoryLineEdit->trapReturnKey());
0033     QVERIFY(categoryLineEdit->isClearButtonEnabled());
0034 
0035     auto enableCategory = w.findChild<QCheckBox *>(QStringLiteral("enable_category"));
0036     QVERIFY(enableCategory);
0037 
0038     lab = w.findChild<QLabel *>(QStringLiteral("categorytype_label"));
0039     QVERIFY(lab);
0040     auto categoryType = w.findChild<QComboBox *>(QStringLiteral("categorytype_combobox"));
0041     QVERIFY(categoryType);
0042     QCOMPARE(categoryType->count(), 4);
0043 }
0044 
0045 void ConfigureCustomSettingWidgetTest::shouldRestoreRules_data()
0046 {
0047     QTest::addColumn<QString>("input");
0048 
0049     QTest::newRow("empty") << QString();
0050     QTest::newRow("validrule") << QStringLiteral("foo.warning=true");
0051     QTest::newRow("validrule2") << QStringLiteral("foo=true");
0052     QTest::newRow("validrule3") << QStringLiteral("foo=false");
0053     QTest::newRow("validrule3*") << QStringLiteral("*.warning=false");
0054 }
0055 
0056 void ConfigureCustomSettingWidgetTest::shouldRestoreRules()
0057 {
0058     QFETCH(QString, input);
0059     ConfigureCustomSettingWidget w;
0060     w.setRule(input);
0061     QCOMPARE(input, w.rule());
0062 }
0063 
0064 void ConfigureCustomSettingWidgetTest::shouldEmitSignalWhenWeChangeLogName()
0065 {
0066     ConfigureCustomSettingWidget w;
0067     auto categoryLineEdit = w.findChild<KLineEdit *>(QStringLiteral("category_lineedit"));
0068     QVERIFY(categoryLineEdit);
0069     QSignalSpy spy(&w, &ConfigureCustomSettingWidget::enableButton);
0070     categoryLineEdit->setText(QStringLiteral("bla"));
0071     QCOMPARE(spy.count(), 1);
0072     QCOMPARE(spy.at(0).at(0).toBool(), true);
0073     categoryLineEdit->clear();
0074     QCOMPARE(spy.count(), 2);
0075     QCOMPARE(spy.at(1).at(0).toBool(), false);
0076 
0077     categoryLineEdit->setText(QStringLiteral(" "));
0078     QCOMPARE(spy.count(), 3);
0079     QCOMPARE(spy.at(2).at(0).toBool(), false);
0080 }
0081 
0082 QTEST_MAIN(ConfigureCustomSettingWidgetTest)
0083 
0084 #include "moc_configurecustomsettingwidgettest.cpp"