File indexing completed on 2024-05-05 05:04:13
0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-License-Identifier: LGPL-2.1-or-later 0003 0004 #include <QtTest/QtTest> 0005 0006 #include "account/accountmanager.h" 0007 #include "account/profileeditor.h" 0008 #include "helperreply.h" 0009 #include "mockaccount.h" 0010 0011 class ProfileEditorTest : public QObject 0012 { 0013 Q_OBJECT 0014 0015 private Q_SLOTS: 0016 void initTestCase() 0017 { 0018 account = new MockAccount(); 0019 AccountManager::instance().addAccount(account, false); 0020 AccountManager::instance().selectAccount(account); 0021 } 0022 0023 void cleanupTestCase() 0024 { 0025 AccountManager::instance().removeAccount(account); 0026 } 0027 0028 void loadDataTest() 0029 { 0030 account->registerGet(account->apiUrl(QStringLiteral("/api/v1/accounts/verify_credentials")), 0031 new TestReply(QStringLiteral("verify_credentials.json"), account)); 0032 0033 ProfileEditorBackend backend; 0034 account->setUsername(QStringLiteral("trwnh")); 0035 backend.setAccount(account); 0036 QCOMPARE(backend.account(), account); 0037 QCOMPARE(backend.displayName(), QStringLiteral("infinite love ⴳ")); 0038 QCOMPARE( 0039 backend.note(), 0040 QStringLiteral( 0041 "i have approximate knowledge of many things. perpetual student. (nb/ace/they)\r\n\r\nxmpp/email: a@trwnh.com\r\nhttps://trwnh.com\r\nhelp me " 0042 "live: https://liberapay.com/at or https://paypal.me/trwnh\r\n\r\n- my triggers are moths and glitter\r\n- i have all notifs except mentions " 0043 "turned off, so please interact if you wanna be friends! i literally will not notice otherwise\r\n- dm me if i did something wrong, so i can " 0044 "improve\r\n- purest person on fedi, do not lewd in my presence\r\n- #1 ami cole fan account\r\n\r\n:fatyoshi:")); 0045 QCOMPARE(backend.bot(), false); 0046 QCOMPARE(backend.avatarUrl(), QUrl(QStringLiteral("https://files.mastodon.social/accounts/avatars/000/014/715/original/34aa222f4ae2e0a9.png"))); 0047 QCOMPARE(backend.backgroundUrl(), QUrl(QStringLiteral("https://files.mastodon.social/accounts/headers/000/014/715/original/5c6fc24edb3bb873.jpg"))); 0048 } 0049 0050 void setDataTest() 0051 { 0052 account->registerGet(account->apiUrl(QStringLiteral("/api/v1/accounts/verify_credentials")), 0053 new TestReply(QStringLiteral("verify_credentials.json"), account)); 0054 ProfileEditorBackend backend; 0055 account->setUsername(QStringLiteral("trwnh")); 0056 backend.setAccount(account); 0057 backend.setDisplayName(QStringLiteral("Hello")); 0058 backend.setAvatarUrl(QUrl(QLatin1String(DATA_DIR) + QLatin1String("/test.png"))); 0059 backend.setBackgroundUrl(QUrl(QLatin1String(DATA_DIR) + QLatin1String("/test.png"))); 0060 QCOMPARE(QStringLiteral("Hello"), backend.displayName()); 0061 QCOMPARE(QUrl(QLatin1String(DATA_DIR) + QLatin1String("/test.png")), backend.avatarUrl()); 0062 QCOMPARE(QUrl(QLatin1String(DATA_DIR) + QLatin1String("/test.png")), backend.backgroundUrl()); 0063 QCOMPARE(QString(), backend.backgroundUrlError()); 0064 QCOMPARE(QString(), backend.avatarUrlError()); 0065 } 0066 0067 private: 0068 MockAccount *account; 0069 }; 0070 0071 QTEST_MAIN(ProfileEditorTest) 0072 #include "profileeditortest.moc"