diff options
Diffstat (limited to 'framework/domain/actions/tests')
-rw-r--r-- | framework/domain/actions/tests/CMakeLists.txt | 6 | ||||
-rw-r--r-- | framework/domain/actions/tests/sinkactiontest.cpp | 60 |
2 files changed, 66 insertions, 0 deletions
diff --git a/framework/domain/actions/tests/CMakeLists.txt b/framework/domain/actions/tests/CMakeLists.txt new file mode 100644 index 00000000..dc9d01b1 --- /dev/null +++ b/framework/domain/actions/tests/CMakeLists.txt | |||
@@ -0,0 +1,6 @@ | |||
1 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) | ||
2 | cmake_policy(SET CMP0063 NEW) | ||
3 | add_executable(sinkactiontest sinkactiontest.cpp) | ||
4 | add_test(sinkactiontest sinkactiontest) | ||
5 | qt5_use_modules(sinkactiontest Core Test Concurrent) | ||
6 | target_link_libraries(sinkactiontest sink actionplugin KF5::Mime mailplugin) | ||
diff --git a/framework/domain/actions/tests/sinkactiontest.cpp b/framework/domain/actions/tests/sinkactiontest.cpp new file mode 100644 index 00000000..3e4567fd --- /dev/null +++ b/framework/domain/actions/tests/sinkactiontest.cpp | |||
@@ -0,0 +1,60 @@ | |||
1 | #include <QTest> | ||
2 | #include <QDebug> | ||
3 | #include <QSignalSpy> | ||
4 | #include <sink/test.h> | ||
5 | #include <sink/store.h> | ||
6 | #include <sink/log.h> | ||
7 | #include <KMime/Message> | ||
8 | |||
9 | #include <actions/action.h> | ||
10 | #include <actions/context.h> | ||
11 | |||
12 | using namespace Sink; | ||
13 | |||
14 | class SinkActionTest : public QObject | ||
15 | { | ||
16 | Q_OBJECT | ||
17 | private slots: | ||
18 | |||
19 | void initTestCase() | ||
20 | { | ||
21 | Sink::Test::initTest(); | ||
22 | Sink::Log::setDebugOutputLevel(Sink::Log::Trace); | ||
23 | } | ||
24 | |||
25 | void testSaveAsDraftFail() | ||
26 | { | ||
27 | Kube::Context context; | ||
28 | auto future = Kube::Action("org.kde.kube.actions.save-as-draft", context).execute(); | ||
29 | |||
30 | QTRY_VERIFY(future.isDone()); | ||
31 | //because of empty context | ||
32 | QVERIFY(future.error()); | ||
33 | } | ||
34 | |||
35 | void testSaveAsDraftNew() | ||
36 | { | ||
37 | auto message = KMime::Message::Ptr::create(); | ||
38 | message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8"); | ||
39 | message->assemble(); | ||
40 | |||
41 | auto &&account = Test::TestAccount::registerAccount(); | ||
42 | auto folder = account.createEntity<ApplicationDomain::Folder>(); | ||
43 | folder->setProperty("specialpurpose", QVariant::fromValue(QByteArrayList() << "drafts")); | ||
44 | |||
45 | Kube::Context context; | ||
46 | context.setProperty("message", QVariant::fromValue(message)); | ||
47 | context.setProperty("accountId", QVariant::fromValue(account.identifier)); | ||
48 | auto future = Kube::Action("org.kde.kube.actions.save-as-draft", context).execute(); | ||
49 | |||
50 | QTRY_VERIFY(future.isDone()); | ||
51 | QVERIFY(!future.error()); | ||
52 | auto mails = account.entities<Sink::ApplicationDomain::Mail>(); | ||
53 | QCOMPARE(mails.size(), 1); | ||
54 | auto mail = mails.first(); | ||
55 | QCOMPARE(mail->getProperty("folder").toByteArray(), folder->identifier()); | ||
56 | } | ||
57 | }; | ||
58 | |||
59 | QTEST_GUILESS_MAIN(SinkActionTest) | ||
60 | #include "sinkactiontest.moc" | ||