File indexing completed on 2024-12-01 04:46:40
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "gravatarupdatewidgettest.h" 0008 #include "../gravatar/widgets/gravatarupdatewidget.h" 0009 #include <QCheckBox> 0010 #include <QLabel> 0011 #include <QPushButton> 0012 #include <QTest> 0013 GravatarUpdateWidgetTest::GravatarUpdateWidgetTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 GravatarUpdateWidgetTest::~GravatarUpdateWidgetTest() = default; 0019 0020 void GravatarUpdateWidgetTest::shouldHaveDefaultValue() 0021 { 0022 KABGravatar::GravatarUpdateWidget widget; 0023 widget.show(); 0024 auto lab = widget.findChild<QLabel *>(QStringLiteral("emaillabel")); 0025 QVERIFY(lab); 0026 0027 auto emaillabel = widget.findChild<QLabel *>(QStringLiteral("email")); 0028 QVERIFY(emaillabel); 0029 0030 auto useLibravatar = widget.findChild<QCheckBox *>(QStringLiteral("uselibravatar")); 0031 QVERIFY(useLibravatar); 0032 QVERIFY(!useLibravatar->isChecked()); 0033 QVERIFY(useLibravatar->isEnabled()); 0034 0035 auto useFallbackGravatar = widget.findChild<QCheckBox *>(QStringLiteral("fallbackgravatar")); 0036 QVERIFY(useFallbackGravatar); 0037 QVERIFY(!useFallbackGravatar->isChecked()); 0038 QVERIFY(!useFallbackGravatar->isEnabled()); 0039 0040 auto searchGravatar = widget.findChild<QPushButton *>(QStringLiteral("search")); 0041 QVERIFY(searchGravatar); 0042 QVERIFY(!searchGravatar->isEnabled()); 0043 0044 auto resultGravatar = widget.findChild<QLabel *>(QStringLiteral("result")); 0045 QVERIFY(resultGravatar); 0046 0047 QVERIFY(widget.pixmap().isNull()); 0048 QVERIFY(widget.resolvedUrl().isEmpty()); 0049 } 0050 0051 void GravatarUpdateWidgetTest::shouldAffectEmail() 0052 { 0053 KABGravatar::GravatarUpdateWidget widget; 0054 0055 auto emaillabel = widget.findChild<QLabel *>(QStringLiteral("email")); 0056 0057 auto searchGravatar = widget.findChild<QPushButton *>(QStringLiteral("search")); 0058 0059 const QString newEmail(QStringLiteral("foo@kde.org")); 0060 widget.setEmail(newEmail); 0061 0062 QCOMPARE(emaillabel->text(), newEmail); 0063 QVERIFY(searchGravatar->isEnabled()); 0064 0065 QString cleanName; 0066 widget.setEmail(cleanName); 0067 QCOMPARE(emaillabel->text(), cleanName); 0068 QVERIFY(!searchGravatar->isEnabled()); 0069 } 0070 0071 QTEST_MAIN(GravatarUpdateWidgetTest) 0072 0073 #include "moc_gravatarupdatewidgettest.cpp"