File indexing completed on 2025-03-09 04:53:54
0001 /* 0002 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "followupreminderselectdatedialogtest.h" 0008 #include <Akonadi/CollectionComboBox> 0009 #include <KDateComboBox> 0010 #include <MessageComposer/FollowUpReminderSelectDateDialog> 0011 #include <QLineEdit> 0012 #include <QTest> 0013 0014 #include <Akonadi/EntityTreeModel> 0015 #include <KCalendarCore/Todo> 0016 #include <QLineEdit> 0017 #include <QPushButton> 0018 #include <QStandardItemModel> 0019 0020 FollowupReminderSelectDateDialogTest::FollowupReminderSelectDateDialogTest(QObject *parent) 0021 : QObject(parent) 0022 { 0023 } 0024 0025 FollowupReminderSelectDateDialogTest::~FollowupReminderSelectDateDialogTest() = default; 0026 0027 QStandardItemModel *FollowupReminderSelectDateDialogTest::defaultItemModel() 0028 { 0029 auto model = new QStandardItemModel; 0030 for (int id = 42; id < 51; ++id) { 0031 Akonadi::Collection collection(id); 0032 collection.setRights(Akonadi::Collection::AllRights); 0033 collection.setName(QString::number(id)); 0034 collection.setContentMimeTypes(QStringList() << KCalendarCore::Todo::todoMimeType()); 0035 0036 auto item = new QStandardItem(collection.name()); 0037 item->setData(QVariant::fromValue(collection), Akonadi::EntityTreeModel::CollectionRole); 0038 item->setData(QVariant::fromValue(collection.id()), Akonadi::EntityTreeModel::CollectionIdRole); 0039 0040 model->appendRow(item); 0041 } 0042 return model; 0043 } 0044 0045 void FollowupReminderSelectDateDialogTest::shouldHaveDefaultValue() 0046 { 0047 auto model = defaultItemModel(); 0048 MessageComposer::FollowUpReminderSelectDateDialog dlg(nullptr, model); 0049 auto datecombobox = dlg.findChild<KDateComboBox *>(QStringLiteral("datecombobox")); 0050 QVERIFY(datecombobox); 0051 0052 auto combobox = dlg.findChild<Akonadi::CollectionComboBox *>(QStringLiteral("collectioncombobox")); 0053 QVERIFY(combobox); 0054 QDate currentDate = QDate::currentDate(); 0055 QCOMPARE(datecombobox->date(), currentDate.addDays(1)); 0056 0057 auto okButton = dlg.findChild<QPushButton *>(QStringLiteral("ok_button")); 0058 QVERIFY(okButton); 0059 QVERIFY(okButton->isEnabled()); 0060 delete model; 0061 } 0062 0063 void FollowupReminderSelectDateDialogTest::shouldDisableOkButtonIfDateIsEmpty() 0064 { 0065 auto model = defaultItemModel(); 0066 MessageComposer::FollowUpReminderSelectDateDialog dlg(nullptr, model); 0067 auto datecombobox = dlg.findChild<KDateComboBox *>(QStringLiteral("datecombobox")); 0068 QVERIFY(datecombobox); 0069 auto okButton = dlg.findChild<QPushButton *>(QStringLiteral("ok_button")); 0070 QVERIFY(okButton->isEnabled()); 0071 datecombobox->lineEdit()->clear(); 0072 QVERIFY(!okButton->isEnabled()); 0073 delete model; 0074 } 0075 0076 void FollowupReminderSelectDateDialogTest::shouldDisableOkButtonIfDateIsNotValid() 0077 { 0078 auto model = defaultItemModel(); 0079 MessageComposer::FollowUpReminderSelectDateDialog dlg(nullptr, model); 0080 auto datecombobox = dlg.findChild<KDateComboBox *>(QStringLiteral("datecombobox")); 0081 QVERIFY(datecombobox); 0082 datecombobox->lineEdit()->setText(QStringLiteral(" ")); 0083 auto okButton = dlg.findChild<QPushButton *>(QStringLiteral("ok_button")); 0084 QVERIFY(!okButton->isEnabled()); 0085 const QDate date = QDate::currentDate(); 0086 datecombobox->setDate(date); 0087 QVERIFY(okButton->isEnabled()); 0088 delete model; 0089 } 0090 0091 void FollowupReminderSelectDateDialogTest::shouldDisableOkButtonIfModelIsEmpty() 0092 { 0093 std::unique_ptr<QStandardItemModel> model(new QStandardItemModel(nullptr)); 0094 MessageComposer::FollowUpReminderSelectDateDialog dlg(nullptr, model.get()); 0095 auto datecombobox = dlg.findChild<KDateComboBox *>(QStringLiteral("datecombobox")); 0096 QVERIFY(datecombobox); 0097 auto okButton = dlg.findChild<QPushButton *>(QStringLiteral("ok_button")); 0098 QVERIFY(!okButton->isEnabled()); 0099 0100 datecombobox->lineEdit()->setText(QStringLiteral(" ")); 0101 QVERIFY(!okButton->isEnabled()); 0102 const QDate date = QDate::currentDate(); 0103 datecombobox->setDate(date); 0104 QVERIFY(!okButton->isEnabled()); 0105 } 0106 0107 QTEST_MAIN(FollowupReminderSelectDateDialogTest) 0108 0109 #include "moc_followupreminderselectdatedialogtest.cpp"