diff --git a/autotests/rocketchataccountsettingstest.h b/autotests/rocketchataccountsettingstest.h --- a/autotests/rocketchataccountsettingstest.h +++ b/autotests/rocketchataccountsettingstest.h @@ -31,6 +31,21 @@ ~RocketChatAccountSettingsTest() = default; private Q_SLOTS: void shouldHaveDefaultValues(); + void shouldEmitSignalWhenSetServerURLChanged(); + void shouldEmitSignalWhenUserNameChanged(); + void shouldEmitSignalWhenUserIDChanged(); + void shouldEmitSignalWhenLoginStatusChanged(); + void shouldSetAccountName(); + void shouldSetUserID(); + void shouldsetAuthToken(); + void shouldSetServerUrl(); + void shouldSetUserName(); + void shouldSetPassword(); + void shouldLogout(); + void shouldNotEmitSignalWhenNewUsernameIsSameAsOld(); + void shouldNotEmitSignalWhenNewServerUrlIsSameAsOld(); }; #endif // ROCKETCHATACCOUNTSETTINGSTEST_H + + diff --git a/autotests/rocketchataccountsettingstest.cpp b/autotests/rocketchataccountsettingstest.cpp --- a/autotests/rocketchataccountsettingstest.cpp +++ b/autotests/rocketchataccountsettingstest.cpp @@ -21,14 +21,185 @@ #include "rocketchataccountsettingstest.h" #include "rocketchataccountsettings.h" #include +#include + QTEST_MAIN(RocketChatAccountSettingsTest) RocketChatAccountSettingsTest::RocketChatAccountSettingsTest(QObject *parent) : QObject(parent) { } +void RocketChatAccountSettingsTest::shouldNotEmitSignalWhenNewServerUrlIsSameAsOld() +{ + RocketChatAccountSettings *SampleChatAccount = new RocketChatAccountSettings; + + QSignalSpy SpyURL(SampleChatAccount, &RocketChatAccountSettings::serverURLChanged); + QString url = SampleChatAccount->serverUrl(); + SampleChatAccount->setServerUrl(url); + QCOMPARE(SpyURL.count(), 0); + + delete SampleChatAccount; +} + +void RocketChatAccountSettingsTest::shouldEmitSignalWhenSetServerURLChanged() +{ + RocketChatAccountSettings *SampleChatAccount = new RocketChatAccountSettings; + + QSignalSpy SpyURL(SampleChatAccount, &RocketChatAccountSettings::serverURLChanged); + SampleChatAccount->setServerUrl(QStringLiteral("bla bla")); + QCOMPARE(SpyURL.count(), 1); + + delete SampleChatAccount; +} + +void RocketChatAccountSettingsTest::shouldNotEmitSignalWhenNewUsernameIsSameAsOld() +{ + RocketChatAccountSettings *SampleChat = new RocketChatAccountSettings; + + QSignalSpy SpyName(SampleChat, &RocketChatAccountSettings::userNameChanged); + QString username = SampleChat->userName(); + SampleChat->setUserName(username); + QCOMPARE(SpyName.count(), 0); + + delete SampleChat; +} + +void RocketChatAccountSettingsTest::shouldEmitSignalWhenUserNameChanged() +{ + RocketChatAccountSettings *SampleChat = new RocketChatAccountSettings; + + QSignalSpy SpyName(SampleChat, &RocketChatAccountSettings::userNameChanged); + SampleChat->setUserName(QStringLiteral("Donal Knuth")); + QCOMPARE(SpyName.count(), 1); + + delete SampleChat; +} + +void RocketChatAccountSettingsTest::shouldEmitSignalWhenUserIDChanged() +{ + RocketChatAccountSettings *SampleChat1 = new RocketChatAccountSettings; + + QSignalSpy SpyID(SampleChat1, &RocketChatAccountSettings::userIDChanged); + SampleChat1->setUserId(QStringLiteral("RA15")); + QCOMPARE(SpyID.count(), 1); + + delete SampleChat1; +} + +void RocketChatAccountSettingsTest::shouldEmitSignalWhenLoginStatusChanged() +{ + +} + +void RocketChatAccountSettingsTest::shouldLogout() +{ + RocketChatAccountSettings *SampleChat = new RocketChatAccountSettings; + + SampleChat->setAuthToken(QStringLiteral("Token305")); + SampleChat->setUserId(QStringLiteral("ECE305")); + SampleChat->setPassword(QStringLiteral("masterPassword")); + + SampleChat->logout(); + QVERIFY(SampleChat->authToken().isEmpty()); + QVERIFY(SampleChat->userId().isEmpty()); + QVERIFY(SampleChat->password().isEmpty()); +} + +void RocketChatAccountSettingsTest::shouldSetAccountName() +{ + RocketChatAccountSettings *sampleChat = new RocketChatAccountSettings; + + QString val = QStringLiteral("myAccount#$^56"); + sampleChat->setAccountName(val); + + QCOMPARE(val, sampleChat->accountName()); + + delete sampleChat; +} + +void RocketChatAccountSettingsTest::shouldsetAuthToken() +{ + RocketChatAccountSettings *sampleChat = new RocketChatAccountSettings; + + QString val = QStringLiteral("myAuthToken#$^56"); + sampleChat->setAuthToken(val); + + QCOMPARE(val, sampleChat->authToken()); + + delete sampleChat; +} + +void RocketChatAccountSettingsTest::shouldSetPassword() +{ + RocketChatAccountSettings *sampleChat = new RocketChatAccountSettings; + + QString val = QStringLiteral("myPass#$^56"); + sampleChat->setPassword(val); + + QCOMPARE(val, sampleChat->password()); + + delete sampleChat; +} + +void RocketChatAccountSettingsTest::shouldSetServerUrl() +{ + RocketChatAccountSettings *sampleChat = new RocketChatAccountSettings; + + QString val = QStringLiteral("my.fancy.url"); + sampleChat->setServerUrl(val); + + QCOMPARE(val, sampleChat->serverUrl()); + + delete sampleChat; +} + +void RocketChatAccountSettingsTest::shouldSetUserID() +{ + RocketChatAccountSettings *sampleChat = new RocketChatAccountSettings; + + QString val = QStringLiteral("ECE305"); + sampleChat->setUserId(val); + + QCOMPARE(val, sampleChat->userId()); + + delete sampleChat; +} + +void RocketChatAccountSettingsTest::shouldSetUserName() +{ + RocketChatAccountSettings *sampleChat = new RocketChatAccountSettings; + + QString val = QStringLiteral("Eric Roberts"); + sampleChat->setUserName(val); + + QCOMPARE(val, sampleChat->userName()); + + delete sampleChat; +} + +/* + * @brief + * All the methods which have return value type as QString + * in rocketchataccountsettings.h should return empty QString by default. + * + * */ void RocketChatAccountSettingsTest::shouldHaveDefaultValues() { - //TODO + RocketChatAccountSettings chat; + + QVERIFY(chat.accountName().isEmpty()); + QVERIFY(chat.authToken().isEmpty()); + QVERIFY(chat.cacheBasePath().isEmpty()); + QVERIFY(chat.userId().isEmpty()); + QVERIFY(chat.userName().isEmpty()); + QVERIFY(chat.password().isEmpty()); + QVERIFY(chat.serverUrl().isEmpty()); + + chat.loadSettings(); + QVERIFY(chat.userId().isEmpty()); + QVERIFY(chat.userName().isEmpty()); + QVERIFY(chat.authToken().isEmpty()); + QCOMPARE(chat.serverUrl(), QStringLiteral("demo.rocket.chat")); + }