Warning, file /network/tokodon/src/autotests/searchtest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #include <QtTest/QtTest>
0005 
0006 #include "helperreply.h"
0007 #include "mockaccount.h"
0008 #include "search/searchmodel.h"
0009 #include <QAbstractItemModelTester>
0010 #include <QSignalSpy>
0011 
0012 class SearchTest : public QObject
0013 {
0014     Q_OBJECT
0015 
0016 private Q_SLOTS:
0017     void initTestCase()
0018     {
0019     }
0020 
0021     void testModel()
0022     {
0023         auto account = new MockAccount();
0024         AccountManager::instance().addAccount(account);
0025         AccountManager::instance().selectAccount(account);
0026         QUrl url = account->apiUrl("/api/v2/search");
0027         url.setQuery(QUrlQuery{{"q", "myQuery"}});
0028         account->registerGet(url, new TestReply("search-result.json", account));
0029 
0030         SearchModel searchModel;
0031         searchModel.search("myQuery");
0032 
0033         QCOMPARE(searchModel.rowCount({}), 3);
0034         QCOMPARE(searchModel.data(searchModel.index(0, 0), AbstractTimelineModel::TypeRole), SearchModel::Account);
0035         QCOMPARE(searchModel.data(searchModel.index(1, 0), AbstractTimelineModel::TypeRole), SearchModel::Status);
0036         QCOMPARE(searchModel.data(searchModel.index(0, 0), AbstractTimelineModel::AuthorIdentityRole).value<Identity *>()->avatarUrl(),
0037                  QUrl("https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg"));
0038         QCOMPARE(searchModel.data(searchModel.index(1, 0), AbstractTimelineModel::AuthorIdentityRole).value<Identity *>()->avatarUrl(),
0039                  QUrl("https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg"));
0040     }
0041 };
0042 
0043 QTEST_MAIN(SearchTest)
0044 #include "searchtest.moc"