summaryrefslogtreecommitdiffstats
path: root/framework/domain/actions/tests/sinkactiontest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain/actions/tests/sinkactiontest.cpp')
-rw-r--r--framework/domain/actions/tests/sinkactiontest.cpp60
1 files changed, 60 insertions, 0 deletions
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
12using namespace Sink;
13
14class SinkActionTest : public QObject
15{
16 Q_OBJECT
17private 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
59QTEST_GUILESS_MAIN(SinkActionTest)
60#include "sinkactiontest.moc"