File indexing completed on 2025-01-19 04:46:48
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "delegateselectortest.h" 0008 #include "../calendar/delegateselector.h" 0009 #include <PimCommonAkonadi/AddresseeLineEdit> 0010 #include <QCheckBox> 0011 #include <QDialogButtonBox> 0012 #include <QLabel> 0013 #include <QPushButton> 0014 #include <QTest> 0015 0016 DelegateSelectorTest::DelegateSelectorTest(QObject *parent) 0017 : QObject(parent) 0018 { 0019 } 0020 0021 DelegateSelectorTest::~DelegateSelectorTest() = default; 0022 0023 void DelegateSelectorTest::shouldHaveDefaultValue() 0024 { 0025 DelegateSelector w; 0026 auto label = w.findChild<QLabel *>(QStringLiteral("label")); 0027 QVERIFY(label); 0028 QVERIFY(!label->text().isEmpty()); 0029 0030 auto mDelegate = w.findChild<PimCommon::AddresseeLineEdit *>(QStringLiteral("delegate")); 0031 QVERIFY(mDelegate); 0032 QVERIFY(mDelegate->text().isEmpty()); 0033 0034 auto mRsvp = w.findChild<QCheckBox *>(QStringLiteral("informcheckbox")); 0035 QVERIFY(mRsvp); 0036 QVERIFY(mRsvp->isChecked()); 0037 QVERIFY(!mRsvp->text().isEmpty()); 0038 0039 auto buttonBox = w.findChild<QDialogButtonBox *>(QStringLiteral("buttonbox")); 0040 QVERIFY(buttonBox); 0041 0042 QPushButton *mOkButton = buttonBox->button(QDialogButtonBox::Ok); 0043 QVERIFY(mOkButton); 0044 QVERIFY(!mOkButton->isEnabled()); 0045 } 0046 0047 void DelegateSelectorTest::shouldChangeOkButtonState() 0048 { 0049 DelegateSelector w; 0050 auto mDelegate = w.findChild<PimCommon::AddresseeLineEdit *>(QStringLiteral("delegate")); 0051 mDelegate->setEnableAkonadiSearch(false); 0052 mDelegate->setEnableBalooSearch(false); 0053 0054 auto buttonBox = w.findChild<QDialogButtonBox *>(QStringLiteral("buttonbox")); 0055 QPushButton *mOkButton = buttonBox->button(QDialogButtonBox::Ok); 0056 QVERIFY(!mOkButton->isEnabled()); 0057 0058 mDelegate->setText(QStringLiteral("foo")); 0059 QVERIFY(mOkButton->isEnabled()); 0060 0061 mDelegate->clear(); 0062 QVERIFY(!mOkButton->isEnabled()); 0063 mDelegate->setText(QStringLiteral(" ")); 0064 QVERIFY(!mOkButton->isEnabled()); 0065 } 0066 0067 void DelegateSelectorTest::shouldReturnCheckBoxState() 0068 { 0069 DelegateSelector w; 0070 auto mRsvp = w.findChild<QCheckBox *>(QStringLiteral("informcheckbox")); 0071 QVERIFY(mRsvp->isChecked()); 0072 mRsvp->setChecked(true); 0073 QVERIFY(w.rsvp()); 0074 0075 mRsvp->setChecked(false); 0076 QVERIFY(!w.rsvp()); 0077 } 0078 0079 QTEST_MAIN(DelegateSelectorTest) 0080 0081 #include "moc_delegateselectortest.cpp"