summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/settings/tests/settingstest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-08-23 20:49:37 -0600
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-08-23 20:52:33 -0600
commit9efd56c64fe848b4557dccbdac244571d97bfc77 (patch)
tree7ffd4b14ac21766155d7a3986b0a8b4351a45530 /framework/src/domain/settings/tests/settingstest.cpp
parentc06438012eb09563daeeb82cacf937efd724cb55 (diff)
downloadkube-9efd56c64fe848b4557dccbdac244571d97bfc77.tar.gz
kube-9efd56c64fe848b4557dccbdac244571d97bfc77.zip
A single test for all accountsettings.
Only the imaptest was working anyways and all of them tested the same things.
Diffstat (limited to 'framework/src/domain/settings/tests/settingstest.cpp')
-rw-r--r--framework/src/domain/settings/tests/settingstest.cpp155
1 files changed, 155 insertions, 0 deletions
diff --git a/framework/src/domain/settings/tests/settingstest.cpp b/framework/src/domain/settings/tests/settingstest.cpp
new file mode 100644
index 00000000..2d997468
--- /dev/null
+++ b/framework/src/domain/settings/tests/settingstest.cpp
@@ -0,0 +1,155 @@
1#include <QTest>
2#include <QDebug>
3#include <QSignalSpy>
4#include <functional>
5#include <QStandardPaths>
6#include <QDir>
7#include <sink/test.h>
8#include <sink/store.h>
9
10#include <accountsettings.h>
11
12
13class TestSettings : public AccountSettings
14{
15 Q_OBJECT
16
17public:
18 TestSettings(QObject *parent = 0)
19 : AccountSettings{parent}
20 {}
21
22 Q_INVOKABLE virtual void load() Q_DECL_OVERRIDE
23 {
24 loadAccount();
25 loadImapResource();
26 loadMailtransportResource();
27 loadIdentity();
28 }
29
30 Q_INVOKABLE virtual void save() Q_DECL_OVERRIDE
31 {
32 saveAccount();
33 saveImapResource();
34 saveMailtransportResource();
35 saveIdentity();
36 }
37
38 Q_INVOKABLE virtual void remove() Q_DECL_OVERRIDE
39 {
40 removeResource(mMailtransportIdentifier);
41 removeResource(mImapIdentifier);
42 removeIdentity();
43 removeAccount();
44 }
45};
46
47class SettingsTest : public QObject
48{
49 Q_OBJECT
50private slots:
51
52 void initTestCase()
53 {
54 Sink::Test::initTest();
55 }
56
57 void testLoad()
58 {
59 auto accountId = "accountid";
60 auto imapServer = QString("imapserver");
61 auto imapUsername = QString("imapName");
62 auto imapPassword = QString("imapPw");
63 auto smtpServer = QString("smtpserver");
64 auto smtpUsername = QString("smtpName");
65 auto smtpPassword = QString("smtpPw");
66 auto username = QString("username");
67 auto emailAddress = QString("emailAddress");
68
69 TestSettings settings;
70 settings.setAccountIdentifier(accountId);
71 settings.setProperty("imapServer", imapServer);
72 settings.setProperty("imapUsername", imapUsername);
73 settings.setProperty("imapPassword", imapPassword);
74 settings.setProperty("smtpServer", smtpServer);
75 settings.setProperty("smtpUsername", smtpUsername);
76 settings.setProperty("smtpPassword", smtpPassword);
77 settings.setProperty("userName", username);
78 settings.setProperty("emailAddress", emailAddress);
79 settings.save();
80
81 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query()).then([](const QList<Sink::ApplicationDomain::SinkResource::Ptr> &resources) {
82 QCOMPARE(resources.size(), 2);
83 })
84 .exec().waitForFinished();
85
86 //Ensure we can read back all the information using the accountid
87 {
88 TestSettings readSettings;
89 QSignalSpy spy(&readSettings, &TestSettings::imapResourceChanged);
90 QSignalSpy spy1(&readSettings, &TestSettings::smtpResourceChanged);
91 readSettings.setAccountIdentifier(accountId);
92 //Once for clear and once for the new setting
93 QTRY_COMPARE(spy.count(), 2);
94 QTRY_COMPARE(spy1.count(), 2);
95 QVERIFY(!readSettings.accountIdentifier().isEmpty());
96 QCOMPARE(readSettings.property("imapServer").toString(), imapServer);
97 QCOMPARE(readSettings.property("imapUsername").toString(), imapUsername);
98 QCOMPARE(readSettings.property("imapPassword").toString(), imapPassword);
99 QCOMPARE(readSettings.property("smtpServer").toString(), smtpServer);
100 QCOMPARE(readSettings.property("smtpUsername").toString(), smtpUsername);
101 QCOMPARE(readSettings.property("smtpPassword").toString(), smtpPassword);
102 QCOMPARE(readSettings.property("userName").toString(), username);
103 QCOMPARE(readSettings.property("emailAddress").toString(), emailAddress);
104 }
105
106 //Modify all settings
107 {
108 settings.setProperty("imapServer", imapServer + "mod");
109 settings.setProperty("imapUsername", imapUsername + "mod");
110 settings.setProperty("imapPassword", imapPassword + "mod");
111 settings.setProperty("smtpServer", smtpServer + "mod");
112 settings.setProperty("smtpUsername", smtpUsername + "mod");
113 settings.setProperty("smtpPassword", smtpPassword + "mod");
114 settings.setProperty("userName", username + "mod");
115 settings.setProperty("emailAddress", emailAddress + "mod");
116 settings.save();
117 }
118
119 //Read back settings again
120 {
121 TestSettings readSettings;
122 QSignalSpy spy(&readSettings, &TestSettings::imapResourceChanged);
123 QSignalSpy spy1(&readSettings, &TestSettings::smtpResourceChanged);
124 readSettings.setAccountIdentifier(accountId);
125 //Once for clear and once for the new setting
126 QTRY_COMPARE(spy.count(), 2);
127 QTRY_COMPARE(spy1.count(), 2);
128 QVERIFY(!readSettings.accountIdentifier().isEmpty());
129 QCOMPARE(readSettings.property("imapServer").toString(), imapServer + "mod");
130 QCOMPARE(readSettings.property("imapUsername").toString(), imapUsername + "mod");
131 QCOMPARE(readSettings.property("imapPassword").toString(), imapPassword + "mod");
132 QCOMPARE(readSettings.property("smtpServer").toString(), smtpServer + "mod");
133 QCOMPARE(readSettings.property("smtpUsername").toString(), smtpUsername + "mod");
134 QCOMPARE(readSettings.property("smtpPassword").toString(), smtpPassword + "mod");
135 QCOMPARE(readSettings.property("userName").toString(), username + "mod");
136 QCOMPARE(readSettings.property("emailAddress").toString(), emailAddress + "mod");
137 }
138
139 {
140 TestSettings settings;
141 QSignalSpy spy(&settings, &TestSettings::imapResourceChanged);
142 settings.setAccountIdentifier(accountId);
143 QTRY_COMPARE(spy.count(), 2);
144 settings.remove();
145 }
146
147 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query()).then([](const QList<Sink::ApplicationDomain::SinkResource::Ptr> &resources) {
148 QCOMPARE(resources.size(), 0);
149 })
150 .exec().waitForFinished();
151 }
152};
153
154QTEST_GUILESS_MAIN(SettingsTest)
155#include "settingstest.moc"