File indexing completed on 2024-10-06 12:56:09

0001 // SPDX-FileCopyrightText: 2023 Rishi Kumar <rsi.dev17@gmail.com>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #include "account/accountmanager.h"
0005 #include "admin/federationtoolmodel.h"
0006 #include "helperreply.h"
0007 #include "mockaccount.h"
0008 
0009 #include <QAbstractItemModelTester>
0010 #include <QSignalSpy>
0011 #include <QtTest/QtTest>
0012 
0013 class FederationToolTest : public QObject
0014 {
0015     Q_OBJECT
0016 
0017 private Q_SLOTS:
0018     void initTestCase()
0019     {
0020         account = new MockAccount();
0021         AccountManager::instance().addAccount(account);
0022         AccountManager::instance().selectAccount(account);
0023     }
0024 
0025     void cleanupTestCase()
0026     {
0027         AccountManager::instance().removeAccount(account);
0028     }
0029 
0030     void testModel()
0031     {
0032         QUrl url = account->apiUrl("/api/v1/admin/domain_blocks");
0033         account->registerGet(url, new TestReply("federation-info.json", account));
0034 
0035         FederationToolModel federationToolModel;
0036         QCOMPARE(federationToolModel.rowCount({}), 2);
0037         QCOMPARE(federationToolModel.data(federationToolModel.index(0, 0), FederationToolModel::IdRole).toInt(), 1);
0038         QCOMPARE(federationToolModel.data(federationToolModel.index(0, 0), FederationToolModel::DomainRole).toUrl(), QUrl("kde.org"));
0039         Q_ASSERT(federationToolModel.data(federationToolModel.index(0, 0), FederationToolModel::CreatedAtRole).isValid());
0040         QCOMPARE(federationToolModel.data(federationToolModel.index(0, 0), FederationToolModel::SeverityRole).toString(), "silence");
0041         QCOMPARE(federationToolModel.data(federationToolModel.index(0, 0), FederationToolModel::RejectMediaRole).toBool(), false);
0042         QCOMPARE(federationToolModel.data(federationToolModel.index(0, 0), FederationToolModel::RejectReportsRole).toBool(), false);
0043         QCOMPARE(federationToolModel.data(federationToolModel.index(0, 0), FederationToolModel::PrivateCommentRole).toString(), "This is a private comment");
0044         QCOMPARE(federationToolModel.data(federationToolModel.index(0, 0), FederationToolModel::PublicCommentRole).toString(), "This is a public comment");
0045         QCOMPARE(federationToolModel.data(federationToolModel.index(0, 0), FederationToolModel::ObfuscateRole).toBool(), false);
0046     }
0047 
0048 private:
0049     MockAccount *account;
0050 };
0051 
0052 QTEST_MAIN(FederationToolTest)
0053 #include "federationtooltest.moc"