followupreminderselectdatedialogtest.cpp 3.83 KB
Newer Older
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
   SPDX-FileCopyrightText: 2014-2021 Laurent Montel <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3

4
   SPDX-License-Identifier: GPL-2.0-or-later
5
6
7
*/

#include "followupreminderselectdatedialogtest.h"
8
#include <MessageComposer/FollowUpReminderSelectDateDialog>
9
#include <AkonadiWidgets/CollectionComboBox>
Laurent Montel's avatar
Laurent Montel committed
10
11
12
#include <KDateComboBox>
#include <QLineEdit>
#include <QTest>
13

Laurent Montel's avatar
Laurent Montel committed
14
15
#include <AkonadiCore/EntityTreeModel>
#include <KCalendarCore/Todo>
16
#include <QLineEdit>
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <QPushButton>
#include <QStandardItemModel>

FollowupReminderSelectDateDialogTest::FollowupReminderSelectDateDialogTest(QObject *parent)
    : QObject(parent)
{
}

FollowupReminderSelectDateDialogTest::~FollowupReminderSelectDateDialogTest()
{
}

QStandardItemModel *FollowupReminderSelectDateDialogTest::defaultItemModel()
{
    QStandardItemModel *model = new QStandardItemModel;
    for (int id = 42; id < 51; ++id) {
        Akonadi::Collection collection(id);
        collection.setRights(Akonadi::Collection::AllRights);
        collection.setName(QString::number(id));
36
        collection.setContentMimeTypes(QStringList() << KCalendarCore::Todo::todoMimeType());
37
38

        QStandardItem *item = new QStandardItem(collection.name());
Laurent Montel's avatar
Laurent Montel committed
39
40
        item->setData(QVariant::fromValue(collection), Akonadi::EntityTreeModel::CollectionRole);
        item->setData(QVariant::fromValue(collection.id()), Akonadi::EntityTreeModel::CollectionIdRole);
41
42
43
44
45
46
47
48

        model->appendRow(item);
    }
    return model;
}

void FollowupReminderSelectDateDialogTest::shouldHaveDefaultValue()
{
Laurent Montel's avatar
Laurent Montel committed
49
    MessageComposer::FollowUpReminderSelectDateDialog dlg(nullptr, defaultItemModel());
50
51
52
53
54
55
    KDateComboBox *datecombobox = dlg.findChild<KDateComboBox *>(QStringLiteral("datecombobox"));
    QVERIFY(datecombobox);

    Akonadi::CollectionComboBox *combobox = dlg.findChild<Akonadi::CollectionComboBox *>(QStringLiteral("collectioncombobox"));
    QVERIFY(combobox);
    QDate currentDate = QDate::currentDate();
56
    QCOMPARE(datecombobox->date(), currentDate.addDays(1));
57
58
59
60
61
62
63
64

    QPushButton *okButton = dlg.findChild<QPushButton *>(QStringLiteral("ok_button"));
    QVERIFY(okButton);
    QVERIFY(okButton->isEnabled());
}

void FollowupReminderSelectDateDialogTest::shouldDisableOkButtonIfDateIsEmpty()
{
Laurent Montel's avatar
Laurent Montel committed
65
    MessageComposer::FollowUpReminderSelectDateDialog dlg(nullptr, defaultItemModel());
66
67
68
69
70
71
72
73
74
75
    KDateComboBox *datecombobox = dlg.findChild<KDateComboBox *>(QStringLiteral("datecombobox"));
    QVERIFY(datecombobox);
    QPushButton *okButton = dlg.findChild<QPushButton *>(QStringLiteral("ok_button"));
    QVERIFY(okButton->isEnabled());
    datecombobox->lineEdit()->clear();
    QVERIFY(!okButton->isEnabled());
}

void FollowupReminderSelectDateDialogTest::shouldDisableOkButtonIfDateIsNotValid()
{
Laurent Montel's avatar
Laurent Montel committed
76
    MessageComposer::FollowUpReminderSelectDateDialog dlg(nullptr, defaultItemModel());
77
78
79
80
81
82
83
84
85
86
87
88
    KDateComboBox *datecombobox = dlg.findChild<KDateComboBox *>(QStringLiteral("datecombobox"));
    QVERIFY(datecombobox);
    datecombobox->lineEdit()->setText(QStringLiteral(" "));
    QPushButton *okButton = dlg.findChild<QPushButton *>(QStringLiteral("ok_button"));
    QVERIFY(!okButton->isEnabled());
    const QDate date = QDate::currentDate();
    datecombobox->setDate(date);
    QVERIFY(okButton->isEnabled());
}

void FollowupReminderSelectDateDialogTest::shouldDisableOkButtonIfModelIsEmpty()
{
Laurent Montel's avatar
Laurent Montel committed
89
    MessageComposer::FollowUpReminderSelectDateDialog dlg(nullptr, new QStandardItemModel(nullptr));
90
91
92
93
94
95
96
97
98
99
100
101
102
    KDateComboBox *datecombobox = dlg.findChild<KDateComboBox *>(QStringLiteral("datecombobox"));
    QVERIFY(datecombobox);
    QPushButton *okButton = dlg.findChild<QPushButton *>(QStringLiteral("ok_button"));
    QVERIFY(!okButton->isEnabled());

    datecombobox->lineEdit()->setText(QStringLiteral(" "));
    QVERIFY(!okButton->isEnabled());
    const QDate date = QDate::currentDate();
    datecombobox->setDate(date);
    QVERIFY(!okButton->isEnabled());
}

QTEST_MAIN(FollowupReminderSelectDateDialogTest)