1 /*
2 SPDX-FileCopyrightText: 2014-2021 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "todoedittest.h"
8 #include "../createtodoplugin/todoedit.h"
9 #include "globalsettings_messageviewer.h"
10 #include <Akonadi/Collection>
11 #include <Akonadi/CollectionComboBox>
12 #include <Akonadi/EntityTreeModel>
13 #include <KMessageWidget>
14 #include <QPushButton>
15 #include <QStandardItemModel>
16 #include <QTest>
17 #include <qtestkeyboard.h>
18 #include <qtestmouse.h>
19
20 #include <QLineEdit>
21 #include <QShortcut>
22 #include <QSignalSpy>
23
24 namespace MessageViewer
25 {
26 extern MESSAGEVIEWER_EXPORT QAbstractItemModel *_k_todoEditStubModel;
27 }
28
TodoEditTest()29 TodoEditTest::TodoEditTest()
30 {
31 qRegisterMetaType<Akonadi::Collection>();
32 qRegisterMetaType<KMime::Message::Ptr>();
33 qRegisterMetaType<KCalendarCore::Todo::Ptr>();
34 QStandardPaths::setTestModeEnabled(true);
35
36 auto model = new QStandardItemModel;
37 for (int id = 42; id < 51; ++id) {
38 Akonadi::Collection collection(id);
39 collection.setRights(Akonadi::Collection::AllRights);
40 collection.setName(QString::number(id));
41 collection.setContentMimeTypes(QStringList() << KCalendarCore::Todo::todoMimeType());
42
43 auto item = new QStandardItem(collection.name());
44 item->setData(QVariant::fromValue(collection), Akonadi::EntityTreeModel::CollectionRole);
45 item->setData(QVariant::fromValue(collection.id()), Akonadi::EntityTreeModel::CollectionIdRole);
46
47 model->appendRow(item);
48 }
49 MessageViewer::_k_todoEditStubModel = model;
50
51 // Fake a default-selected collection for shouldHaveDefaultValuesOnCreation test
52 MessageViewer::MessageViewerSettingsBase::self()->setLastSelectedFolder(43);
53 }
54
shouldHaveDefaultValuesOnCreation()55 void TodoEditTest::shouldHaveDefaultValuesOnCreation()
56 {
57 MessageViewer::TodoEdit edit;
58 QVERIFY(edit.collection().isValid());
59 QVERIFY(!edit.message());
60 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
61 auto openEditor = edit.findChild<QPushButton *>(QStringLiteral("open-editor-button"));
62 auto save = edit.findChild<QPushButton *>(QStringLiteral("save-button"));
63 QVERIFY(openEditor);
64 QVERIFY(save);
65 QCOMPARE(openEditor->isEnabled(), false);
66 QCOMPARE(save->isEnabled(), false);
67 QVERIFY(noteedit);
68 QCOMPARE(noteedit->text(), QString());
69 }
70
shouldEmitCollectionChanged()71 void TodoEditTest::shouldEmitCollectionChanged()
72 {
73 MessageViewer::TodoEdit edit;
74 QSignalSpy spy(&edit, &MessageViewer::TodoEdit::collectionChanged);
75 edit.setCollection(Akonadi::Collection(42));
76 QCOMPARE(spy.count(), 1);
77 QCOMPARE(spy.at(0).at(0).value<Akonadi::Collection>(), Akonadi::Collection(42));
78 }
79
shouldEmitMessageChanged()80 void TodoEditTest::shouldEmitMessageChanged()
81 {
82 MessageViewer::TodoEdit edit;
83 QSignalSpy spy(&edit, &MessageViewer::TodoEdit::messageChanged);
84 KMime::Message::Ptr msg(new KMime::Message);
85 edit.setMessage(msg);
86 QCOMPARE(spy.count(), 1);
87 QCOMPARE(spy.at(0).at(0).value<KMime::Message::Ptr>(), msg);
88 }
89
shouldNotEmitWhenCollectionIsNotChanged()90 void TodoEditTest::shouldNotEmitWhenCollectionIsNotChanged()
91 {
92 MessageViewer::TodoEdit edit;
93 edit.setCollection(Akonadi::Collection(42));
94 QSignalSpy spy(&edit, &MessageViewer::TodoEdit::collectionChanged);
95 edit.setCollection(Akonadi::Collection(42));
96 QCOMPARE(spy.count(), 0);
97 }
98
shouldNotEmitWhenMessageIsNotChanged()99 void TodoEditTest::shouldNotEmitWhenMessageIsNotChanged()
100 {
101 MessageViewer::TodoEdit edit;
102 KMime::Message::Ptr msg(new KMime::Message);
103 edit.setMessage(msg);
104 QSignalSpy spy(&edit, &MessageViewer::TodoEdit::messageChanged);
105 edit.setMessage(msg);
106 QCOMPARE(spy.count(), 0);
107 }
108
shouldHaveSameValueAfterSet()109 void TodoEditTest::shouldHaveSameValueAfterSet()
110 {
111 MessageViewer::TodoEdit edit;
112 KMime::Message::Ptr msg(new KMime::Message);
113 edit.setCollection(Akonadi::Collection(42));
114 edit.setMessage(msg);
115 QCOMPARE(edit.collection(), Akonadi::Collection(42));
116 QCOMPARE(edit.message(), msg);
117 }
118
shouldHaveASubject()119 void TodoEditTest::shouldHaveASubject()
120 {
121 MessageViewer::TodoEdit edit;
122 KMime::Message::Ptr msg(new KMime::Message);
123
124 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
125 QVERIFY(noteedit);
126 QCOMPARE(noteedit->text(), QString());
127
128 QString subject = QStringLiteral("Test Note");
129 msg->subject(true)->fromUnicodeString(subject, "us-ascii");
130 edit.setMessage(msg);
131 edit.showToDoWidget();
132
133 QCOMPARE(noteedit->text(), QStringLiteral("Reply to \"%1\"").arg(subject));
134 }
135
shouldEmptySubjectWhenMessageIsNull()136 void TodoEditTest::shouldEmptySubjectWhenMessageIsNull()
137 {
138 MessageViewer::TodoEdit edit;
139 KMime::Message::Ptr msg(new KMime::Message);
140 QString subject = QStringLiteral("Test Note");
141 msg->subject(true)->fromUnicodeString(subject, "us-ascii");
142 edit.setMessage(msg);
143 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
144 edit.setMessage(KMime::Message::Ptr());
145 QCOMPARE(noteedit->text(), QString());
146 }
147
shouldEmptySubjectWhenMessageHasNotSubject()148 void TodoEditTest::shouldEmptySubjectWhenMessageHasNotSubject()
149 {
150 MessageViewer::TodoEdit edit;
151 KMime::Message::Ptr msg(new KMime::Message);
152 QString subject = QStringLiteral("Test Note");
153 msg->subject(true)->fromUnicodeString(subject, "us-ascii");
154 edit.setMessage(msg);
155 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
156 KMime::Message::Ptr msgSubjectEmpty(new KMime::Message);
157 edit.setMessage(msgSubjectEmpty);
158 QCOMPARE(noteedit->text(), QString());
159 }
160
shouldSelectLineWhenPutMessage()161 void TodoEditTest::shouldSelectLineWhenPutMessage()
162 {
163 MessageViewer::TodoEdit edit;
164 KMime::Message::Ptr msg(new KMime::Message);
165 QString subject = QStringLiteral("Test Note");
166 msg->subject(true)->fromUnicodeString(subject, "us-ascii");
167 edit.setMessage(msg);
168 edit.showToDoWidget();
169 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
170 QVERIFY(noteedit->hasSelectedText());
171 const QString selectedText = noteedit->selectedText();
172 QCOMPARE(selectedText, QStringLiteral("Reply to \"%1\"").arg(subject));
173 }
174
shouldEmitCollectionChangedWhenChangeComboboxItem()175 void TodoEditTest::shouldEmitCollectionChangedWhenChangeComboboxItem()
176 {
177 MessageViewer::TodoEdit edit;
178 auto akonadicombobox = edit.findChild<Akonadi::CollectionComboBox *>(QStringLiteral("akonadicombobox"));
179 QVERIFY(akonadicombobox);
180 QVERIFY(akonadicombobox->currentCollection().isValid());
181 }
182
shouldEmitNotEmitTodoWhenTextIsEmpty()183 void TodoEditTest::shouldEmitNotEmitTodoWhenTextIsEmpty()
184 {
185 MessageViewer::TodoEdit edit;
186 KMime::Message::Ptr msg(new KMime::Message);
187 edit.setMessage(msg);
188 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
189 QSignalSpy spy(&edit, &MessageViewer::TodoEdit::createTodo);
190 QTest::keyClick(noteedit, Qt::Key_Enter);
191 QCOMPARE(spy.count(), 0);
192 }
193
shouldEmitNotEmitTodoWhenTextTrimmedIsEmpty()194 void TodoEditTest::shouldEmitNotEmitTodoWhenTextTrimmedIsEmpty()
195 {
196 MessageViewer::TodoEdit edit;
197 KMime::Message::Ptr msg(new KMime::Message);
198 edit.setMessage(msg);
199 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
200 QSignalSpy spy(&edit, &MessageViewer::TodoEdit::createTodo);
201 noteedit->setText(QStringLiteral(" "));
202 QTest::keyClick(noteedit, Qt::Key_Enter);
203 QCOMPARE(spy.count(), 0);
204
205 noteedit->setText(QStringLiteral(" F"));
206 QTest::keyClick(noteedit, Qt::Key_Enter);
207 QCOMPARE(spy.count(), 1);
208 }
209
shouldEmitTodoWhenPressEnter()210 void TodoEditTest::shouldEmitTodoWhenPressEnter()
211 {
212 MessageViewer::TodoEdit edit;
213 KMime::Message::Ptr msg(new KMime::Message);
214 QString subject = QStringLiteral("Test Note");
215 msg->subject(true)->fromUnicodeString(subject, "us-ascii");
216 edit.setMessage(msg);
217 edit.showToDoWidget();
218 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
219 QSignalSpy spy(&edit, &MessageViewer::TodoEdit::createTodo);
220 QTest::keyClick(noteedit, Qt::Key_Enter);
221 QCOMPARE(spy.count(), 1);
222 }
223
shouldTodoHasCorrectSubject()224 void TodoEditTest::shouldTodoHasCorrectSubject()
225 {
226 MessageViewer::TodoEdit edit;
227 KMime::Message::Ptr msg(new KMime::Message);
228 QString subject = QStringLiteral("Test Note");
229 msg->subject(true)->fromUnicodeString(subject, "us-ascii");
230 edit.setMessage(msg);
231 edit.showToDoWidget();
232 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
233 QSignalSpy spy(&edit, &MessageViewer::TodoEdit::createTodo);
234 QTest::keyClick(noteedit, Qt::Key_Enter);
235 QCOMPARE(spy.count(), 1);
236 auto todoPtr = spy.at(0).at(0).value<KCalendarCore::Todo::Ptr>();
237 QVERIFY(todoPtr);
238 QCOMPARE(todoPtr->summary(), QStringLiteral("Reply to \"%1\"").arg(subject));
239 }
240
shouldClearAllWhenCloseWidget()241 void TodoEditTest::shouldClearAllWhenCloseWidget()
242 {
243 MessageViewer::TodoEdit edit;
244 edit.show();
245 qApp->setActiveWindow(&edit);
246 QVERIFY(QTest::qWaitForWindowExposed(&edit));
247
248 KMime::Message::Ptr msg(new KMime::Message);
249 QString subject = QStringLiteral("Test Note");
250 msg->subject(true)->fromUnicodeString(subject, "us-ascii");
251 edit.setMessage(msg);
252
253 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
254 edit.slotCloseWidget();
255 QCOMPARE(noteedit->text(), QString());
256 QVERIFY(!edit.message());
257 }
258
shouldEmitCollectionChangedWhenCurrentCollectionWasChanged()259 void TodoEditTest::shouldEmitCollectionChangedWhenCurrentCollectionWasChanged()
260 {
261 MessageViewer::TodoEdit edit;
262 auto akonadicombobox = edit.findChild<Akonadi::CollectionComboBox *>(QStringLiteral("akonadicombobox"));
263 akonadicombobox->setCurrentIndex(0);
264 QCOMPARE(akonadicombobox->currentIndex(), 0);
265 QSignalSpy spy(&edit, &MessageViewer::TodoEdit::collectionChanged);
266 akonadicombobox->setCurrentIndex(3);
267 QCOMPARE(akonadicombobox->currentIndex(), 3);
268 QCOMPARE(spy.count(), 1);
269 }
270
shouldEmitCorrectCollection()271 void TodoEditTest::shouldEmitCorrectCollection()
272 {
273 MessageViewer::TodoEdit edit;
274 auto akonadicombobox = edit.findChild<Akonadi::CollectionComboBox *>(QStringLiteral("akonadicombobox"));
275 KMime::Message::Ptr msg(new KMime::Message);
276 QString subject = QStringLiteral("Test Note");
277 msg->subject(true)->fromUnicodeString(subject, "us-ascii");
278 edit.setMessage(msg);
279 edit.showToDoWidget();
280 akonadicombobox->setCurrentIndex(3);
281 Akonadi::Collection col = akonadicombobox->currentCollection();
282 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
283 QSignalSpy spy(&edit, &MessageViewer::TodoEdit::createTodo);
284 QTest::keyClick(noteedit, Qt::Key_Enter);
285 QCOMPARE(spy.count(), 1);
286 QCOMPARE(spy.at(0).at(1).value<Akonadi::Collection>(), col);
287 }
288
shouldHideWidgetWhenClickOnCloseButton()289 void TodoEditTest::shouldHideWidgetWhenClickOnCloseButton()
290 {
291 MessageViewer::TodoEdit edit;
292 edit.show();
293 QVERIFY(QTest::qWaitForWindowExposed(&edit));
294 QVERIFY(edit.isVisible());
295 auto close = edit.findChild<QPushButton *>(QStringLiteral("close-button"));
296 QTest::mouseClick(close, Qt::LeftButton);
297 QCOMPARE(edit.isVisible(), false);
298 }
299
shouldHideWidgetWhenPressEscape()300 void TodoEditTest::shouldHideWidgetWhenPressEscape()
301 {
302 MessageViewer::TodoEdit edit;
303 edit.show();
304 // make sure the window is active so we can test for focus
305 qApp->setActiveWindow(&edit);
306 QVERIFY(QTest::qWaitForWindowExposed(&edit));
307 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
308 noteedit->setFocus();
309 QVERIFY(noteedit->hasFocus());
310 QTest::keyPress(&edit, Qt::Key_Escape);
311 QCOMPARE(edit.isVisible(), false);
312 }
313
shouldHideWidgetWhenSaveClicked()314 void TodoEditTest::shouldHideWidgetWhenSaveClicked()
315 {
316 MessageViewer::TodoEdit edit;
317 edit.show();
318 QVERIFY(QTest::qWaitForWindowExposed(&edit));
319
320 KMime::Message::Ptr msg(new KMime::Message);
321 msg->subject(true)->fromUnicodeString(QStringLiteral("Test Note"), "us-ascii");
322 edit.setMessage(msg);
323 auto save = edit.findChild<QPushButton *>(QStringLiteral("save-button"));
324 QTest::mouseClick(save, Qt::LeftButton);
325 QCOMPARE(edit.isVisible(), true);
326 }
327
shouldSaveCollectionSettings()328 void TodoEditTest::shouldSaveCollectionSettings()
329 {
330 MessageViewer::TodoEdit edit;
331 auto akonadicombobox = edit.findChild<Akonadi::CollectionComboBox *>(QStringLiteral("akonadicombobox"));
332 akonadicombobox->setCurrentIndex(3);
333 const Akonadi::Collection::Id id = akonadicombobox->currentCollection().id();
334 auto close = edit.findChild<QPushButton *>(QStringLiteral("close-button"));
335 QTest::mouseClick(close, Qt::LeftButton);
336 QCOMPARE(MessageViewer::MessageViewerSettingsBase::self()->lastSelectedFolder(), id);
337 }
338
shouldSaveCollectionSettingsWhenCloseWidget()339 void TodoEditTest::shouldSaveCollectionSettingsWhenCloseWidget()
340 {
341 MessageViewer::TodoEdit edit;
342 auto akonadicombobox = edit.findChild<Akonadi::CollectionComboBox *>(QStringLiteral("akonadicombobox"));
343 akonadicombobox->setCurrentIndex(4);
344 const Akonadi::Collection::Id id = akonadicombobox->currentCollection().id();
345 edit.writeConfig();
346 QCOMPARE(MessageViewer::MessageViewerSettingsBase::self()->lastSelectedFolder(), id);
347 }
348
shouldSaveCollectionSettingsWhenDeleteWidget()349 void TodoEditTest::shouldSaveCollectionSettingsWhenDeleteWidget()
350 {
351 auto edit = new MessageViewer::TodoEdit;
352 auto akonadicombobox = edit->findChild<Akonadi::CollectionComboBox *>(QStringLiteral("akonadicombobox"));
353 akonadicombobox->setCurrentIndex(4);
354 const Akonadi::Collection::Id id = akonadicombobox->currentCollection().id();
355 delete edit;
356 QCOMPARE(MessageViewer::MessageViewerSettingsBase::self()->lastSelectedFolder(), id);
357 }
358
shouldSetFocusWhenWeCallTodoEdit()359 void TodoEditTest::shouldSetFocusWhenWeCallTodoEdit()
360 {
361 MessageViewer::TodoEdit edit;
362 edit.show();
363 // make sure the window is active so we can test for focus
364 qApp->setActiveWindow(&edit);
365 QVERIFY(QTest::qWaitForWindowExposed(&edit));
366 KMime::Message::Ptr msg(new KMime::Message);
367 QString subject = QStringLiteral("Test Note");
368 msg->subject(true)->fromUnicodeString(subject, "us-ascii");
369 edit.setMessage(msg);
370 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
371 QCOMPARE(noteedit->hasFocus(), true);
372 edit.setFocus();
373 QCOMPARE(noteedit->hasFocus(), false);
374 edit.showToDoWidget();
375 QCOMPARE(noteedit->hasFocus(), true);
376 }
377
shouldNotEmitTodoWhenMessageIsNull()378 void TodoEditTest::shouldNotEmitTodoWhenMessageIsNull()
379 {
380 MessageViewer::TodoEdit edit;
381 QString subject = QStringLiteral("Test Note");
382 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
383 noteedit->setText(subject);
384 QSignalSpy spy(&edit, &MessageViewer::TodoEdit::createTodo);
385 QTest::keyClick(noteedit, Qt::Key_Enter);
386 QCOMPARE(spy.count(), 0);
387 }
388
shouldClearLineAfterEmitNewNote()389 void TodoEditTest::shouldClearLineAfterEmitNewNote()
390 {
391 MessageViewer::TodoEdit edit;
392 KMime::Message::Ptr msg(new KMime::Message);
393 QString subject = QStringLiteral("Test Note");
394 msg->subject(true)->fromUnicodeString(subject, "us-ascii");
395 edit.setMessage(msg);
396 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
397 QTest::keyClick(noteedit, Qt::Key_Enter);
398 QCOMPARE(noteedit->text(), QString());
399 }
400
shouldHaveLineEditFocus()401 void TodoEditTest::shouldHaveLineEditFocus()
402 {
403 MessageViewer::TodoEdit edit;
404 edit.show();
405 // make sure the window is active so we can test for focus
406 qApp->setActiveWindow(&edit);
407 QVERIFY(QTest::qWaitForWindowExposed(&edit));
408 KMime::Message::Ptr msg(new KMime::Message);
409 QString subject = QStringLiteral("Test Note");
410 msg->subject(true)->fromUnicodeString(subject, "us-ascii");
411 edit.setMessage(msg);
412 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
413 QCOMPARE(noteedit->hasFocus(), true);
414 }
415
shouldShowMessageWidget()416 void TodoEditTest::shouldShowMessageWidget()
417 {
418 MessageViewer::TodoEdit edit;
419 edit.show();
420 QVERIFY(QTest::qWaitForWindowExposed(&edit));
421
422 KMime::Message::Ptr msg(new KMime::Message);
423 msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii");
424 edit.setMessage(msg);
425 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
426 noteedit->setText(QStringLiteral("Test Note"));
427 auto msgwidget = edit.findChild<KMessageWidget *>(QStringLiteral("msgwidget"));
428 QCOMPARE(msgwidget->isVisible(), false);
429 QTest::keyClick(noteedit, Qt::Key_Enter);
430 QCOMPARE(msgwidget->isVisible(), true);
431 }
432
shouldHideMessageWidget()433 void TodoEditTest::shouldHideMessageWidget()
434 {
435 MessageViewer::TodoEdit edit;
436 edit.show();
437 QVERIFY(QTest::qWaitForWindowExposed(&edit));
438 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
439 noteedit->setText(QStringLiteral("Test note"));
440
441 KMime::Message::Ptr msg(new KMime::Message);
442 msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii");
443 edit.setMessage(msg);
444 auto msgwidget = edit.findChild<KMessageWidget *>(QStringLiteral("msgwidget"));
445 msgwidget->show();
446 QCOMPARE(msgwidget->isVisible(), true);
447 noteedit->setText(QStringLiteral("Another note"));
448 QCOMPARE(msgwidget->isVisible(), false);
449 }
450
shouldHideMessageWidgetWhenAddNewMessage()451 void TodoEditTest::shouldHideMessageWidgetWhenAddNewMessage()
452 {
453 MessageViewer::TodoEdit edit;
454 edit.show();
455 QVERIFY(QTest::qWaitForWindowExposed(&edit));
456
457 KMime::Message::Ptr msg(new KMime::Message);
458 msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii");
459 edit.setMessage(msg);
460 edit.showToDoWidget();
461 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
462 noteedit->setText(QStringLiteral("Test Note"));
463 auto msgwidget = edit.findChild<KMessageWidget *>(QStringLiteral("msgwidget"));
464 QTest::keyClick(noteedit, Qt::Key_Enter);
465 QCOMPARE(msgwidget->isVisible(), true);
466
467 KMime::Message::Ptr msg2(new KMime::Message);
468 msg2->subject(true)->fromUnicodeString(QStringLiteral("Test note 2"), "us-ascii");
469 edit.setMessage(msg2);
470 edit.showToDoWidget();
471 QCOMPARE(msgwidget->isVisible(), false);
472 }
473
shouldHideMessageWidgetWhenCloseWidget()474 void TodoEditTest::shouldHideMessageWidgetWhenCloseWidget()
475 {
476 MessageViewer::TodoEdit edit;
477 edit.show();
478 QVERIFY(QTest::qWaitForWindowExposed(&edit));
479
480 KMime::Message::Ptr msg(new KMime::Message);
481 msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii");
482 edit.setMessage(msg);
483 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
484 noteedit->setText(QStringLiteral("Test Note"));
485 auto msgwidget = edit.findChild<KMessageWidget *>(QStringLiteral("msgwidget"));
486 QTest::keyClick(noteedit, Qt::Key_Enter);
487 QCOMPARE(msgwidget->isVisible(), true);
488 edit.slotCloseWidget();
489
490 QCOMPARE(msgwidget->isHidden(), true);
491 }
492
shouldEnabledSaveOpenEditorButton()493 void TodoEditTest::shouldEnabledSaveOpenEditorButton()
494 {
495 MessageViewer::TodoEdit edit;
496 KMime::Message::Ptr msg(new KMime::Message);
497 msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii");
498 edit.setMessage(msg);
499 edit.showToDoWidget();
500
501 auto noteedit = edit.findChild<QLineEdit *>(QStringLiteral("noteedit"));
502 auto openEditor = edit.findChild<QPushButton *>(QStringLiteral("open-editor-button"));
503 auto save = edit.findChild<QPushButton *>(QStringLiteral("save-button"));
504 QCOMPARE(openEditor->isEnabled(), true);
505 QCOMPARE(save->isEnabled(), true);
506 noteedit->clear();
507
508 QCOMPARE(openEditor->isEnabled(), false);
509 QCOMPARE(save->isEnabled(), false);
510 noteedit->setText(QStringLiteral("test 2"));
511 QCOMPARE(openEditor->isEnabled(), true);
512 QCOMPARE(save->isEnabled(), true);
513
514 noteedit->setText(QStringLiteral(" "));
515 QCOMPARE(openEditor->isEnabled(), false);
516 QCOMPARE(save->isEnabled(), false);
517
518 noteedit->setText(QStringLiteral(" foo"));
519 QCOMPARE(openEditor->isEnabled(), true);
520 QCOMPARE(save->isEnabled(), true);
521 }
522
shouldDisabledSaveOpenEditorButtonWhenCollectionComboBoxIsEmpty()523 void TodoEditTest::shouldDisabledSaveOpenEditorButtonWhenCollectionComboBoxIsEmpty()
524 {
525 MessageViewer::TodoEdit edit;
526 auto akonadicombobox = edit.findChild<Akonadi::CollectionComboBox *>(QStringLiteral("akonadicombobox"));
527 // Create an empty combobox
528 akonadicombobox->setModel(new QStandardItemModel());
529
530 KMime::Message::Ptr msg(new KMime::Message);
531 msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii");
532 edit.setMessage(msg);
533
534 auto openEditor = edit.findChild<QPushButton *>(QStringLiteral("open-editor-button"));
535 auto save = edit.findChild<QPushButton *>(QStringLiteral("save-button"));
536 QCOMPARE(openEditor->isEnabled(), false);
537 QCOMPARE(save->isEnabled(), false);
538 }
539
540 QTEST_MAIN(TodoEditTest)
541