Commit 070ccf33 authored by Glen Ditchfield's avatar Glen Ditchfield 🐛 Committed by Glen Ditchfield
Browse files

Test initialization and display of todo datetime GUI elements

parent 2363225a
Pipeline #166604 passed with stage
in 1 minute and 57 seconds
/*
SPDX-FileCopyrightText: 2020 Glen Ditchfield <GJDitchfield@acm.org>
SPDX-FileCopyrightText: 2020, 2022 Glen Ditchfield <GJDitchfield@acm.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
......@@ -18,86 +18,194 @@ class IncidenceDateTimeTest : public QObject
{
Q_OBJECT
IncidenceDialog *mDialog;
QCheckBox *mAllDay;
QCheckBox *mStartCheck;
QCheckBox *mEndCheck;
KDateComboBox *mStartDate;
KTimeComboBox *mStartTime;
KTimeZoneComboBox *mStartZone;
KDateComboBox *mEndDate;
KTimeComboBox *mEndTime;
KTimeZoneComboBox *mEndZone;
public:
IncidenceDateTimeTest()
{
mDialog = new IncidenceDialog();
mAllDay = mDialog->findChild<QCheckBox *>(QStringLiteral("mWholeDayCheck"));
QVERIFY2(mAllDay, "Couldn't find the 'All Day' checkbox.");
mStartCheck = mDialog->findChild<QCheckBox *>(QStringLiteral("mStartCheck"));
QVERIFY2(mStartCheck, "Couldn't find the 'Start' checkbox.");
mEndCheck = mDialog->findChild<QCheckBox *>(QStringLiteral("mEndCheck"));
QVERIFY2(mEndCheck, "Couldn't find the 'End' checkbox.");
mStartDate = mDialog->findChild<KDateComboBox *>(QStringLiteral("mStartDateEdit"));
QVERIFY2(mStartDate, "Couldn't find start date field.");
mStartTime = mDialog->findChild<KTimeComboBox *>(QStringLiteral("mStartTimeEdit"));
QVERIFY2(mStartTime, "Couldn't find start time field.");
mStartZone = mDialog->findChild<KTimeZoneComboBox *>(QStringLiteral("mTimeZoneComboStart"));
QVERIFY2(mStartZone, "Couldn't find start time zone field.");
mEndDate = mDialog->findChild<KDateComboBox *>(QStringLiteral("mEndDateEdit"));
QVERIFY2(mEndDate, "Couldn't find end date field.");
mEndTime = mDialog->findChild<KTimeComboBox *>(QStringLiteral("mEndTimeEdit"));
QVERIFY2(mEndTime, "Couldn't find end time field.");
mEndZone = mDialog->findChild<KTimeZoneComboBox *>(QStringLiteral("mTimeZoneComboEnd"));
QVERIFY2(mEndZone, "Couldn't find end time zone field.");
}
private Q_SLOTS:
void initTestCase()
{
qputenv("TZ", "Asia/Tokyo");
}
void testStartTimeValidation()
{
QLocale currentLocale;
QLocale::setDefault(QLocale::c());
Akonadi::Item item;
KCalendarCore::Event::Ptr event(new KCalendarCore::Event);
item.setPayload<KCalendarCore::Event::Ptr>(event);
auto dialog = new IncidenceDialog();
dialog->load(item);
const QDate date {2022, 04, 01};
const QTime time {00, 00, 00};
const QTimeZone zone {"Etc/UTC"};
const QDateTime dt {date, time, zone};
// Put the dialog into a known, valid state.
auto editor = dialog->findChild<IncidenceEditor *>();
KCalendarCore::Event::Ptr event(new KCalendarCore::Event);
event->setSummary(QStringLiteral("e"));
event->setDtStart(dt);
event->setDtEnd(dt);
event->setAllDay(false);
Akonadi::Item item;
item.setPayload<KCalendarCore::Event::Ptr>(event);
mDialog->load(item);
auto editor = mDialog->findChild<IncidenceEditor *>();
QVERIFY2(editor, "Couldn't find the combined editor.");
QCOMPARE(editor->metaObject()->className(), "IncidenceEditorNG::CombinedIncidenceEditor");
auto allDay = dialog->findChild<QCheckBox *>(QStringLiteral("mWholeDayCheck"));
QVERIFY2(allDay, "Couldn't find the 'All Day' checkbox.");
allDay->setCheckState(Qt::Unchecked);
auto startCheck = dialog->findChild<QCheckBox *>(QStringLiteral("mStartCheck"));
QVERIFY2(startCheck, "Couldn't find the 'Start' checkbox.");
startCheck->setCheckState(Qt::Checked);
auto endCheck = dialog->findChild<QCheckBox *>(QStringLiteral("mEndCheck"));
QVERIFY2(endCheck, "Couldn't find the 'End' checkbox.");
endCheck->setCheckState(Qt::Checked);
auto summary = dialog->findChild<QLineEdit *>(QStringLiteral("mSummaryEdit"));
QVERIFY2(summary, "Couldn't find the 'Summary' field.");
summary->setText(QStringLiteral("e"));
QVERIFY(editor->isValid());
auto startDate = dialog->findChild<KDateComboBox *>(QStringLiteral("mStartDateEdit"));
QVERIFY2(startDate, "Couldn't find start date field.");
startDate->setCurrentText(QStringLiteral("32 Jan 2000"));
mStartDate->setCurrentText(QStringLiteral("32 Jan 2000"));
QVERIFY2(!editor->isValid(), "Didn't detect invalid start date.");
startDate->setCurrentText(QStringLiteral("12 Jan 2000"));
mStartDate->setCurrentText(QStringLiteral("12 Jan 2000"));
QVERIFY(editor->isValid());
auto startTime = dialog->findChild<KTimeComboBox *>(QStringLiteral("mStartTimeEdit"));
QVERIFY2(startTime, "Couldn't find start time field.");
startTime->setCurrentText(QStringLiteral("12:99:00"));
mStartTime->setCurrentText(QStringLiteral("12:99:00"));
QVERIFY2(!editor->isValid(), "Didn't detect invalid start time.");
startTime->setCurrentText(QStringLiteral("12:00:00"));
mStartTime->setCurrentText(QStringLiteral("12:00:00"));
QVERIFY(editor->isValid());
auto endDate = dialog->findChild<KDateComboBox *>(QStringLiteral("mEndDateEdit"));
QVERIFY2(endDate, "Couldn't find end date field.");
endDate->setCurrentText(QStringLiteral("33 Jan 2000"));
mEndDate->setCurrentText(QStringLiteral("33 Jan 2000"));
QVERIFY2(!editor->isValid(), "Didn't detect invalid end date.");
endDate->setCurrentText(QStringLiteral("13 Jan 2000"));
mEndDate->setCurrentText(QStringLiteral("13 Jan 2000"));
QVERIFY(editor->isValid());
auto endTime = dialog->findChild<KTimeComboBox *>(QStringLiteral("mEndTimeEdit"));
QVERIFY2(endTime, "Couldn't find end time field.");
endTime->setCurrentText(QStringLiteral("12:99:00"));
mEndTime->setCurrentText(QStringLiteral("12:99:00"));
QVERIFY2(!editor->isValid(), "Didn't detect invalid end time.");
endTime->setCurrentText(QStringLiteral("12:00:00"));
mEndTime->setCurrentText(QStringLiteral("12:00:00"));
QVERIFY(editor->isValid());
auto startZone = dialog->findChild<KTimeZoneComboBox *>(QStringLiteral("mTimeZoneComboStart"));
QVERIFY2(startZone, "Couldn't find start time zone field.");
auto endZone = dialog->findChild<KTimeZoneComboBox *>(QStringLiteral("mTimeZoneComboEnd"));
QVERIFY2(endZone, "Couldn't find end time zone field.");
startZone->selectTimeZone(QTimeZone("Africa/Abidjan")); // UTC.
endZone->selectTimeZone(QTimeZone("Africa/Abidjan"));
mStartZone->selectTimeZone(QTimeZone("Africa/Abidjan")); // UTC.
mEndZone->selectTimeZone(QTimeZone("Africa/Abidjan"));
QVERIFY(editor->isValid());
endDate->setDate(startDate->date().addDays(-1));
endTime->setTime(startTime->time());
mEndDate->setDate(mStartDate->date().addDays(-1));
mEndTime->setTime(mStartTime->time());
QVERIFY2(!editor->isValid(), "Didn't detect end date < start date");
endDate->setDate(startDate->date());
mEndDate->setDate(mStartDate->date());
QVERIFY(editor->isValid());
endTime->setTime(startTime->time().addSecs(-60));
mEndTime->setTime(mStartTime->time().addSecs(-60));
QVERIFY2(!editor->isValid(), "Didn't detect end time < start time");
endTime->setTime(startTime->time());
mEndTime->setTime(mStartTime->time());
QVERIFY(editor->isValid());
endZone->selectTimeZone(QTimeZone("Africa/Addis_Ababa")); // UTC+3; causes 3-hour shift in effective end time.
mEndZone->selectTimeZone(QTimeZone("Africa/Addis_Ababa")); // UTC+3; causes 3-hour shift in effective end time.
QVERIFY2(!editor->isValid(), "Didn't detect end time < start time in different time zone");
QLocale::setDefault(currentLocale);
}
void testLoadingTimelessTodo()
{
KCalendarCore::Todo::Ptr todo {new KCalendarCore::Todo};
todo->setDtStart(QDateTime());
todo->setDtDue(QDateTime());
todo->setAllDay(false);
Akonadi::Item item;
item.setPayload<KCalendarCore::Todo::Ptr>(todo);
mDialog->load(item);
QVERIFY( ! mAllDay->isEnabled());
QVERIFY(mAllDay->isVisible());
QVERIFY(mStartCheck->isEnabled());
QVERIFY(mStartCheck->isVisible());
QCOMPARE(mStartCheck->checkState(), Qt::Unchecked);
QVERIFY(mEndCheck->isEnabled());
QVERIFY(mEndCheck->isVisible());
QCOMPARE(mEndCheck->checkState(), Qt::Unchecked);
}
void testLoadingTimedTodo()
{
const QDate date {2022, 04, 01};
const QTime time {00, 00, 00};
const QTimeZone zone {"Africa/Abidjan"};
const QDateTime dt {date, time, zone};
KCalendarCore::Todo::Ptr todo {new KCalendarCore::Todo};
todo->setDtStart(dt);
todo->setDtDue(dt);
todo->setAllDay(false);
Akonadi::Item item;
item.setPayload<KCalendarCore::Todo::Ptr>(todo);
mDialog->load(item);
QVERIFY(mAllDay->isEnabled());
QVERIFY(mAllDay->isVisible());
QCOMPARE(mAllDay->checkState(), Qt::Unchecked);
QVERIFY(mStartCheck->isEnabled());
QVERIFY(mStartCheck->isVisible());
QCOMPARE(mStartCheck->checkState(), Qt::Checked);
QCOMPARE(mStartDate->date(), date);
QCOMPARE(mStartTime->time(), time);
QCOMPARE(mStartZone->selectedTimeZone(), zone);
QVERIFY(mEndCheck->isEnabled());
QVERIFY(mEndCheck->isVisible());
QCOMPARE(mEndCheck->checkState(), Qt::Checked);
QCOMPARE(mEndDate->date(), date);
QCOMPARE(mEndTime->time(), time);
QCOMPARE(mEndZone->selectedTimeZone(), zone);
}
void testLoadingAlldayTodo()
{
const QDate date {2022, 04, 01};
const QTime time {00, 00, 00};
const QTimeZone zone {"Africa/Abidjan"};
const QDateTime dt {date, time, zone};
KCalendarCore::Todo::Ptr todo {new KCalendarCore::Todo};
todo->setDtStart(dt);
todo->setDtDue(dt);
todo->setAllDay(true);
Akonadi::Item item;
item.setPayload<KCalendarCore::Todo::Ptr>(todo);
mDialog->load(item);
QCOMPARE(mAllDay->isEnabled(), true);
QVERIFY(mAllDay->isVisible());
QCOMPARE(mAllDay->checkState(), Qt::Checked);
QVERIFY(mStartCheck->isEnabled());
QVERIFY(mStartCheck->isVisible());
QCOMPARE(mStartCheck->checkState(), Qt::Checked);
QCOMPARE(mStartDate->date(), date);
QVERIFY( ! mStartTime->isEnabled());
QVERIFY( ! mStartZone->isVisible());
QVERIFY(mEndCheck->isEnabled());
QVERIFY(mEndCheck->isVisible());
QCOMPARE(mEndCheck->checkState(), Qt::Checked);
QVERIFY( ! mEndTime->isEnabled());
QVERIFY( ! mEndZone->isVisible());
}
};
QTEST_MAIN(IncidenceDateTimeTest)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment