2 Copyright (c) 2014 Sandro Knauß <knauss@kolabsys.com>
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License, version 2, as
6 published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "koeventpopupmenutest.h"
19 #include "dialog/noteeditdialog.h"
20 #include "koeventpopupmenu.h"
21 #include <IncidenceEditor/IncidenceDialog>
22 #include <IncidenceEditor/IncidenceAttendee>
23 #include <CalendarSupport/Utils>
24 #include <AkonadiCore/EntityTreeModel>
25 #include <Akonadi/Notes/NoteUtils>
26 #include <KCalCore/Event>
27 #include <KCalCore/Todo>
29 #include <KMime/KMimeMessage>
30 #include <QPushButton>
32 #include <qtestkeyboard.h>
33 #include <qtestmouse.h>
38 KoEventPopupMenuTest::KoEventPopupMenuTest()
42 void KoEventPopupMenuTest::createEventFromEvent()
44 Akonadi::ETMCalendar::Ptr
calendar(new Akonadi::ETMCalendar());
45 KOEventPopupMenu
menu(0);
47 KCalCore::Event::Ptr
event(new KCalCore::Event());
49 item
.setMimeType(KCalCore::Event::eventMimeType());
50 item
.setPayload
<KCalCore::Event::Ptr
>(event
);
52 menu
.setCalendar(calendar
);
53 menu
.showIncidencePopup(item
, QDate());
54 QAction
*createevent
= menu
.findChild
<QAction
*>(QStringLiteral("createevent"));
55 createevent
->trigger();
57 IncidenceEditorNG::IncidenceDialog
*dlg
= menu
.findChild
<IncidenceEditorNG::IncidenceDialog
*>(QStringLiteral("incidencedialog"));
62 void KoEventPopupMenuTest::createTodoFromTodo()
64 Akonadi::ETMCalendar::Ptr
calendar(new Akonadi::ETMCalendar());
65 KOEventPopupMenu
menu(0);
67 KCalCore::Todo::Ptr
todo(new KCalCore::Todo());
69 item
.setMimeType(KCalCore::Todo::todoMimeType());
70 item
.setPayload
<KCalCore::Todo::Ptr
>(todo
);
72 menu
.setCalendar(calendar
);
73 menu
.showIncidencePopup(item
, QDate());
74 QAction
*createtodo
= menu
.findChild
<QAction
*>(QStringLiteral("createtodo"));
75 createtodo
->trigger();
77 IncidenceEditorNG::IncidenceDialog
*dlg
= menu
.findChild
<IncidenceEditorNG::IncidenceDialog
*>(QStringLiteral("incidencedialog"));
81 void KoEventPopupMenuTest::createEventFromTodo()
83 Akonadi::ETMCalendar::Ptr
calendar(new Akonadi::ETMCalendar());
84 KOEventPopupMenu
menu(0);
86 KCalCore::Todo::Ptr
todo(new KCalCore::Todo());
88 item
.setMimeType(KCalCore::Todo::todoMimeType());
89 item
.setPayload
<KCalCore::Todo::Ptr
>(todo
);
92 QString
summary(QStringLiteral("a test"));
93 start
.setTime_t(1402593346);
94 end
.setTime_t(1403593346);
95 todo
->setDtStart(start
);
97 todo
->setSummary(summary
);
99 menu
.setCalendar(calendar
);
100 menu
.showIncidencePopup(item
, QDate());
101 QAction
*createevent
= menu
.findChild
<QAction
*>(QStringLiteral("createevent"));
102 createevent
->trigger();
103 IncidenceEditorNG::IncidenceDialog
*dlg
= qFindChild
<IncidenceEditorNG::IncidenceDialog
*>(&menu
);
105 IncidenceEditorNG::IncidenceEditor
*editor
= qFindChild
<IncidenceEditorNG::IncidenceEditor
*>(&menu
);
107 KCalCore::Event::Ptr
event(editor
->incidence
<KCalCore::Event
>());
108 QVERIFY(event
->uid() != todo
->uid());
109 QCOMPARE(event
->dtStart(), start
);
110 QCOMPARE(event
->dtEnd(), end
);
111 QCOMPARE(event
->allDay(), false);
112 QCOMPARE(event
->summary(), summary
);
115 void KoEventPopupMenuTest::createTodoFromEvent()
117 Akonadi::ETMCalendar::Ptr
calendar(new Akonadi::ETMCalendar());
118 KOEventPopupMenu
menu(0);
120 KCalCore::Event::Ptr
event(new KCalCore::Event());
122 item
.setMimeType(KCalCore::Event::eventMimeType());
123 item
.setPayload
<KCalCore::Event::Ptr
>(event
);
125 KDateTime start
, end
;
126 QString
summary(QStringLiteral("a test"));
127 start
.setTime_t(1402593346);
128 end
.setTime_t(1403593346);
129 event
->setDtStart(start
);
130 event
->setDtEnd(end
);
131 event
->setSummary(summary
);
133 menu
.setCalendar(calendar
);
134 menu
.showIncidencePopup(item
, QDate());
135 QAction
*createtodo
= menu
.findChild
<QAction
*>(QStringLiteral("createtodo"));
136 createtodo
->trigger();
137 IncidenceEditorNG::IncidenceDialog
*dlg
= qFindChild
<IncidenceEditorNG::IncidenceDialog
*>(&menu
);
139 IncidenceEditorNG::IncidenceEditor
*editor
= qFindChild
<IncidenceEditorNG::IncidenceEditor
*>(&menu
);
141 KCalCore::Todo::Ptr
todo(editor
->incidence
<KCalCore::Todo
>());
142 QVERIFY(todo
->uid() != event
->uid());
143 QCOMPARE(todo
->dtStart(), start
);
144 QCOMPARE(todo
->dtDue(), end
);
145 QCOMPARE(todo
->allDay(), false);
146 QCOMPARE(todo
->summary(), summary
);
149 void KoEventPopupMenuTest::createNoteFromEvent()
151 Akonadi::ETMCalendar::Ptr
calendar(new Akonadi::ETMCalendar());
152 KOEventPopupMenu
menu(0);
154 KCalCore::Event::Ptr
event(new KCalCore::Event());
156 item
.setMimeType(KCalCore::Event::eventMimeType());
157 item
.setPayload
<KCalCore::Event::Ptr
>(event
);
159 KDateTime start
, end
;
160 QString
summary(QStringLiteral("A test"));
161 QString
description(QStringLiteral("A long description"));
162 start
.setTime_t(1402593346);
163 end
.setTime_t(1403593346);
164 event
->setDtStart(start
);
165 event
->setDtEnd(end
);
166 event
->setSummary(summary
);
167 event
->setDescription(description
, true);
169 menu
.setCalendar(calendar
);
170 menu
.showIncidencePopup(item
, QDate());
171 QAction
*createnote
= menu
.findChild
<QAction
*>(QStringLiteral("createnote"));
172 NoteEditDialog
*noteedit
= qFindChild
<NoteEditDialog
*>(&menu
);
174 createnote
->trigger();
175 noteedit
= qFindChild
<NoteEditDialog
*>(&menu
);
177 Akonadi::NoteUtils::NoteMessageWrapper
note(noteedit
->note());
178 QCOMPARE(note
.title(), summary
);
179 QCOMPARE(note
.text(), description
);
180 QCOMPARE(note
.textFormat(), Qt::RichText
);
181 QCOMPARE(note
.attachments().count(), 1);
182 QCOMPARE(note
.attachments().at(0).mimetype(), KCalCore::Event::eventMimeType());
183 QCOMPARE(note
.attachments().at(0).url(), (QUrl
)item
.url());
184 QCOMPARE(note
.attachments().at(0).data(), QByteArray());
187 void KoEventPopupMenuTest::createNoteFromTodo()
189 Akonadi::ETMCalendar::Ptr
calendar(new Akonadi::ETMCalendar());
190 KOEventPopupMenu
menu(0);
192 KCalCore::Todo::Ptr
todo(new KCalCore::Todo());
194 item
.setMimeType(KCalCore::Todo::todoMimeType());
195 item
.setPayload
<KCalCore::Todo::Ptr
>(todo
);
197 KDateTime start
, end
;
198 QString
summary(QStringLiteral("a test"));
199 QString
description(QStringLiteral("A long description"));
200 start
.setTime_t(1402593346);
201 end
.setTime_t(1403593346);
202 todo
->setDtStart(start
);
204 todo
->setSummary(summary
);
205 todo
->setDescription(description
);
207 menu
.setCalendar(calendar
);
208 menu
.showIncidencePopup(item
, QDate());
209 QAction
*createnote
= menu
.findChild
<QAction
*>(QStringLiteral("createnote"));
211 NoteEditDialog
*noteedit
= qFindChild
<NoteEditDialog
*>(&menu
);
213 createnote
->trigger();
214 noteedit
= qFindChild
<NoteEditDialog
*>(&menu
);
216 Akonadi::NoteUtils::NoteMessageWrapper
note(noteedit
->note());
217 QCOMPARE(note
.title(), summary
);
218 QCOMPARE(note
.text(), description
);
219 QCOMPARE(note
.attachments().count(), 1);
220 QCOMPARE(note
.attachments().at(0).mimetype(), KCalCore::Todo::todoMimeType());
221 QCOMPARE(note
.attachments().at(0).url(), (QUrl
)item
.url());
222 QCOMPARE(note
.attachments().at(0).data(), QByteArray());
225 void KoEventPopupMenuTest::defaultMenuEventVisible()
227 Akonadi::ETMCalendar::Ptr
calendar(new Akonadi::ETMCalendar());
228 KOEventPopupMenu
menu(0);
230 KCalCore::Event::Ptr
event(new KCalCore::Event());
232 item
.setMimeType(KCalCore::Event::eventMimeType());
233 item
.setPayload
<KCalCore::Event::Ptr
>(event
);
235 menu
.setCalendar(calendar
);
236 menu
.showIncidencePopup(item
, QDate());
237 QAction
*createevent
= menu
.findChild
<QAction
*>(QStringLiteral("createevent"));
238 QAction
*createnote
= menu
.findChild
<QAction
*>(QStringLiteral("createnote"));
239 QAction
*createtodo
= menu
.findChild
<QAction
*>(QStringLiteral("createtodo"));
240 QVERIFY(!createevent
->isVisible());
241 QVERIFY(createnote
->isVisible());
242 QVERIFY(createtodo
->isVisible());
245 void KoEventPopupMenuTest::defaultMenuTodoVisible()
247 Akonadi::ETMCalendar::Ptr
calendar(new Akonadi::ETMCalendar());
248 KOEventPopupMenu
menu(0);
250 KCalCore::Todo::Ptr
todo(new KCalCore::Todo());
253 item
.setMimeType(KCalCore::Todo::todoMimeType());
254 item
.setPayload
<KCalCore::Todo::Ptr
>(todo
);
256 menu
.setCalendar(calendar
);
257 menu
.showIncidencePopup(item
, QDate());
258 QAction
*createevent
= menu
.findChild
<QAction
*>(QStringLiteral("createevent"));
259 QAction
*createnote
= menu
.findChild
<QAction
*>(QStringLiteral("createnote"));
260 QAction
*createtodo
= menu
.findChild
<QAction
*>(QStringLiteral("createtodo"));
261 QVERIFY(createevent
->isVisible());
262 QVERIFY(createnote
->isVisible());
263 QVERIFY(!createtodo
->isVisible());
266 QTEST_MAIN(KoEventPopupMenuTest
)