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

0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 #include <QtTest/QtTest>
0005 
0006 #include "conversation/conversationmodel.h"
0007 #include "timeline/abstracttimelinemodel.h"
0008 #include "helperreply.h"
0009 #include "mockaccount.h"
0010 #include <QAbstractItemModelTester>
0011 #include <QSignalSpy>
0012 
0013 class ConversationModelTest : public QObject
0014 {
0015     Q_OBJECT
0016 
0017 private Q_SLOTS:
0018     void initTestCase()
0019     {
0020     }
0021 
0022     void testModel()
0023     {
0024         auto account = new MockAccount();
0025         AccountManager::instance().addAccount(account);
0026         AccountManager::instance().selectAccount(account);
0027         QUrl url = account->apiUrl("/api/v1/conversations");
0028         account->registerGet(url, new TestReply("conversation-result.json", account));
0029 
0030         ConversationModel conversationModel;
0031 
0032         QCOMPARE(conversationModel.rowCount({}), 1);
0033         QCOMPARE(conversationModel.data(conversationModel.index(0, 0), AbstractTimelineModel::AuthorIdentityRole).value<Identity *>()->avatarUrl(),
0034                  QUrl("https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg"));
0035         QCOMPARE(conversationModel.data(conversationModel.index(0, 0), AbstractTimelineModel::AuthorIdentityRole).value<Identity *>()->account(), "Gargron");
0036         QCOMPARE(conversationModel.data(conversationModel.index(0, 0), ConversationModel::ConversationIdRole).toString(), "418374");
0037         QCOMPARE(conversationModel.data(conversationModel.index(0, 0), ConversationModel::UnreadRole), false);
0038         QCOMPARE(conversationModel.data(conversationModel.index(0, 0), AbstractTimelineModel::ContentRole), QStringLiteral("LOREM"));
0039         QCOMPARE(conversationModel.data(conversationModel.index(0, 0), AbstractTimelineModel::AuthorIdentityRole).value<Identity *>()->displayName(),
0040                  QStringLiteral("Eugen"));
0041     }
0042 };
0043 
0044 QTEST_MAIN(ConversationModelTest)
0045 #include "conversationmodeltest.moc"