Commit 0f5d36ba authored by Laurent Montel's avatar Laurent Montel 😁

Move plugin here

parent 358ec822
......@@ -18,6 +18,7 @@ set(KDEPIMADDONS_VERSION "${KDEPIMADDONS_VERSION_NUMBER}${KDEPIMADDONS_DEV_VERSI
set(KDEPIMADDONS_LIB_VERSION "${KDEPIMADDONS_VERSION_NUMBER}")
set(KDEPIMADDONS_LIB_SOVERSION "5")
set(AKONADINOTES_LIB_VERSION "4.78.0")
set(QT_REQUIRED_VERSION "5.4.0")
set(KF5_VERSION "5.16.0")
include(ECMOptionalAddSubdirectory)
......@@ -82,6 +83,7 @@ find_package(KF5KdepimDBusInterfaces ${KDEPIM_LIB_INSTALLED_VERSION} CONFIG REQU
find_package(KF5LibKSieve ${KDEPIM_LIB_INSTALLED_VERSION} CONFIG REQUIRED)
find_package(KF5Gravatar ${KDEPIM_LIB_INSTALLED_VERSION} CONFIG REQUIRED)
find_package(MailTransportDBusService CONFIG REQUIRED)
find_package(KF5AkonadiNotes ${AKONADINOTES_LIB_VERSION} CONFIG REQUIRED)
add_definitions( -DQT_NO_CAST_FROM_ASCII )
add_definitions( -DQT_NO_CAST_TO_ASCII )
......
if(BUILD_TESTING)
add_subdirectory(autotests)
endif()
add_definitions(-DTRANSLATION_DOMAIN=\"messageviewerplugins\")
add_subdirectory(translatorplugin)
add_subdirectory(createnoteplugin)
add_subdirectory(createtodoplugin)
add_subdirectory(createeventplugin)
#! /bin/sh
$XGETTEXT `find . -name '*.cpp' -o -name '*.h' | grep -v '/tests/' | grep -v '/autotests/'` -o $podir/messageviewerplugins.pot
set(common_SRCS)
ecm_qt_declare_logging_category(common_SRCS HEADER createeventplugin_debug.h IDENTIFIER CREATEEVENTPLUGIN_LOG CATEGORY_NAME log_createeventplugin)
ecm_qt_declare_logging_category(common_SRCS HEADER createnoteplugin_debug.h IDENTIFIER CREATENOTEPLUGIN_LOG CATEGORY_NAME log_createnoteplugin)
ecm_qt_declare_logging_category(common_SRCS HEADER createtodoplugin_debug.h IDENTIFIER CREATETODOPLUGIN_LOG CATEGORY_NAME log_createtodoplugin)
macro(add_messageviewer_viewerplugin_unittest _source _additional _jsonfile)
set( _test ${_source} ${_additional} ${common_SRCS})
get_filename_component(_name ${_source} NAME_WE)
add_executable( ${_name} ${_test} )
kcoreaddons_desktop_to_json(${_name} ${_jsonfile})
add_test( ${_name} ${_name} )
ecm_mark_as_test(messageviewer-viewerplugin-unittest-${_name})
target_link_libraries( ${_name} KF5::MessageViewer KF5::Libkleo KF5::QGpgme Qt5::Test Qt5::WebKitWidgets KF5::KIOCore KF5::Mime KF5::AkonadiCore KF5::AkonadiNotes KF5::CalendarCore KF5::GrantleeTheme KF5::IncidenceEditorsng)
endmacro ()
macro(add_messageviewer_viewerplugin_class_unittest _source )
set( _test ${_source} ${common_SRCS})
get_filename_component(_name ${_source} NAME_WE)
add_executable( ${_name} ${_test} )
add_test( ${_name} ${_name} )
ecm_mark_as_test(messageviewer-viewerplugin-${_name})
target_link_libraries( ${_name} KF5::MessageViewer KF5::Libkleo KF5::QGpgme Qt5::Test Qt5::WebKitWidgets KF5::KIOCore KF5::Mime KF5::AkonadiCore KF5::AkonadiNotes KF5::CalendarCore KF5::GrantleeTheme)
endmacro ()
macro(add_messageviewer_viewerplugin_widget_unittest _source _additional )
set( _test ${_source} ${_additional} ${common_SRCS})
get_filename_component(_name ${_source} NAME_WE)
add_executable( ${_name} ${_test} )
add_test( ${_name} ${_name} )
ecm_mark_as_test(messageviewer-viewerplugin-${_name})
target_link_libraries( ${_name} KF5::MessageViewer KF5::Libkleo KF5::QGpgme Qt5::Test Qt5::WebKitWidgets KF5::KIOCore KF5::Mime KF5::AkonadiCore KF5::AkonadiNotes KF5::CalendarCore KF5::GrantleeTheme KF5::IncidenceEditorsng)
endmacro ()
add_messageviewer_viewerplugin_class_unittest(viewerpluginmanagertest.cpp)
add_messageviewer_viewerplugin_class_unittest(viewerplugintoolmanagertest.cpp)
add_messageviewer_viewerplugin_widget_unittest(todoedittest.cpp "../createtodoplugin/todoedit.cpp")
add_messageviewer_viewerplugin_widget_unittest(noteedittest.cpp "../createnoteplugin/noteedit.cpp")
set_tests_properties(todoedittest PROPERTIES ENVIRONMENT "LC_ALL=C")
add_messageviewer_viewerplugin_widget_unittest(eventedittest.cpp "../createeventplugin/eventedit.cpp;../createeventplugin/eventdatetimewidget.cpp")
add_messageviewer_viewerplugin_widget_unittest(eventdatetimewidgettest.cpp "../createeventplugin/eventdatetimewidget.cpp")
add_messageviewer_viewerplugin_unittest(viewerplugincreateeventtest.cpp "../createeventplugin/eventdatetimewidget.cpp;../createeventplugin/eventedit.cpp;../createeventplugin/viewerplugincreateevent.cpp;../createeventplugin/viewerplugincreateeventinterface.cpp" "../createeventplugin/messageviewer_createeventplugin.desktop")
add_messageviewer_viewerplugin_unittest(viewerplugincreatetodotest.cpp "../createtodoplugin/viewerplugincreatetodo.cpp;../createtodoplugin/viewerplugincreatetodointerface.cpp;../createtodoplugin/todoedit.cpp" "../createtodoplugin/messageviewer_createtodoplugin.desktop")
add_messageviewer_viewerplugin_unittest(viewerplugincreatenotetest.cpp "../createnoteplugin/noteedit.cpp;../createnoteplugin/viewerplugincreatenote.cpp;../createnoteplugin/viewerplugincreatenoteinterface.cpp" "../createnoteplugin/messageviewer_createnoteplugin.desktop")
add_messageviewer_viewerplugin_unittest(viewerplugintranslatortest.cpp "../translatorplugin/viewerplugintranslator.cpp;../translatorplugin/viewerplugintranslatorinterface.cpp" "../translatorplugin/messageviewer_translatorplugin.desktop")
/*
Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "eventdatetimewidgettest.h"
#include "../createeventplugin/eventdatetimewidget.h"
#include <KDateComboBox>
#include <KTimeComboBox>
#include <qtest.h>
#include <QSignalSpy>
EventDateTimeWidgetTest::EventDateTimeWidgetTest(QObject *parent)
: QObject(parent)
{
}
EventDateTimeWidgetTest::~EventDateTimeWidgetTest()
{
}
void EventDateTimeWidgetTest::shouldHaveDefaultValue()
{
MessageViewer::EventDateTimeWidget edit;
KDateComboBox *datecombobox = edit.findChild<KDateComboBox *>(QStringLiteral("eventdatecombobox"));
QVERIFY(datecombobox);
KTimeComboBox *timecombobox = edit.findChild<KTimeComboBox *>(QStringLiteral("eventtimecombobox"));
QVERIFY(timecombobox);
}
void EventDateTimeWidgetTest::shouldSetDateTime()
{
MessageViewer::EventDateTimeWidget edit;
const QDateTime currentDateTime = QDateTime::currentDateTime();
edit.setDateTime(currentDateTime);
QCOMPARE(edit.dateTime().time().minute(), currentDateTime.time().minute());
QCOMPARE(edit.dateTime().time().hour(), currentDateTime.time().hour());
}
void EventDateTimeWidgetTest::shouldEmitSignalWhenDateTimeChanged()
{
MessageViewer::EventDateTimeWidget edit;
QDateTime currentDateTime = QDateTime::currentDateTime();
edit.setDateTime(currentDateTime);
QSignalSpy spy(&edit, SIGNAL(dateTimeChanged(QDateTime)));
currentDateTime.setDate(currentDateTime.date().addDays(1));
edit.setDateTime(currentDateTime);
QCOMPARE(spy.count(), 1);
}
void EventDateTimeWidgetTest::shouldEmitSignalWhenJustTimeChanged()
{
MessageViewer::EventDateTimeWidget edit;
QDateTime currentDateTime = QDateTime::currentDateTime();
edit.setDateTime(currentDateTime);
QSignalSpy spy(&edit, SIGNAL(dateTimeChanged(QDateTime)));
QTime time = currentDateTime.time().addSecs(3600);
edit.setTime(time);
QCOMPARE(spy.count(), 1);
}
void EventDateTimeWidgetTest::shouldEmitSignalWhenJustDateChanged()
{
MessageViewer::EventDateTimeWidget edit;
QDateTime currentDateTime = QDateTime::currentDateTime();
edit.setDateTime(currentDateTime);
QSignalSpy spy(&edit, SIGNAL(dateTimeChanged(QDateTime)));
QDate date = currentDateTime.date().addDays(1);
edit.setDate(date);
QCOMPARE(spy.count(), 1);
}
void EventDateTimeWidgetTest::shouldNotEmitSignalWhenDateTimeWasNotChanged()
{
MessageViewer::EventDateTimeWidget edit;
QDateTime currentDateTime = QDateTime::currentDateTime();
edit.setDateTime(currentDateTime);
QSignalSpy spy(&edit, SIGNAL(dateTimeChanged(QDateTime)));
currentDateTime.setDate(currentDateTime.date().addDays(1));
edit.setDateTime(currentDateTime);
QCOMPARE(spy.count(), 1);
edit.setDateTime(currentDateTime);
//FIX ME
//QCOMPARE(spy.count(), 2);
}
QTEST_MAIN(EventDateTimeWidgetTest)
/*
Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef EVENTDATETIMEWIDGETTEST_H
#define EVENTDATETIMEWIDGETTEST_H
#include <QObject>
class EventDateTimeWidgetTest : public QObject
{
Q_OBJECT
public:
explicit EventDateTimeWidgetTest(QObject *parent = Q_NULLPTR);
~EventDateTimeWidgetTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldSetDateTime();
void shouldEmitSignalWhenDateTimeChanged();
void shouldEmitSignalWhenJustTimeChanged();
void shouldEmitSignalWhenJustDateChanged();
void shouldNotEmitSignalWhenDateTimeWasNotChanged();
};
#endif // EVENTDATETIMEWIDGETTEST_H
/*
Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "eventedittest.h"
#include "../createeventplugin/eventedit.h"
#include "../createeventplugin/eventdatetimewidget.h"
#include "globalsettings_messageviewer.h"
#include <AkonadiCore/Collection>
#include <AkonadiWidgets/CollectionComboBox>
#include <AkonadiCore/EntityTreeModel>
#include <QStandardItemModel>
#include <KCalCore/Event>
#include <QPushButton>
#include <qtest.h>
#include <qtestkeyboard.h>
#include <qtestmouse.h>
#include <QSignalSpy>
#include <QLineEdit>
#include <QHBoxLayout>
#include <QShortcut>
#include <QAction>
namespace MessageViewer
{
extern MESSAGEVIEWER_EXPORT QAbstractItemModel *_k_eventEditStubModel;
}
EventEditTest::EventEditTest()
{
qRegisterMetaType<Akonadi::Collection>();
qRegisterMetaType<KMime::Message::Ptr>();
qRegisterMetaType<KCalCore::Event::Ptr>();
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));
collection.setContentMimeTypes(QStringList() << KCalCore::Event::eventMimeType());
QStandardItem *item = new QStandardItem(collection.name());
item->setData(QVariant::fromValue(collection),
Akonadi::EntityTreeModel::CollectionRole);
item->setData(QVariant::fromValue(collection.id()),
Akonadi::EntityTreeModel::CollectionIdRole);
model->appendRow(item);
}
MessageViewer::_k_eventEditStubModel = model;
}
void EventEditTest::shouldHaveDefaultValuesOnCreation()
{
MessageViewer::EventEdit edit;
//We can't test it. Collection value is stored in settings here, and not in jenkins so disable it
QVERIFY(edit.collection().isValid());
QVERIFY(!edit.message());
QLineEdit *eventedit = edit.findChild<QLineEdit *>(QStringLiteral("eventedit"));
QVERIFY(eventedit);
QCOMPARE(eventedit->text(), QString());
QPushButton *openEditor = edit.findChild<QPushButton *>(QStringLiteral("open-editor-button"));
QPushButton *save = edit.findChild<QPushButton *>(QStringLiteral("save-button"));
QVERIFY(openEditor);
QVERIFY(save);
QCOMPARE(openEditor->isEnabled(), false);
QCOMPARE(save->isEnabled(), false);
QDateTime currentDateTime = QDateTime::currentDateTime();
MessageViewer::EventDateTimeWidget *startDateTime = edit.findChild<MessageViewer::EventDateTimeWidget *>(QStringLiteral("startdatetimeedit"));
QVERIFY(startDateTime);
QCOMPARE(startDateTime->dateTime().date(), currentDateTime.date());
QCOMPARE(startDateTime->dateTime().time().hour(), currentDateTime.time().hour());
QCOMPARE(startDateTime->dateTime().time().minute(), currentDateTime.time().minute());
MessageViewer::EventDateTimeWidget *endDateTime = edit.findChild<MessageViewer::EventDateTimeWidget *>(QStringLiteral("enddatetimeedit"));
QVERIFY(endDateTime);
currentDateTime = currentDateTime.addSecs(3600); // +1hour
QCOMPARE(endDateTime->dateTime().date(), currentDateTime.date());
QCOMPARE(endDateTime->dateTime().time().hour(), currentDateTime.time().hour());
QCOMPARE(endDateTime->dateTime().time().minute(), currentDateTime.time().minute());
}
void EventEditTest::shouldEmitCollectionChanged()
{
MessageViewer::EventEdit edit;
QSignalSpy spy(&edit, SIGNAL(collectionChanged(Akonadi::Collection)));
edit.setCollection(Akonadi::Collection(42));
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.at(0).at(0).value<Akonadi::Collection>(), Akonadi::Collection(42));
}
void EventEditTest::shouldEmitMessageChanged()
{
MessageViewer::EventEdit edit;
QSignalSpy spy(&edit, SIGNAL(messageChanged(KMime::Message::Ptr)));
KMime::Message::Ptr msg(new KMime::Message);
edit.setMessage(msg);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.at(0).at(0).value<KMime::Message::Ptr>(), msg);
}
void EventEditTest::shouldNotEmitWhenCollectionIsNotChanged()
{
MessageViewer::EventEdit edit;
edit.setCollection(Akonadi::Collection(42));
QSignalSpy spy(&edit, SIGNAL(collectionChanged(Akonadi::Collection)));
edit.setCollection(Akonadi::Collection(42));
QCOMPARE(spy.count(), 0);
}
void EventEditTest::shouldNotEmitWhenMessageIsNotChanged()
{
MessageViewer::EventEdit edit;
KMime::Message::Ptr msg(new KMime::Message);
edit.setMessage(msg);
QSignalSpy spy(&edit, SIGNAL(messageChanged(KMime::Message::Ptr)));
edit.setMessage(msg);
QCOMPARE(spy.count(), 0);
}
void EventEditTest::shouldEmitEventWhenPressEnter()
{
MessageViewer::EventEdit edit;
KMime::Message::Ptr msg(new KMime::Message);
QString subject = QStringLiteral("Test Note");
msg->subject(true)->fromUnicodeString(subject, "us-ascii");
edit.setMessage(msg);
QLineEdit *eventedit = edit.findChild<QLineEdit *>(QStringLiteral("eventedit"));
eventedit->setFocus();
QSignalSpy spy(&edit, SIGNAL(createEvent(KCalCore::Event::Ptr,Akonadi::Collection)));
QTest::keyClick(eventedit, Qt::Key_Enter);
QCOMPARE(spy.count(), 1);
}
void EventEditTest::shouldHideWidgetWhenPressEnter()
{
MessageViewer::EventEdit edit;
edit.show();
QTest::qWaitForWindowExposed(&edit);
QVERIFY(edit.isVisible());
KMime::Message::Ptr msg(new KMime::Message);
QString subject = QStringLiteral("Test Note");
msg->subject(true)->fromUnicodeString(subject, "us-ascii");
edit.setMessage(msg);
QLineEdit *eventedit = edit.findChild<QLineEdit *>(QStringLiteral("eventedit"));
QTest::keyClick(eventedit, Qt::Key_Enter);
QCOMPARE(edit.isVisible(), false);
}
void EventEditTest::shouldHideWidgetWhenPressEscape()
{
MessageViewer::EventEdit edit;
edit.show();
QTest::qWaitForWindowExposed(&edit);
QLineEdit *eventedit = edit.findChild<QLineEdit *>(QStringLiteral("eventedit"));
eventedit->setFocus();
QVERIFY(eventedit->hasFocus());
QTest::keyPress(&edit, Qt::Key_Escape);
QCOMPARE(edit.isVisible(), false);
}
void EventEditTest::shouldHideWidgetWhenSaveClicked()
{
MessageViewer::EventEdit edit;
edit.show();
QTest::qWaitForWindowExposed(&edit);
KMime::Message::Ptr msg(new KMime::Message);
msg->subject(true)->fromUnicodeString(QStringLiteral("Test Note"), "us-ascii");
edit.setMessage(msg);
QPushButton *save = edit.findChild<QPushButton *>(QStringLiteral("save-button"));
QTest::mouseClick(save, Qt::LeftButton);
QCOMPARE(edit.isVisible(), false);
}
void EventEditTest::shouldSaveCollectionSettings()
{
MessageViewer::EventEdit edit;
edit.show();
QTest::qWaitForWindowExposed(&edit);
Akonadi::CollectionComboBox *akonadicombobox = edit.findChild<Akonadi::CollectionComboBox *>(QStringLiteral("akonadicombobox"));
akonadicombobox->setCurrentIndex(3);
const Akonadi::Collection::Id id = akonadicombobox->currentCollection().id();
QPushButton *close = edit.findChild<QPushButton *>(QStringLiteral("close-button"));
QTest::mouseClick(close, Qt::LeftButton);
QCOMPARE(MessageViewer::MessageViewerSettingsBase::self()->lastEventSelectedFolder(), id);
}
void EventEditTest::shouldSaveCollectionSettingsWhenCloseWidget()
{
MessageViewer::EventEdit edit;
edit.show();
QTest::qWaitForWindowExposed(&edit);
Akonadi::CollectionComboBox *akonadicombobox = edit.findChild<Akonadi::CollectionComboBox *>(QStringLiteral("akonadicombobox"));
akonadicombobox->setCurrentIndex(4);
const Akonadi::Collection::Id id = akonadicombobox->currentCollection().id();
edit.writeConfig();
QCOMPARE(MessageViewer::MessageViewerSettingsBase::self()->lastEventSelectedFolder(), id);
}
void EventEditTest::shouldSaveCollectionSettingsWhenDeleteWidget()
{
MessageViewer::EventEdit *edit = new MessageViewer::EventEdit;
Akonadi::CollectionComboBox *akonadicombobox = edit->findChild<Akonadi::CollectionComboBox *>(QStringLiteral("akonadicombobox"));
akonadicombobox->setCurrentIndex(5);
const Akonadi::Collection::Id id = akonadicombobox->currentCollection().id();
delete edit;
QCOMPARE(MessageViewer::MessageViewerSettingsBase::self()->lastEventSelectedFolder(), id);
}
void EventEditTest::shouldNotEmitCreateEventWhenDateIsInvalid()
{
MessageViewer::EventEdit edit;
KMime::Message::Ptr msg(new KMime::Message);
MessageViewer::EventDateTimeWidget *startDateTime = edit.findChild<MessageViewer::EventDateTimeWidget *>(QStringLiteral("startdatetimeedit"));
startDateTime->setDateTime(QDateTime());
MessageViewer::EventDateTimeWidget *endDateTime = edit.findChild<MessageViewer::EventDateTimeWidget *>(QStringLiteral("enddatetimeedit"));
endDateTime->setDateTime(QDateTime());
QString subject = QStringLiteral("Test Note");
msg->subject(true)->fromUnicodeString(subject, "us-ascii");
edit.setMessage(msg);
QLineEdit *eventedit = edit.findChild<QLineEdit *>(QStringLiteral("eventedit"));
QSignalSpy spy(&edit, SIGNAL(createEvent(KCalCore::Event::Ptr,Akonadi::Collection)));
QTest::keyClick(eventedit, Qt::Key_Enter);
QCOMPARE(spy.count(), 0);
}
void EventEditTest::shouldEventHasCorrectSubject()
{
MessageViewer::EventEdit edit;
KMime::Message::Ptr msg(new KMime::Message);
QString subject = QStringLiteral("Test Note");
msg->subject(true)->fromUnicodeString(subject, "us-ascii");
edit.setMessage(msg);
QLineEdit *noteedit = edit.findChild<QLineEdit *>(QStringLiteral("eventedit"));
QVERIFY(noteedit);
QSignalSpy spy(&edit, SIGNAL(createEvent(KCalCore::Event::Ptr,Akonadi::Collection)));
QTest::keyClick(noteedit, Qt::Key_Enter);
QCOMPARE(spy.count(), 1);
KCalCore::Event::Ptr eventPtr = spy.at(0).at(0).value<KCalCore::Event::Ptr>();
QVERIFY(eventPtr);
QCOMPARE(eventPtr->summary(), subject);
}
void EventEditTest::shouldSelectLineWhenPutMessage()
{
MessageViewer::EventEdit edit;
KMime::Message::Ptr msg(new KMime::Message);
QString subject = QStringLiteral("Test Note");
msg->subject(true)->fromUnicodeString(subject, "us-ascii");
edit.setMessage(msg);
QLineEdit *noteedit = edit.findChild<QLineEdit *>(QStringLiteral("eventedit"));
QVERIFY(noteedit);
QVERIFY(noteedit->hasSelectedText());
const QString selectedText = noteedit->selectedText();
QCOMPARE(selectedText, subject);
}
void EventEditTest::shouldHaveCorrectStartEndDateTime()
{
MessageViewer::EventEdit edit;
KMime::Message::Ptr msg(new KMime::Message);
QString subject = QStringLiteral("Test Note");
msg->subject(true)->fromUnicodeString(subject, "us-ascii");
edit.setMessage(msg);
QDateTime currentDateTime = QDateTime::currentDateTime();
MessageViewer::EventDateTimeWidget *startDateTime = edit.findChild<MessageViewer::EventDateTimeWidget *>(QStringLiteral("startdatetimeedit"));
startDateTime->setDateTime(currentDateTime);
QDateTime endDt = currentDateTime.addDays(1);
MessageViewer::EventDateTimeWidget *endDateTime = edit.findChild<MessageViewer::EventDateTimeWidget *>(QStringLiteral("enddatetimeedit"));
endDateTime->setDateTime(endDt);
QLineEdit *noteedit = edit.findChild<QLineEdit *>(QStringLiteral("eventedit"));
QVERIFY(noteedit);
QSignalSpy spy(&edit, SIGNAL(createEvent(KCalCore::Event::Ptr,Akonadi::Collection)));
QTest::keyClick(noteedit, Qt::Key_Enter);
QCOMPARE(spy.count(), 1);
KCalCore::Event::Ptr eventPtr = spy.at(0).at(0).value<KCalCore::Event::Ptr>();
QVERIFY(eventPtr);
QCOMPARE(eventPtr->dtStart().date(), currentDateTime.date());
QCOMPARE(eventPtr->dtStart().time().hour(), currentDateTime.time().hour());
QCOMPARE(eventPtr->dtStart().time().minute(), currentDateTime.time().minute());
QCOMPARE(eventPtr->dtEnd().date(), endDt.date());
QCOMPARE(eventPtr->dtEnd().time().hour(), endDt.time().hour());
QCOMPARE(eventPtr->dtEnd().time().minute(), endDt.time().minute());
}
void EventEditTest::shouldSetFocusWhenWeCallTodoEdit()
{
MessageViewer::EventEdit edit;
edit.show();
QTest::qWaitForWindowExposed(&edit);
QLineEdit *noteedit = edit.findChild<QLineEdit *>(QStringLiteral("eventedit"));
QVERIFY(noteedit);
edit.setFocus();
edit.showEventEdit();
QVERIFY(noteedit->hasFocus());
}
void EventEditTest::shouldEnsureEndDateIsNotBeforeStartDate()