File indexing completed on 2024-12-01 04:35:22

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "accountmanagertest.h"
0008 #include "accountmanager.h"
0009 #include "model/rocketchataccountfilterproxymodel.h"
0010 #include "model/rocketchataccountmodel.h"
0011 #include "rocketchataccount.h"
0012 #include <QTest>
0013 QTEST_GUILESS_MAIN(AccountManagerTest)
0014 
0015 AccountManagerTest::AccountManagerTest(QObject *parent)
0016     : QObject(parent)
0017 {
0018 }
0019 
0020 void AccountManagerTest::shouldHaveDefaultValue()
0021 {
0022     AccountManager w;
0023     QVERIFY(w.rocketChatAccountModel());
0024     QVERIFY(w.rocketChatAccountProxyModel());
0025     QCOMPARE(w.rocketChatAccountProxyModel()->sourceModel(), w.rocketChatAccountModel());
0026 
0027     QVERIFY(w.account());
0028 }
0029 
0030 void AccountManagerTest::shouldAddAccount()
0031 {
0032     AccountManager w;
0033     for (int i = 0; i < 10; ++i) {
0034         auto c = new RocketChatAccount();
0035         w.addAccount(c);
0036     }
0037     // We have a default account when we load account
0038     QCOMPARE(w.rocketChatAccountModel()->rowCount(), 11);
0039 }
0040 
0041 void AccountManagerTest::shouldReturnAccountFromAccountName()
0042 {
0043     AccountManager w;
0044     QVERIFY(!w.accountFromName(QStringLiteral("DDDD")));
0045 
0046     auto c = new RocketChatAccount();
0047     QString accountName = QStringLiteral("bla");
0048     c->setAccountName(accountName);
0049     w.addAccount(c);
0050     QVERIFY(w.accountFromName(accountName));
0051 
0052     QVERIFY(!w.accountFromName(QStringLiteral("DDDD")));
0053 
0054     accountName = QStringLiteral("bli");
0055     c = new RocketChatAccount();
0056     c->setAccountName(accountName);
0057     w.addAccount(c);
0058     QVERIFY(w.accountFromName(accountName));
0059     w.removeAccount(QStringLiteral("bla"));
0060     w.removeAccount(QStringLiteral("bli"));
0061 }
0062 
0063 #include "moc_accountmanagertest.cpp"