diff --git a/autotests/rocketchataccountsettingstest.h b/autotests/rocketchataccountsettingstest.h --- a/autotests/rocketchataccountsettingstest.h +++ b/autotests/rocketchataccountsettingstest.h @@ -31,6 +31,18 @@ ~RocketChatAccountSettingsTest() = default; private Q_SLOTS: void shouldHaveDefaultValues(); + void shouldEmitSignalWhenSetServerURLCalled(); + void shouldEmitSignalWhenUserNameChanged(); + void shouldEmitSignalWhenUserIDChanged(); + void shouldEmitSignalWhenLoginStatusChanged(); + void shouldSetAccountName(); + void shouldSetUserID(); + void shouldsetAuthToken(); + void shouldSetServerUrl(); + void shouldSetUserName(); + void shouldSetPassword(); }; #endif // ROCKETCHATACCOUNTSETTINGSTEST_H + + diff --git a/autotests/rocketchataccountsettingstest.cpp b/autotests/rocketchataccountsettingstest.cpp --- a/autotests/rocketchataccountsettingstest.cpp +++ b/autotests/rocketchataccountsettingstest.cpp @@ -22,6 +22,7 @@ #include "rocketchataccountsettings.h" #include #include + QTEST_MAIN(RocketChatAccountSettingsTest) RocketChatAccountSettingsTest::RocketChatAccountSettingsTest(QObject *parent) @@ -29,46 +30,137 @@ { } +void RocketChatAccountSettingsTest::shouldEmitSignalWhenSetServerURLCalled() +{ + RocketChatAccountSettings *SampleChatAccount = new RocketChatAccountSettings; + + QSignalSpy SpyURL(SampleChatAccount, &RocketChatAccountSettings::serverURLChanged); + SampleChatAccount->setServerUrl(QStringLiteral("bla bla")); + QCOMPARE(SpyURL.count(), 1); + + delete SampleChatAccount; +} + +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() +{ + RocketChatAccountSettings *SampleChatAccount = new RocketChatAccountSettings; + + QSignalSpy SpyLoginStatus(SampleChatAccount, &RocketChatAccountSettings::loginStatusChanged); + SampleChatAccount->logout(); + QCOMPARE(SpyLoginStatus.count(), 0); + + delete SampleChatAccount; +} + +void RocketChatAccountSettingsTest::shouldSetAccountName() +{ + RocketChatAccountSettings *sampleChat = new RocketChatAccountSettings; + + sampleChat->setAccountName(QStringLiteral("myAccount#$^56")); + + QCOMPARE(QStringLiteral("myAccount#$^56"), sampleChat->accountName()); + + delete sampleChat; +} + +void RocketChatAccountSettingsTest::shouldsetAuthToken() +{ + RocketChatAccountSettings *sampleChat = new RocketChatAccountSettings; + + sampleChat->setAuthToken(QStringLiteral("myAuthToken#$^56")); + + QCOMPARE(QStringLiteral("myAuthToken#$^56"), sampleChat->authToken()); + + delete sampleChat; +} + +void RocketChatAccountSettingsTest::shouldSetPassword() +{ + RocketChatAccountSettings *sampleChat = new RocketChatAccountSettings; + + sampleChat->setPassword(QStringLiteral("myPass#$^56")); + + QCOMPARE(QStringLiteral("myPass#$^56"), sampleChat->password()); + + delete sampleChat; +} + +void RocketChatAccountSettingsTest::shouldSetServerUrl() +{ + RocketChatAccountSettings *sampleChat = new RocketChatAccountSettings; + + sampleChat->setServerUrl(QStringLiteral("my.fancy.url")); + + QCOMPARE(QStringLiteral("my.fancy.url"), sampleChat->serverUrl()); + + delete sampleChat; +} + +void RocketChatAccountSettingsTest::shouldSetUserID() +{ + RocketChatAccountSettings *sampleChat = new RocketChatAccountSettings; + + sampleChat->setUserId(QStringLiteral("ECE305")); + + QCOMPARE(QStringLiteral("ECE305"), sampleChat->userId()); + + delete sampleChat; +} + +void RocketChatAccountSettingsTest::shouldSetUserName() +{ + RocketChatAccountSettings *sampleChat = new RocketChatAccountSettings; + + sampleChat->setUserName(QStringLiteral("Eric Roberts")); + + QCOMPARE(QStringLiteral("Eric Roberts"), sampleChat->userName()); + + delete sampleChat; +} /* * @brief * All the methods which have return value type as QString * in rocketchataccountsettings.h should return empty QString. * - * Check all the Q_Signals declared in rocketchataccountsettings.h * */ void RocketChatAccountSettingsTest::shouldHaveDefaultValues() { - RocketChatAccountSettings *SampleChatAccount = new RocketChatAccountSettings; - - QVERIFY(SampleChatAccount->accountName().isEmpty()); - QVERIFY(SampleChatAccount->authToken().isEmpty()); - QVERIFY(SampleChatAccount->cacheBasePath().isEmpty()); - QVERIFY(SampleChatAccount->userId().isEmpty()); - QVERIFY(SampleChatAccount->userName().isEmpty()); - QVERIFY(SampleChatAccount->password().isEmpty()); - QVERIFY(SampleChatAccount->serverUrl().isEmpty()); - - - - QSignalSpy SpyURL(SampleChatAccount, SIGNAL(serverURLChanged())); - SampleChatAccount->serverURLChanged(); - QVERIFY(SpyURL.isValid()); - - QSignalSpy SpyName(SampleChatAccount, SIGNAL(userNameChanged())); - SampleChatAccount->userNameChanged(); - QVERIFY(SpyName.isValid()); + RocketChatAccountSettings chat; - QSignalSpy SpyID(SampleChatAccount, SIGNAL(userIDChanged())); - SampleChatAccount->userIDChanged(); - QVERIFY(SpyID.isValid()); + 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()); - QSignalSpy SpyLoginStatus(SampleChatAccount, SIGNAL(loginStatusChanged())); - SampleChatAccount->userIDChanged(); - QVERIFY(SpyLoginStatus.isValid()); + chat.loadSettings(); + QVERIFY(chat.userId().isEmpty()); + QVERIFY(chat.userName().isEmpty()); + QVERIFY(chat.authToken().isEmpty()); + QCOMPARE(chat.serverUrl(), QStringLiteral("demo.rocket.chat")); - SampleChatAccount->loadSettings(); - QVERIFY(SampleChatAccount->userId().isEmpty()); - QVERIFY(SampleChatAccount->userName().isEmpty()); - QVERIFY(SampleChatAccount->authToken().isEmpty()); - QCOMPARE(SampleChatAccount->serverUrl(), QStringLiteral("demo.rocket.chat")); }