1 /*
2 SPDX-FileCopyrightText: 2015-2021 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5
6 */
7
8 #include "configurecustomsettingwidgettest.h"
9 #include "configurecustomsettingwidget.h"
10 #include <KLineEdit>
11 #include <QCheckBox>
12 #include <QComboBox>
13 #include <QLabel>
14 #include <QSignalSpy>
15 #include <QTest>
16
ConfigureCustomSettingWidgetTest(QObject * parent)17 ConfigureCustomSettingWidgetTest::ConfigureCustomSettingWidgetTest(QObject *parent)
18 : QObject(parent)
19 {
20 }
21
~ConfigureCustomSettingWidgetTest()22 ConfigureCustomSettingWidgetTest::~ConfigureCustomSettingWidgetTest()
23 {
24 }
25
shouldHaveDefaultValue()26 void ConfigureCustomSettingWidgetTest::shouldHaveDefaultValue()
27 {
28 ConfigureCustomSettingWidget w;
29 auto lab = w.findChild<QLabel *>(QStringLiteral("category_label"));
30 QVERIFY(lab);
31
32 auto categoryLineEdit = w.findChild<KLineEdit *>(QStringLiteral("category_lineedit"));
33 QVERIFY(categoryLineEdit);
34 QVERIFY(categoryLineEdit->trapReturnKey());
35 QVERIFY(categoryLineEdit->isClearButtonEnabled());
36
37 auto enableCategory = w.findChild<QCheckBox *>(QStringLiteral("enable_category"));
38 QVERIFY(enableCategory);
39
40 lab = w.findChild<QLabel *>(QStringLiteral("categorytype_label"));
41 QVERIFY(lab);
42 auto categoryType = w.findChild<QComboBox *>(QStringLiteral("categorytype_combobox"));
43 QVERIFY(categoryType);
44 QCOMPARE(categoryType->count(), 4);
45 }
46
shouldRestoreRules_data()47 void ConfigureCustomSettingWidgetTest::shouldRestoreRules_data()
48 {
49 QTest::addColumn<QString>("input");
50
51 QTest::newRow("empty") << QString();
52 QTest::newRow("validrule") << QStringLiteral("foo.warning=true");
53 QTest::newRow("validrule2") << QStringLiteral("foo=true");
54 QTest::newRow("validrule3") << QStringLiteral("foo=false");
55 QTest::newRow("validrule3*") << QStringLiteral("*.warning=false");
56 }
57
shouldRestoreRules()58 void ConfigureCustomSettingWidgetTest::shouldRestoreRules()
59 {
60 QFETCH(QString, input);
61 ConfigureCustomSettingWidget w;
62 w.setRule(input);
63 QCOMPARE(input, w.rule());
64 }
65
shouldEmitSignalWhenWeChangeLogName()66 void ConfigureCustomSettingWidgetTest::shouldEmitSignalWhenWeChangeLogName()
67 {
68 ConfigureCustomSettingWidget w;
69 auto categoryLineEdit = w.findChild<KLineEdit *>(QStringLiteral("category_lineedit"));
70 QVERIFY(categoryLineEdit);
71 QSignalSpy spy(&w, &ConfigureCustomSettingWidget::enableButton);
72 categoryLineEdit->setText(QStringLiteral("bla"));
73 QCOMPARE(spy.count(), 1);
74 QCOMPARE(spy.at(0).at(0).toBool(), true);
75 categoryLineEdit->clear();
76 QCOMPARE(spy.count(), 2);
77 QCOMPARE(spy.at(1).at(0).toBool(), false);
78
79 categoryLineEdit->setText(QStringLiteral(" "));
80 QCOMPARE(spy.count(), 3);
81 QCOMPARE(spy.at(2).at(0).toBool(), false);
82 }
83
84 QTEST_MAIN(ConfigureCustomSettingWidgetTest)
85