diff --git a/examples/apps/etm_usage/entitytreewidget.cpp b/examples/apps/etm_usage/entitytreewidget.cpp index 104b07bd..ad5666ea 100644 --- a/examples/apps/etm_usage/entitytreewidget.cpp +++ b/examples/apps/etm_usage/entitytreewidget.cpp @@ -1,167 +1,167 @@ /* Copyright (c) 2010 Stephen Kelly This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // READ THE README FILE #include "entitytreewidget.h" #include #include #include #include #include #include #include using namespace Akonadi; static const QString predefinedMimeTypes[] = { QLatin1String(""), QLatin1String("message/rfc822"), QLatin1String("text/directory"), QLatin1String("text/calendar"), QLatin1String("message/rfc822,text/directory") }; static const QString predefinedUserVisibleMimeTypes[] = { QLatin1String("All"), QLatin1String("Email"), QLatin1String("Addressees"), QLatin1String("Events"), QLatin1String("Email and Addressees") }; EntityTreeWidget::EntityTreeWidget(QWidget *parent) : QWidget(parent) , m_treeView(new QTreeView) , m_typeComboBox(new QComboBox) , m_typeLineEdit(new QLineEdit) , m_monitor(new Monitor(this)) { for (uint i = 0; i < sizeof predefinedMimeTypes / sizeof *predefinedMimeTypes; ++i) { m_typeComboBox->addItem(predefinedUserVisibleMimeTypes[i], predefinedMimeTypes[i]); } QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(m_typeComboBox); layout->addWidget(m_typeLineEdit); layout->addWidget(m_treeView); m_monitor->setCollectionMonitored(Collection::root()); m_monitor->fetchCollection(true); m_monitor->setAllMonitored(true); m_monitor->itemFetchScope().fetchFullPayload(true); m_monitor->itemFetchScope().fetchAllAttributes(true); m_treeView->setSelectionMode(QAbstractItemView::ExtendedSelection); } EntityTreeWidget::~EntityTreeWidget() { } void EntityTreeWidget::connectTreeToModel(QTreeView *tree, EntityTreeModel *model) { tree->setModel(model); } void EntityTreeWidget::mimeTypesChoiceChanged(int index) { m_typeLineEdit->setText(m_typeComboBox->itemData(index).toString()); } void EntityTreeWidget::mimeTypesChanged(const QString &mimetypeList) { const QStringList list = mimetypeList.isEmpty() ? QStringList() : mimetypeList.split(QStringLiteral(",")); const auto listMimetypes = m_monitor->mimeTypesMonitored(); - for (const QString mimetype : listMimetypes) { + for (const QString &mimetype : listMimetypes) { if (!list.contains(mimetype)) { m_monitor->setMimeTypeMonitored(mimetype, false); } } for (const QString &mimetype : list) { m_monitor->setMimeTypeMonitored(mimetype, true); } } QTreeView *EntityTreeWidget::view() const { return m_treeView; } EntityTreeModel *EntityTreeWidget::model() const { return m_etm; } void EntityTreeWidget::init() { if (m_treeView->model()) { return; // Already set up } m_etm = getETM(); connectTreeToModel(m_treeView, m_etm); connect(m_typeComboBox, SIGNAL(currentIndexChanged(int)), SLOT(mimeTypesChoiceChanged(int))); connect(m_typeLineEdit, &QLineEdit::textChanged, this, &EntityTreeWidget::mimeTypesChanged); } Akonadi::Monitor *EntityTreeWidget::monitor() const { return m_monitor; } EntityTreeModel *EntityTreeWidget::getETM() { return new EntityTreeModel(m_monitor, this); } static int num; void EntityTreeWidget::dumpTree() { num = 1; qDebug() << dumpLevel(QModelIndex(), 1); } QString EntityTreeWidget::dumpLevel(const QModelIndex &parent, int level) { const int rowCount = m_etm->rowCount(parent); QString lines; for (int row = 0; row < rowCount; ++row) { QString line; line.append(QLatin1String("\"")); for (int l = 0; l < level; ++l) { line.append(QLatin1String("- ")); } line.append(QString::number(num++)); line.append(QLatin1String("\"")); line.append(QLatin1String("\n")); lines.append(line); // qDebug() << line; static const int column = 0; const QModelIndex idx = m_etm->index(row, column, parent); if (m_etm->hasChildren(idx)) { lines.append(dumpLevel(idx, level + 1)); } } return lines; } diff --git a/kmail/plugins/antispamplugin/autotests/antispamplugininterfacetest.cpp b/kmail/plugins/antispamplugin/autotests/antispamplugininterfacetest.cpp index c3b111b0..0b0d55aa 100644 --- a/kmail/plugins/antispamplugin/autotests/antispamplugininterfacetest.cpp +++ b/kmail/plugins/antispamplugin/autotests/antispamplugininterfacetest.cpp @@ -1,60 +1,60 @@ /* Copyright (C) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "antispamplugininterfacetest.h" #include "../antispamplugininterface.h" #include #include #include AntiSpamPluginInterfaceTest::AntiSpamPluginInterfaceTest(QObject *parent) : QObject(parent) { } AntiSpamPluginInterfaceTest::~AntiSpamPluginInterfaceTest() { } void AntiSpamPluginInterfaceTest::shouldHaveDefaultValue() { AntiSpamPluginInterface interface; QVERIFY(!interface.parentWidget()); QVERIFY(!interface.actionTypes().at(0).action()); } void AntiSpamPluginInterfaceTest::shouldCreateAction() { AntiSpamPluginInterface interface; interface.createAction(new KActionCollection(this)); QCOMPARE(interface.actionTypes().count(), 1); QVERIFY(interface.actionTypes().at(0).action()); } void AntiSpamPluginInterfaceTest::shouldEmitActivatedSignal() { AntiSpamPluginInterface interface; interface.createAction(new KActionCollection(this)); - QSignalSpy spy1(&interface, SIGNAL(emitPluginActivated(PimCommon::AbstractGenericPluginInterface*))); + QSignalSpy spy1(&interface, &PimCommon::AbstractGenericPluginInterface::emitPluginActivated); interface.actionTypes().at(0).action()->trigger(); QCOMPARE(spy1.count(), 1); } QTEST_MAIN(AntiSpamPluginInterfaceTest) diff --git a/kmail/plugins/antivirusplugin/autotests/antivirusplugininterfacetest.cpp b/kmail/plugins/antivirusplugin/autotests/antivirusplugininterfacetest.cpp index 3ac0cefb..16c037e9 100644 --- a/kmail/plugins/antivirusplugin/autotests/antivirusplugininterfacetest.cpp +++ b/kmail/plugins/antivirusplugin/autotests/antivirusplugininterfacetest.cpp @@ -1,60 +1,60 @@ /* Copyright (C) 2015-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "antivirusplugininterfacetest.h" #include "../antivirusplugininterface.h" #include #include #include AntiVirusPluginInterfaceTest::AntiVirusPluginInterfaceTest(QObject *parent) : QObject(parent) { } AntiVirusPluginInterfaceTest::~AntiVirusPluginInterfaceTest() { } void AntiVirusPluginInterfaceTest::shouldHaveDefaultValue() { AntiVirusPluginInterface interface; QVERIFY(!interface.parentWidget()); QCOMPARE(interface.actionTypes().count(), 0); } void AntiVirusPluginInterfaceTest::shouldCreateAction() { AntiVirusPluginInterface interface; interface.createAction(new KActionCollection(this)); QCOMPARE(interface.actionTypes().count(), 1); QVERIFY(interface.actionTypes().at(0).action()); } void AntiVirusPluginInterfaceTest::shouldEmitActivatedSignal() { AntiVirusPluginInterface interface; interface.createAction(new KActionCollection(this)); - QSignalSpy spy1(&interface, SIGNAL(emitPluginActivated(PimCommon::AbstractGenericPluginInterface*))); + QSignalSpy spy1(&interface, &PimCommon::AbstractGenericPluginInterface::emitPluginActivated); interface.actionTypes().at(0).action()->trigger(); QCOMPARE(spy1.count(), 1); } QTEST_MAIN(AntiVirusPluginInterfaceTest) diff --git a/kmail/plugins/logactivitiesplugin/autotests/logactivitiesplugininterfacetest.cpp b/kmail/plugins/logactivitiesplugin/autotests/logactivitiesplugininterfacetest.cpp index 07c45f85..21e057a7 100644 --- a/kmail/plugins/logactivitiesplugin/autotests/logactivitiesplugininterfacetest.cpp +++ b/kmail/plugins/logactivitiesplugin/autotests/logactivitiesplugininterfacetest.cpp @@ -1,61 +1,61 @@ /* Copyright (C) 2017-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "logactivitiesplugininterfacetest.h" #include "../logactivitiesplugininterface.h" #include #include #include LogActivitiesPluginInterfaceTest::LogActivitiesPluginInterfaceTest(QObject *parent) : QObject(parent) { } LogActivitiesPluginInterfaceTest::~LogActivitiesPluginInterfaceTest() { } void LogActivitiesPluginInterfaceTest::shouldHaveDefaultValue() { LogActivitiesPluginInterface interface; interface.createAction(new KActionCollection(this)); QVERIFY(!interface.parentWidget()); QCOMPARE(interface.actionTypes().count(), 1); QVERIFY(interface.actionTypes().at(0).action()); } void LogActivitiesPluginInterfaceTest::shouldCreateAction() { LogActivitiesPluginInterface interface; interface.createAction(new KActionCollection(this)); QVERIFY(interface.actionTypes().at(0).action()); } void LogActivitiesPluginInterfaceTest::shouldEmitActivatedSignal() { LogActivitiesPluginInterface interface; interface.createAction(new KActionCollection(this)); - QSignalSpy spy1(&interface, SIGNAL(emitPluginActivated(PimCommon::AbstractGenericPluginInterface*))); + QSignalSpy spy1(&interface, &PimCommon::AbstractGenericPluginInterface::emitPluginActivated); interface.actionTypes().at(0).action()->trigger(); QCOMPARE(spy1.count(), 1); } QTEST_MAIN(LogActivitiesPluginInterfaceTest) diff --git a/plugins/messageviewerplugins/autotests/eventdatetimewidgettest.cpp b/plugins/messageviewerplugins/autotests/eventdatetimewidgettest.cpp index b52afc07..bcd5b3b2 100644 --- a/plugins/messageviewerplugins/autotests/eventdatetimewidgettest.cpp +++ b/plugins/messageviewerplugins/autotests/eventdatetimewidgettest.cpp @@ -1,110 +1,110 @@ /* Copyright (C) 2014-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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; see the file COPYING. 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 #include #include #include EventDateTimeWidgetTest::EventDateTimeWidgetTest(QObject *parent) : QObject(parent) { } EventDateTimeWidgetTest::~EventDateTimeWidgetTest() { } void EventDateTimeWidgetTest::shouldHaveDefaultValue() { MessageViewer::EventDateTimeWidget edit; KDateComboBox *datecombobox = edit.findChild(QStringLiteral("eventdatecombobox")); QVERIFY(datecombobox); KTimeComboBox *timecombobox = edit.findChild(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))); + QSignalSpy spy(&edit, &MessageViewer::EventDateTimeWidget::dateTimeChanged); 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))); + QSignalSpy spy(&edit, &MessageViewer::EventDateTimeWidget::dateTimeChanged); 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))); + QSignalSpy spy(&edit, &MessageViewer::EventDateTimeWidget::dateTimeChanged); 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))); + QSignalSpy spy(&edit, &MessageViewer::EventDateTimeWidget::dateTimeChanged); 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) diff --git a/plugins/messageviewerplugins/autotests/eventedittest.cpp b/plugins/messageviewerplugins/autotests/eventedittest.cpp index c5ae8a56..5df0c339 100644 --- a/plugins/messageviewerplugins/autotests/eventedittest.cpp +++ b/plugins/messageviewerplugins/autotests/eventedittest.cpp @@ -1,446 +1,446 @@ /* Copyright (C) 2014-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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; see the file COPYING. 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 #include #include #include #include #include #include #include #include #include #include #include namespace MessageViewer { extern MESSAGEVIEWER_EXPORT QAbstractItemModel *_k_eventEditStubModel; } EventEditTest::EventEditTest(QObject *parent) : QObject(parent) { qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); QStandardPaths::setTestModeEnabled(true); 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; // Fake a default-selected collection for shouldHaveDefaultValuesOnCreation test MessageViewer::MessageViewerSettingsBase::self()->setLastEventSelectedFolder(43); } void EventEditTest::shouldHaveDefaultValuesOnCreation() { MessageViewer::EventEdit edit; QVERIFY(edit.collection().isValid()); QVERIFY(!edit.message()); QLineEdit *eventedit = edit.findChild(QStringLiteral("eventedit")); QVERIFY(eventedit); QCOMPARE(eventedit->text(), QString()); QPushButton *openEditor = edit.findChild(QStringLiteral("open-editor-button")); QPushButton *save = edit.findChild(QStringLiteral("save-button")); QVERIFY(openEditor); QVERIFY(save); QCOMPARE(openEditor->isEnabled(), false); QCOMPARE(save->isEnabled(), false); QDateTime currentDateTime = QDateTime::currentDateTime(); MessageViewer::EventDateTimeWidget *startDateTime = edit.findChild(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(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))); + QSignalSpy spy(&edit, &MessageViewer::EventEdit::collectionChanged); edit.setCollection(Akonadi::Collection(42)); QCOMPARE(spy.count(), 1); QCOMPARE(spy.at(0).at(0).value(), Akonadi::Collection(42)); } void EventEditTest::shouldEmitMessageChanged() { MessageViewer::EventEdit edit; - QSignalSpy spy(&edit, SIGNAL(messageChanged(KMime::Message::Ptr))); + QSignalSpy spy(&edit, &MessageViewer::EventEdit::messageChanged); KMime::Message::Ptr msg(new KMime::Message); edit.setMessage(msg); QCOMPARE(spy.count(), 1); QCOMPARE(spy.at(0).at(0).value(), msg); } void EventEditTest::shouldNotEmitWhenCollectionIsNotChanged() { MessageViewer::EventEdit edit; edit.setCollection(Akonadi::Collection(42)); - QSignalSpy spy(&edit, SIGNAL(collectionChanged(Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::EventEdit::collectionChanged); 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))); + QSignalSpy spy(&edit, &MessageViewer::EventEdit::messageChanged); edit.setMessage(msg); QCOMPARE(spy.count(), 0); } void EventEditTest::shouldEmitEventWhenPressEnter() { MessageViewer::EventEdit edit; edit.show(); // make sure the window is active so we can test for focus qApp->setActiveWindow(&edit); QVERIFY(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(QStringLiteral("eventedit")); eventedit->setFocus(); - QSignalSpy spy(&edit, SIGNAL(createEvent(KCalCore::Event::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::EventEdit::createEvent); QTest::keyClick(eventedit, Qt::Key_Enter); QCOMPARE(spy.count(), 1); } void EventEditTest::shouldHideWidgetWhenPressEnter() { MessageViewer::EventEdit edit; edit.show(); QVERIFY(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(QStringLiteral("eventedit")); QTest::keyClick(eventedit, Qt::Key_Enter); QCOMPARE(edit.isVisible(), false); } void EventEditTest::shouldHideWidgetWhenPressEscape() { MessageViewer::EventEdit edit; edit.show(); // make sure the window is active so we can test for focus qApp->setActiveWindow(&edit); QVERIFY(QTest::qWaitForWindowExposed(&edit)); QLineEdit *eventedit = edit.findChild(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(); QVERIFY(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(QStringLiteral("save-button")); QTest::mouseClick(save, Qt::LeftButton); QCOMPARE(edit.isVisible(), false); } void EventEditTest::shouldSaveCollectionSettings() { MessageViewer::EventEdit edit; edit.show(); QVERIFY(QTest::qWaitForWindowExposed(&edit)); Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(QStringLiteral("akonadicombobox")); akonadicombobox->setCurrentIndex(3); const Akonadi::Collection::Id id = akonadicombobox->currentCollection().id(); QPushButton *close = edit.findChild(QStringLiteral("close-button")); QTest::mouseClick(close, Qt::LeftButton); QCOMPARE(MessageViewer::MessageViewerSettingsBase::self()->lastEventSelectedFolder(), id); } void EventEditTest::shouldSaveCollectionSettingsWhenCloseWidget() { MessageViewer::EventEdit edit; edit.show(); QVERIFY(QTest::qWaitForWindowExposed(&edit)); Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(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(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(QStringLiteral("startdatetimeedit")); startDateTime->setDateTime(QDateTime()); MessageViewer::EventDateTimeWidget *endDateTime = edit.findChild(QStringLiteral("enddatetimeedit")); endDateTime->setDateTime(QDateTime()); QString subject = QStringLiteral("Test Note"); msg->subject(true)->fromUnicodeString(subject, "us-ascii"); edit.setMessage(msg); QLineEdit *eventedit = edit.findChild(QStringLiteral("eventedit")); - QSignalSpy spy(&edit, SIGNAL(createEvent(KCalCore::Event::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::EventEdit::createEvent); 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(QStringLiteral("eventedit")); QVERIFY(noteedit); - QSignalSpy spy(&edit, SIGNAL(createEvent(KCalCore::Event::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::EventEdit::createEvent); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 1); KCalCore::Event::Ptr eventPtr = spy.at(0).at(0).value(); 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(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(QStringLiteral("startdatetimeedit")); startDateTime->setDateTime(currentDateTime); QDateTime endDt = currentDateTime.addDays(1); MessageViewer::EventDateTimeWidget *endDateTime = edit.findChild(QStringLiteral("enddatetimeedit")); endDateTime->setDateTime(endDt); QLineEdit *noteedit = edit.findChild(QStringLiteral("eventedit")); QVERIFY(noteedit); - QSignalSpy spy(&edit, SIGNAL(createEvent(KCalCore::Event::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::EventEdit::createEvent); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 1); KCalCore::Event::Ptr eventPtr = spy.at(0).at(0).value(); 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(); // make sure the window is active so we can test for focus qApp->setActiveWindow(&edit); QVERIFY(QTest::qWaitForWindowExposed(&edit)); QLineEdit *noteedit = edit.findChild(QStringLiteral("eventedit")); QVERIFY(noteedit); edit.setFocus(); edit.showEventEdit(); QVERIFY(noteedit->hasFocus()); } void EventEditTest::shouldEnsureEndDateIsNotBeforeStartDate() { MessageViewer::EventEdit edit; MessageViewer::EventDateTimeWidget *startDateTime = edit.findChild(QStringLiteral("startdatetimeedit")); MessageViewer::EventDateTimeWidget *endDateTime = edit.findChild(QStringLiteral("enddatetimeedit")); QDateTime startDt = startDateTime->dateTime(); QVERIFY(startDt < endDateTime->dateTime()); startDt.setTime(QTime(5, 12)); endDateTime->setDateTime(startDt.addSecs(3600)); startDt = startDt.addDays(1); startDateTime->setDateTime(startDt); QCOMPARE(startDt.date(), endDateTime->date()); QVERIFY(startDt.time() < endDateTime->time()); startDt = startDt.addSecs(2 * 3600); startDateTime->setDateTime(startDt); QCOMPARE(startDt.time(), endDateTime->time()); } void EventEditTest::shouldEnabledSaveOpenEditorButton() { MessageViewer::EventEdit edit; KMime::Message::Ptr msg(new KMime::Message); msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii"); edit.setMessage(msg); QLineEdit *noteedit = edit.findChild(QStringLiteral("eventedit")); QVERIFY(noteedit); QPushButton *openEditor = edit.findChild(QStringLiteral("open-editor-button")); QPushButton *save = edit.findChild(QStringLiteral("save-button")); QCOMPARE(openEditor->isEnabled(), true); QCOMPARE(save->isEnabled(), true); noteedit->clear(); QCOMPARE(openEditor->isEnabled(), false); QCOMPARE(save->isEnabled(), false); noteedit->setText(QStringLiteral(" ")); QCOMPARE(openEditor->isEnabled(), false); QCOMPARE(save->isEnabled(), false); noteedit->setText(QStringLiteral(" foo")); QCOMPARE(openEditor->isEnabled(), true); QCOMPARE(save->isEnabled(), true); } void EventEditTest::shouldUpdateStartEndDateWhenReopenIt() { MessageViewer::EventEdit edit; KMime::Message::Ptr msg(new KMime::Message); msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii"); edit.setMessage(msg); QDateTime currentDateTime = QDateTime::currentDateTime(); MessageViewer::EventDateTimeWidget *startDateTime = edit.findChild(QStringLiteral("startdatetimeedit")); 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(QStringLiteral("enddatetimeedit")); auto endTime = currentDateTime.addSecs(3600); QCOMPARE(endDateTime->dateTime().date(), endTime.date()); QCOMPARE(endDateTime->dateTime().time().hour(), endTime.time().hour()); QCOMPARE(endDateTime->dateTime().time().minute(), endTime.time().minute()); QDateTime newDateTime = currentDateTime; newDateTime = newDateTime.addSecs(60 * 60); //+1h startDateTime->setDateTime(newDateTime); endDateTime->setDateTime(newDateTime); QCOMPARE(startDateTime->dateTime().time().hour(), newDateTime.time().hour()); QCOMPARE(startDateTime->dateTime().time().minute(), newDateTime.time().minute()); QCOMPARE(startDateTime->dateTime().date(), newDateTime.date()); QCOMPARE(endDateTime->dateTime().time().hour(), newDateTime.time().hour()); QCOMPARE(endDateTime->dateTime().time().minute(), newDateTime.time().minute()); QCOMPARE(endDateTime->dateTime().date(), newDateTime.date()); edit.slotCloseWidget(); edit.showEventEdit(); QCOMPARE(startDateTime->dateTime().date(), currentDateTime.date()); QCOMPARE(startDateTime->dateTime().time().hour(), currentDateTime.time().hour()); QCOMPARE(startDateTime->dateTime().time().minute(), currentDateTime.time().minute()); QCOMPARE(endDateTime->dateTime().date(), endTime.date()); QCOMPARE(endDateTime->dateTime().time().hour(), endTime.time().hour()); QCOMPARE(endDateTime->dateTime().time().minute(), endTime.time().minute()); } void EventEditTest::shouldDisabledSaveOpenEditorButtonWhenCollectionComboBoxIsEmpty() { MessageViewer::EventEdit edit; Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(QStringLiteral("akonadicombobox")); //Create an empty combobox akonadicombobox->setModel(new QStandardItemModel()); KMime::Message::Ptr msg(new KMime::Message); msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii"); edit.setMessage(msg); QPushButton *openEditor = edit.findChild(QStringLiteral("open-editor-button")); QPushButton *save = edit.findChild(QStringLiteral("save-button")); QCOMPARE(openEditor->isEnabled(), false); QCOMPARE(save->isEnabled(), false); } QTEST_MAIN(EventEditTest) diff --git a/plugins/messageviewerplugins/autotests/noteedittest.cpp b/plugins/messageviewerplugins/autotests/noteedittest.cpp index 95925ea8..40ea6dde 100644 --- a/plugins/messageviewerplugins/autotests/noteedittest.cpp +++ b/plugins/messageviewerplugins/autotests/noteedittest.cpp @@ -1,433 +1,433 @@ /* Copyright (c) 2014 Sandro Knauß 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 "noteedittest.h" #include "globalsettings_messageviewer.h" #include "../createnoteplugin/noteedit.h" #include #include #include #include #include #include #include #include #include #include namespace MessageViewer { extern MESSAGEVIEWER_EXPORT QAbstractItemModel *_k_noteEditStubModel; } NoteEditTest::NoteEditTest() { qRegisterMetaType(); qRegisterMetaType(); QStandardPaths::setTestModeEnabled(true); 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() << Akonadi::NoteUtils::noteMimeType()); 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_noteEditStubModel = model; // Fake a default-selected collection for shouldHaveDefaultValuesOnCreation test MessageViewer::MessageViewerSettingsBase::self()->setLastNoteSelectedFolder(43); } void NoteEditTest::shouldHaveDefaultValuesOnCreation() { MessageViewer::NoteEdit edit; QVERIFY(edit.collection().isValid()); QVERIFY(!edit.message()); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); QPushButton *save = edit.findChild(QStringLiteral("save-button")); QVERIFY(save); QCOMPARE(save->isEnabled(), false); QVERIFY(noteedit); QCOMPARE(noteedit->text(), QString()); } void NoteEditTest::shouldEmitCollectionChanged() { MessageViewer::NoteEdit edit; - QSignalSpy spy(&edit, SIGNAL(collectionChanged(Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::NoteEdit::collectionChanged); edit.setCollection(Akonadi::Collection(42)); QCOMPARE(spy.count(), 1); QCOMPARE(spy.at(0).at(0).value(), Akonadi::Collection(42)); } void NoteEditTest::shouldEmitMessageChanged() { MessageViewer::NoteEdit edit; - QSignalSpy spy(&edit, SIGNAL(messageChanged(KMime::Message::Ptr))); + QSignalSpy spy(&edit, &MessageViewer::NoteEdit::messageChanged); KMime::Message::Ptr msg(new KMime::Message); edit.setMessage(msg); QCOMPARE(spy.count(), 1); QCOMPARE(spy.at(0).at(0).value(), msg); } void NoteEditTest::shouldNotEmitWhenCollectionIsNotChanged() { MessageViewer::NoteEdit edit; edit.setCollection(Akonadi::Collection(42)); - QSignalSpy spy(&edit, SIGNAL(collectionChanged(Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::NoteEdit::collectionChanged); edit.setCollection(Akonadi::Collection(42)); QCOMPARE(spy.count(), 0); } void NoteEditTest::shouldNotEmitWhenMessageIsNotChanged() { MessageViewer::NoteEdit edit; KMime::Message::Ptr msg(new KMime::Message); edit.setMessage(msg); - QSignalSpy spy(&edit, SIGNAL(messageChanged(KMime::Message::Ptr))); + QSignalSpy spy(&edit, &MessageViewer::NoteEdit::messageChanged); edit.setMessage(msg); QCOMPARE(spy.count(), 0); } void NoteEditTest::shouldHaveSameValueAfterSet() { MessageViewer::NoteEdit edit; KMime::Message::Ptr msg(new KMime::Message); edit.setCollection(Akonadi::Collection(42)); edit.setMessage(msg); QCOMPARE(edit.collection(), Akonadi::Collection(42)); QCOMPARE(edit.message(), msg); } void NoteEditTest::shouldHaveASubject() { MessageViewer::NoteEdit edit; KMime::Message::Ptr msg(new KMime::Message); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); QVERIFY(noteedit); QCOMPARE(noteedit->text(), QString()); QString subject = QStringLiteral("Test Note"); msg->subject(true)->fromUnicodeString(subject, "us-ascii"); edit.setMessage(msg); QCOMPARE(noteedit->text(), subject); } void NoteEditTest::shouldEmptySubjectWhenMessageIsNull() { MessageViewer::NoteEdit 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(QStringLiteral("noteedit")); edit.setMessage(KMime::Message::Ptr()); QCOMPARE(noteedit->text(), QString()); } void NoteEditTest::shouldEmptySubjectWhenMessageHasNotSubject() { MessageViewer::NoteEdit 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(QStringLiteral("noteedit")); KMime::Message::Ptr msgSubjectEmpty(new KMime::Message); edit.setMessage(msgSubjectEmpty); QCOMPARE(noteedit->text(), QString()); } void NoteEditTest::shouldSelectLineWhenPutMessage() { MessageViewer::NoteEdit 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(QStringLiteral("noteedit")); QVERIFY(noteedit->hasSelectedText()); const QString selectedText = noteedit->selectedText(); QCOMPARE(selectedText, subject); } void NoteEditTest::shouldEmitCollectionChangedWhenChangeComboboxItem() { MessageViewer::NoteEdit edit; Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(QStringLiteral("akonadicombobox")); QVERIFY(akonadicombobox); QVERIFY(akonadicombobox->currentCollection().isValid()); } void NoteEditTest::shouldEmitNotEmitNoteWhenTextIsEmpty() { MessageViewer::NoteEdit edit; KMime::Message::Ptr msg(new KMime::Message); edit.setMessage(msg); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); - QSignalSpy spy(&edit, SIGNAL(createNote(KMime::Message::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::NoteEdit::createNote); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 0); } void NoteEditTest::shouldEmitNotEmitNoteWhenTextTrimmedIsEmpty() { MessageViewer::NoteEdit edit; KMime::Message::Ptr msg(new KMime::Message); edit.setMessage(msg); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); - QSignalSpy spy(&edit, SIGNAL(createNote(KMime::Message::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::NoteEdit::createNote); noteedit->setText(QStringLiteral(" ")); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 0); noteedit->setText(QStringLiteral(" F")); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 1); } void NoteEditTest::shouldEmitNoteWhenPressEnter() { MessageViewer::NoteEdit 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(QStringLiteral("noteedit")); - QSignalSpy spy(&edit, SIGNAL(createNote(KMime::Message::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::NoteEdit::createNote); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 1); } void NoteEditTest::shouldNoteHasCorrectSubject() { MessageViewer::NoteEdit 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(QStringLiteral("noteedit")); - QSignalSpy spy(&edit, SIGNAL(createNote(KMime::Message::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::NoteEdit::createNote); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 1); KMime::Message::Ptr notePtr = spy.at(0).at(0).value(); QVERIFY((bool)notePtr); Akonadi::NoteUtils::NoteMessageWrapper note(notePtr); QCOMPARE(note.title(), subject); } void NoteEditTest::shouldClearAllWhenCloseWidget() { MessageViewer::NoteEdit 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(QStringLiteral("noteedit")); edit.slotCloseWidget(); QCOMPARE(noteedit->text(), QString()); QVERIFY(!edit.message()); } void NoteEditTest::shouldEmitCollectionChangedWhenCurrentCollectionWasChanged() { MessageViewer::NoteEdit edit; Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(QStringLiteral("akonadicombobox")); akonadicombobox->setCurrentIndex(0); QCOMPARE(akonadicombobox->currentIndex(), 0); - QSignalSpy spy(&edit, SIGNAL(collectionChanged(Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::NoteEdit::collectionChanged); akonadicombobox->setCurrentIndex(3); QCOMPARE(akonadicombobox->currentIndex(), 3); QCOMPARE(spy.count(), 1); } void NoteEditTest::shouldEmitCorrectCollection() { MessageViewer::NoteEdit edit; Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(QStringLiteral("akonadicombobox")); KMime::Message::Ptr msg(new KMime::Message); QString subject = QStringLiteral("Test Note"); msg->subject(true)->fromUnicodeString(subject, "us-ascii"); edit.setMessage(msg); akonadicombobox->setCurrentIndex(3); Akonadi::Collection col = akonadicombobox->currentCollection(); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); - QSignalSpy spy(&edit, SIGNAL(createNote(KMime::Message::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::NoteEdit::createNote); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 1); QCOMPARE(spy.at(0).at(1).value(), col); } void NoteEditTest::shouldHideWidgetWhenClickOnCloseButton() { MessageViewer::NoteEdit edit; edit.show(); QVERIFY(QTest::qWaitForWindowExposed(&edit)); QVERIFY(edit.isVisible()); QPushButton *close = edit.findChild(QStringLiteral("close-button")); QTest::mouseClick(close, Qt::LeftButton); QCOMPARE(edit.isVisible(), false); } void NoteEditTest::shouldHideWidgetWhenPressEscape() { MessageViewer::NoteEdit edit; edit.show(); // make sure the window is active so we can test for focus qApp->setActiveWindow(&edit); QVERIFY(QTest::qWaitForWindowExposed(&edit)); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); noteedit->setFocus(); QVERIFY(noteedit->hasFocus()); QTest::keyPress(&edit, Qt::Key_Escape); QCOMPARE(edit.isVisible(), false); } void NoteEditTest::shouldHideWidgetWhenSaveClicked() { MessageViewer::NoteEdit edit; edit.show(); QVERIFY(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(QStringLiteral("save-button")); QTest::mouseClick(save, Qt::LeftButton); QCOMPARE(edit.isVisible(), false); } void NoteEditTest::shouldSaveCollectionSettings() { MessageViewer::NoteEdit edit; Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(QStringLiteral("akonadicombobox")); akonadicombobox->setCurrentIndex(3); const Akonadi::Collection::Id id = akonadicombobox->currentCollection().id(); QPushButton *close = edit.findChild(QStringLiteral("close-button")); QTest::mouseClick(close, Qt::LeftButton); QCOMPARE(MessageViewer::MessageViewerSettingsBase::self()->lastNoteSelectedFolder(), id); } void NoteEditTest::shouldSaveCollectionSettingsWhenCloseWidget() { MessageViewer::NoteEdit edit; Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(QStringLiteral("akonadicombobox")); akonadicombobox->setCurrentIndex(4); const Akonadi::Collection::Id id = akonadicombobox->currentCollection().id(); edit.writeConfig(); QCOMPARE(MessageViewer::MessageViewerSettingsBase::self()->lastNoteSelectedFolder(), id); } void NoteEditTest::shouldSaveCollectionSettingsWhenDeleteWidget() { MessageViewer::NoteEdit *edit = new MessageViewer::NoteEdit; Akonadi::CollectionComboBox *akonadicombobox = edit->findChild(QStringLiteral("akonadicombobox")); akonadicombobox->setCurrentIndex(4); const Akonadi::Collection::Id id = akonadicombobox->currentCollection().id(); delete edit; QCOMPARE(MessageViewer::MessageViewerSettingsBase::self()->lastNoteSelectedFolder(), id); } void NoteEditTest::shouldSetFocusWhenWeCallNoteEdit() { MessageViewer::NoteEdit edit; edit.show(); // make sure the window is active so we can test for focus qApp->setActiveWindow(&edit); QVERIFY(QTest::qWaitForWindowExposed(&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(QStringLiteral("noteedit")); QCOMPARE(noteedit->hasFocus(), true); edit.setFocus(); QCOMPARE(noteedit->hasFocus(), false); edit.showNoteEdit(); QCOMPARE(noteedit->hasFocus(), true); } void NoteEditTest::shouldNotEmitNoteWhenMessageIsNull() { MessageViewer::NoteEdit edit; QString subject = QStringLiteral("Test Note"); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); noteedit->setText(subject); - QSignalSpy spy(&edit, SIGNAL(createNote(KMime::Message::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::NoteEdit::createNote); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 0); } void NoteEditTest::shouldClearLineAfterEmitNewNote() { MessageViewer::NoteEdit 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(QStringLiteral("noteedit")); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(noteedit->text(), QString()); } void NoteEditTest::shouldHaveLineEditFocus() { MessageViewer::NoteEdit edit; edit.show(); // make sure the window is active so we can test for focus qApp->setActiveWindow(&edit); QVERIFY(QTest::qWaitForWindowExposed(&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(QStringLiteral("noteedit")); QCOMPARE(noteedit->hasFocus(), true); } void NoteEditTest::shouldShouldEnabledSaveEditorButton() { MessageViewer::NoteEdit edit; KMime::Message::Ptr msg(new KMime::Message); msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii"); edit.setMessage(msg); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); QPushButton *save = edit.findChild(QStringLiteral("save-button")); QCOMPARE(save->isEnabled(), true); noteedit->clear(); QCOMPARE(save->isEnabled(), false); QVERIFY(noteedit->text().isEmpty()); noteedit->setText(QStringLiteral(" ")); QCOMPARE(save->isEnabled(), false); } QTEST_MAIN(NoteEditTest) diff --git a/plugins/messageviewerplugins/autotests/todoedittest.cpp b/plugins/messageviewerplugins/autotests/todoedittest.cpp index 591dbda8..c977c3d8 100644 --- a/plugins/messageviewerplugins/autotests/todoedittest.cpp +++ b/plugins/messageviewerplugins/autotests/todoedittest.cpp @@ -1,554 +1,554 @@ /* Copyright (C) 2014-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "todoedittest.h" #include "globalsettings_messageviewer.h" #include "../createtodoplugin/todoedit.h" #include #include #include #include #include #include #include #include #include #include #include #include namespace MessageViewer { extern MESSAGEVIEWER_EXPORT QAbstractItemModel *_k_todoEditStubModel; } TodoEditTest::TodoEditTest() { qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); QStandardPaths::setTestModeEnabled(true); 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::Todo::todoMimeType()); 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_todoEditStubModel = model; // Fake a default-selected collection for shouldHaveDefaultValuesOnCreation test MessageViewer::MessageViewerSettingsBase::self()->setLastSelectedFolder(43); } void TodoEditTest::shouldHaveDefaultValuesOnCreation() { MessageViewer::TodoEdit edit; QVERIFY(edit.collection().isValid()); QVERIFY(!edit.message()); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); QPushButton *openEditor = edit.findChild(QStringLiteral("open-editor-button")); QPushButton *save = edit.findChild(QStringLiteral("save-button")); QVERIFY(openEditor); QVERIFY(save); QCOMPARE(openEditor->isEnabled(), false); QCOMPARE(save->isEnabled(), false); QVERIFY(noteedit); QCOMPARE(noteedit->text(), QString()); } void TodoEditTest::shouldEmitCollectionChanged() { MessageViewer::TodoEdit edit; - QSignalSpy spy(&edit, SIGNAL(collectionChanged(Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::TodoEdit::collectionChanged); edit.setCollection(Akonadi::Collection(42)); QCOMPARE(spy.count(), 1); QCOMPARE(spy.at(0).at(0).value(), Akonadi::Collection(42)); } void TodoEditTest::shouldEmitMessageChanged() { MessageViewer::TodoEdit edit; - QSignalSpy spy(&edit, SIGNAL(messageChanged(KMime::Message::Ptr))); + QSignalSpy spy(&edit, &MessageViewer::TodoEdit::messageChanged); KMime::Message::Ptr msg(new KMime::Message); edit.setMessage(msg); QCOMPARE(spy.count(), 1); QCOMPARE(spy.at(0).at(0).value(), msg); } void TodoEditTest::shouldNotEmitWhenCollectionIsNotChanged() { MessageViewer::TodoEdit edit; edit.setCollection(Akonadi::Collection(42)); - QSignalSpy spy(&edit, SIGNAL(collectionChanged(Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::TodoEdit::collectionChanged); edit.setCollection(Akonadi::Collection(42)); QCOMPARE(spy.count(), 0); } void TodoEditTest::shouldNotEmitWhenMessageIsNotChanged() { MessageViewer::TodoEdit edit; KMime::Message::Ptr msg(new KMime::Message); edit.setMessage(msg); - QSignalSpy spy(&edit, SIGNAL(messageChanged(KMime::Message::Ptr))); + QSignalSpy spy(&edit, &MessageViewer::TodoEdit::messageChanged); edit.setMessage(msg); QCOMPARE(spy.count(), 0); } void TodoEditTest::shouldHaveSameValueAfterSet() { MessageViewer::TodoEdit edit; KMime::Message::Ptr msg(new KMime::Message); edit.setCollection(Akonadi::Collection(42)); edit.setMessage(msg); QCOMPARE(edit.collection(), Akonadi::Collection(42)); QCOMPARE(edit.message(), msg); } void TodoEditTest::shouldHaveASubject() { MessageViewer::TodoEdit edit; KMime::Message::Ptr msg(new KMime::Message); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); QVERIFY(noteedit); QCOMPARE(noteedit->text(), QString()); QString subject = QStringLiteral("Test Note"); msg->subject(true)->fromUnicodeString(subject, "us-ascii"); edit.setMessage(msg); edit.showToDoWidget(); QCOMPARE(noteedit->text(), QStringLiteral("Reply to \"%1\"").arg(subject)); } void TodoEditTest::shouldEmptySubjectWhenMessageIsNull() { MessageViewer::TodoEdit 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(QStringLiteral("noteedit")); edit.setMessage(KMime::Message::Ptr()); QCOMPARE(noteedit->text(), QString()); } void TodoEditTest::shouldEmptySubjectWhenMessageHasNotSubject() { MessageViewer::TodoEdit 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(QStringLiteral("noteedit")); KMime::Message::Ptr msgSubjectEmpty(new KMime::Message); edit.setMessage(msgSubjectEmpty); QCOMPARE(noteedit->text(), QString()); } void TodoEditTest::shouldSelectLineWhenPutMessage() { MessageViewer::TodoEdit edit; KMime::Message::Ptr msg(new KMime::Message); QString subject = QStringLiteral("Test Note"); msg->subject(true)->fromUnicodeString(subject, "us-ascii"); edit.setMessage(msg); edit.showToDoWidget(); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); QVERIFY(noteedit->hasSelectedText()); const QString selectedText = noteedit->selectedText(); QCOMPARE(selectedText, QStringLiteral("Reply to \"%1\"").arg(subject)); } void TodoEditTest::shouldEmitCollectionChangedWhenChangeComboboxItem() { MessageViewer::TodoEdit edit; Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(QStringLiteral("akonadicombobox")); QVERIFY(akonadicombobox); QVERIFY(akonadicombobox->currentCollection().isValid()); } void TodoEditTest::shouldEmitNotEmitTodoWhenTextIsEmpty() { MessageViewer::TodoEdit edit; KMime::Message::Ptr msg(new KMime::Message); edit.setMessage(msg); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); - QSignalSpy spy(&edit, SIGNAL(createTodo(KCalCore::Todo::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::TodoEdit::createTodo); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 0); } void TodoEditTest::shouldEmitNotEmitTodoWhenTextTrimmedIsEmpty() { MessageViewer::TodoEdit edit; KMime::Message::Ptr msg(new KMime::Message); edit.setMessage(msg); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); - QSignalSpy spy(&edit, SIGNAL(createTodo(KCalCore::Todo::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::TodoEdit::createTodo); noteedit->setText(QStringLiteral(" ")); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 0); noteedit->setText(QStringLiteral(" F")); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 1); } void TodoEditTest::shouldEmitTodoWhenPressEnter() { MessageViewer::TodoEdit edit; KMime::Message::Ptr msg(new KMime::Message); QString subject = QStringLiteral("Test Note"); msg->subject(true)->fromUnicodeString(subject, "us-ascii"); edit.setMessage(msg); edit.showToDoWidget(); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); - QSignalSpy spy(&edit, SIGNAL(createTodo(KCalCore::Todo::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::TodoEdit::createTodo); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 1); } void TodoEditTest::shouldTodoHasCorrectSubject() { MessageViewer::TodoEdit edit; KMime::Message::Ptr msg(new KMime::Message); QString subject = QStringLiteral("Test Note"); msg->subject(true)->fromUnicodeString(subject, "us-ascii"); edit.setMessage(msg); edit.showToDoWidget(); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); - QSignalSpy spy(&edit, SIGNAL(createTodo(KCalCore::Todo::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::TodoEdit::createTodo); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 1); KCalCore::Todo::Ptr todoPtr = spy.at(0).at(0).value(); QVERIFY(todoPtr); QCOMPARE(todoPtr->summary(), QStringLiteral("Reply to \"%1\"").arg(subject)); } void TodoEditTest::shouldClearAllWhenCloseWidget() { MessageViewer::TodoEdit edit; edit.show(); qApp->setActiveWindow(&edit); QVERIFY(QTest::qWaitForWindowExposed(&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(QStringLiteral("noteedit")); edit.slotCloseWidget(); QCOMPARE(noteedit->text(), QString()); QVERIFY(!edit.message()); } void TodoEditTest::shouldEmitCollectionChangedWhenCurrentCollectionWasChanged() { MessageViewer::TodoEdit edit; Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(QStringLiteral("akonadicombobox")); akonadicombobox->setCurrentIndex(0); QCOMPARE(akonadicombobox->currentIndex(), 0); - QSignalSpy spy(&edit, SIGNAL(collectionChanged(Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::TodoEdit::collectionChanged); akonadicombobox->setCurrentIndex(3); QCOMPARE(akonadicombobox->currentIndex(), 3); QCOMPARE(spy.count(), 1); } void TodoEditTest::shouldEmitCorrectCollection() { MessageViewer::TodoEdit edit; Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(QStringLiteral("akonadicombobox")); KMime::Message::Ptr msg(new KMime::Message); QString subject = QStringLiteral("Test Note"); msg->subject(true)->fromUnicodeString(subject, "us-ascii"); edit.setMessage(msg); edit.showToDoWidget(); akonadicombobox->setCurrentIndex(3); Akonadi::Collection col = akonadicombobox->currentCollection(); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); - QSignalSpy spy(&edit, SIGNAL(createTodo(KCalCore::Todo::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::TodoEdit::createTodo); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 1); QCOMPARE(spy.at(0).at(1).value(), col); } void TodoEditTest::shouldHideWidgetWhenClickOnCloseButton() { MessageViewer::TodoEdit edit; edit.show(); QVERIFY(QTest::qWaitForWindowExposed(&edit)); QVERIFY(edit.isVisible()); QPushButton *close = edit.findChild(QStringLiteral("close-button")); QTest::mouseClick(close, Qt::LeftButton); QCOMPARE(edit.isVisible(), false); } void TodoEditTest::shouldHideWidgetWhenPressEscape() { MessageViewer::TodoEdit edit; edit.show(); // make sure the window is active so we can test for focus qApp->setActiveWindow(&edit); QVERIFY(QTest::qWaitForWindowExposed(&edit)); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); noteedit->setFocus(); QVERIFY(noteedit->hasFocus()); QTest::keyPress(&edit, Qt::Key_Escape); QCOMPARE(edit.isVisible(), false); } void TodoEditTest::shouldHideWidgetWhenSaveClicked() { MessageViewer::TodoEdit edit; edit.show(); QVERIFY(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(QStringLiteral("save-button")); QTest::mouseClick(save, Qt::LeftButton); QCOMPARE(edit.isVisible(), true); } void TodoEditTest::shouldSaveCollectionSettings() { MessageViewer::TodoEdit edit; Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(QStringLiteral("akonadicombobox")); akonadicombobox->setCurrentIndex(3); const Akonadi::Collection::Id id = akonadicombobox->currentCollection().id(); QPushButton *close = edit.findChild(QStringLiteral("close-button")); QTest::mouseClick(close, Qt::LeftButton); QCOMPARE(MessageViewer::MessageViewerSettingsBase::self()->lastSelectedFolder(), id); } void TodoEditTest::shouldSaveCollectionSettingsWhenCloseWidget() { MessageViewer::TodoEdit edit; Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(QStringLiteral("akonadicombobox")); akonadicombobox->setCurrentIndex(4); const Akonadi::Collection::Id id = akonadicombobox->currentCollection().id(); edit.writeConfig(); QCOMPARE(MessageViewer::MessageViewerSettingsBase::self()->lastSelectedFolder(), id); } void TodoEditTest::shouldSaveCollectionSettingsWhenDeleteWidget() { MessageViewer::TodoEdit *edit = new MessageViewer::TodoEdit; Akonadi::CollectionComboBox *akonadicombobox = edit->findChild(QStringLiteral("akonadicombobox")); akonadicombobox->setCurrentIndex(4); const Akonadi::Collection::Id id = akonadicombobox->currentCollection().id(); delete edit; QCOMPARE(MessageViewer::MessageViewerSettingsBase::self()->lastSelectedFolder(), id); } void TodoEditTest::shouldSetFocusWhenWeCallTodoEdit() { MessageViewer::TodoEdit edit; edit.show(); // make sure the window is active so we can test for focus qApp->setActiveWindow(&edit); QVERIFY(QTest::qWaitForWindowExposed(&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(QStringLiteral("noteedit")); QCOMPARE(noteedit->hasFocus(), true); edit.setFocus(); QCOMPARE(noteedit->hasFocus(), false); edit.showToDoWidget(); QCOMPARE(noteedit->hasFocus(), true); } void TodoEditTest::shouldNotEmitTodoWhenMessageIsNull() { MessageViewer::TodoEdit edit; QString subject = QStringLiteral("Test Note"); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); noteedit->setText(subject); - QSignalSpy spy(&edit, SIGNAL(createTodo(KCalCore::Todo::Ptr,Akonadi::Collection))); + QSignalSpy spy(&edit, &MessageViewer::TodoEdit::createTodo); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(spy.count(), 0); } void TodoEditTest::shouldClearLineAfterEmitNewNote() { MessageViewer::TodoEdit 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(QStringLiteral("noteedit")); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(noteedit->text(), QString()); } void TodoEditTest::shouldHaveLineEditFocus() { MessageViewer::TodoEdit edit; edit.show(); // make sure the window is active so we can test for focus qApp->setActiveWindow(&edit); QVERIFY(QTest::qWaitForWindowExposed(&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(QStringLiteral("noteedit")); QCOMPARE(noteedit->hasFocus(), true); } void TodoEditTest::shouldShowMessageWidget() { MessageViewer::TodoEdit edit; edit.show(); QVERIFY(QTest::qWaitForWindowExposed(&edit)); KMime::Message::Ptr msg(new KMime::Message); msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii"); edit.setMessage(msg); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); noteedit->setText(QStringLiteral("Test Note")); KMessageWidget *msgwidget = edit.findChild(QStringLiteral("msgwidget")); QCOMPARE(msgwidget->isVisible(), false); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(msgwidget->isVisible(), true); } void TodoEditTest::shouldHideMessageWidget() { MessageViewer::TodoEdit edit; edit.show(); QVERIFY(QTest::qWaitForWindowExposed(&edit)); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); noteedit->setText(QStringLiteral("Test note")); KMime::Message::Ptr msg(new KMime::Message); msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii"); edit.setMessage(msg); KMessageWidget *msgwidget = edit.findChild(QStringLiteral("msgwidget")); msgwidget->show(); QCOMPARE(msgwidget->isVisible(), true); noteedit->setText(QStringLiteral("Another note")); QCOMPARE(msgwidget->isVisible(), false); } void TodoEditTest::shouldHideMessageWidgetWhenAddNewMessage() { MessageViewer::TodoEdit edit; edit.show(); QVERIFY(QTest::qWaitForWindowExposed(&edit)); KMime::Message::Ptr msg(new KMime::Message); msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii"); edit.setMessage(msg); edit.showToDoWidget(); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); noteedit->setText(QStringLiteral("Test Note")); KMessageWidget *msgwidget = edit.findChild(QStringLiteral("msgwidget")); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(msgwidget->isVisible(), true); KMime::Message::Ptr msg2(new KMime::Message); msg2->subject(true)->fromUnicodeString(QStringLiteral("Test note 2"), "us-ascii"); edit.setMessage(msg2); edit.showToDoWidget(); QCOMPARE(msgwidget->isVisible(), false); } void TodoEditTest::shouldHideMessageWidgetWhenCloseWidget() { MessageViewer::TodoEdit edit; edit.show(); QVERIFY(QTest::qWaitForWindowExposed(&edit)); KMime::Message::Ptr msg(new KMime::Message); msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii"); edit.setMessage(msg); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); noteedit->setText(QStringLiteral("Test Note")); KMessageWidget *msgwidget = edit.findChild(QStringLiteral("msgwidget")); QTest::keyClick(noteedit, Qt::Key_Enter); QCOMPARE(msgwidget->isVisible(), true); edit.slotCloseWidget(); QCOMPARE(msgwidget->isHidden(), true); } void TodoEditTest::shouldEnabledSaveOpenEditorButton() { MessageViewer::TodoEdit edit; KMime::Message::Ptr msg(new KMime::Message); msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii"); edit.setMessage(msg); edit.showToDoWidget(); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); QPushButton *openEditor = edit.findChild(QStringLiteral("open-editor-button")); QPushButton *save = edit.findChild(QStringLiteral("save-button")); QCOMPARE(openEditor->isEnabled(), true); QCOMPARE(save->isEnabled(), true); noteedit->clear(); QCOMPARE(openEditor->isEnabled(), false); QCOMPARE(save->isEnabled(), false); noteedit->setText(QStringLiteral("test 2")); QCOMPARE(openEditor->isEnabled(), true); QCOMPARE(save->isEnabled(), true); noteedit->setText(QStringLiteral(" ")); QCOMPARE(openEditor->isEnabled(), false); QCOMPARE(save->isEnabled(), false); noteedit->setText(QStringLiteral(" foo")); QCOMPARE(openEditor->isEnabled(), true); QCOMPARE(save->isEnabled(), true); } void TodoEditTest::shouldDisabledSaveOpenEditorButtonWhenCollectionComboBoxIsEmpty() { MessageViewer::TodoEdit edit; Akonadi::CollectionComboBox *akonadicombobox = edit.findChild(QStringLiteral("akonadicombobox")); //Create an empty combobox akonadicombobox->setModel(new QStandardItemModel()); KMime::Message::Ptr msg(new KMime::Message); msg->subject(true)->fromUnicodeString(QStringLiteral("Test note"), "us-ascii"); edit.setMessage(msg); QPushButton *openEditor = edit.findChild(QStringLiteral("open-editor-button")); QPushButton *save = edit.findChild(QStringLiteral("save-button")); QCOMPARE(openEditor->isEnabled(), false); QCOMPARE(save->isEnabled(), false); } QTEST_MAIN(TodoEditTest)