File indexing completed on 2024-04-28 05:02:16
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 0010 class SearchTest : public QObject 0011 { 0012 Q_OBJECT 0013 0014 private Q_SLOTS: 0015 void initTestCase() 0016 { 0017 } 0018 0019 void testModel() 0020 { 0021 auto account = new MockAccount(); 0022 AccountManager::instance().addAccount(account, false); 0023 AccountManager::instance().selectAccount(account); 0024 QUrl url = account->apiUrl(QStringLiteral("/api/v2/search")); 0025 url.setQuery(QUrlQuery{{QStringLiteral("q"), QStringLiteral("myQuery")}}); 0026 account->registerGet(url, new TestReply(QStringLiteral("search-result.json"), account)); 0027 0028 SearchModel searchModel; 0029 searchModel.search(QStringLiteral("myQuery")); 0030 0031 QCOMPARE(searchModel.rowCount({}), 3); 0032 QCOMPARE(searchModel.data(searchModel.index(0, 0), AbstractTimelineModel::TypeRole), SearchModel::Account); 0033 QCOMPARE(searchModel.data(searchModel.index(1, 0), AbstractTimelineModel::TypeRole), SearchModel::Status); 0034 QCOMPARE(searchModel.data(searchModel.index(0, 0), AbstractTimelineModel::AuthorIdentityRole).value<Identity *>()->avatarUrl(), 0035 QUrl(QStringLiteral("https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg"))); 0036 QCOMPARE(searchModel.data(searchModel.index(1, 0), AbstractTimelineModel::AuthorIdentityRole).value<Identity *>()->avatarUrl(), 0037 QUrl(QStringLiteral("https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg"))); 0038 } 0039 }; 0040 0041 QTEST_MAIN(SearchTest) 0042 #include "searchtest.moc"