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.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); 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")), new TestReply("verify_credentials.json", account)); 0031 0032 ProfileEditorBackend backend; 0033 account->setUsername("trwnh"); 0034 backend.setAccount(account); 0035 QCOMPARE(backend.account(), account); 0036 QCOMPARE(backend.displayName(), "infinite love ⴳ"); 0037 QCOMPARE(backend.note(), 0038 "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 " 0039 "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 " 0040 "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 " 0041 "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:"); 0042 QCOMPARE(backend.privacy(), "public"); 0043 QCOMPARE(backend.sensitive(), false); 0044 QCOMPARE(backend.language(), "fr"); 0045 QCOMPARE(backend.bot(), false); 0046 QCOMPARE(backend.avatarUrl(), QUrl("https://files.mastodon.social/accounts/avatars/000/014/715/original/34aa222f4ae2e0a9.png")); 0047 QCOMPARE(backend.backgroundUrl(), QUrl("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")), new TestReply("verify_credentials.json", account)); 0053 ProfileEditorBackend backend; 0054 account->setUsername("trwnh"); 0055 backend.setAccount(account); 0056 backend.setDisplayName("Hello"); 0057 backend.setAvatarUrl(QUrl(QLatin1String(DATA_DIR) + QLatin1String("/test.png"))); 0058 backend.setBackgroundUrl(QUrl(QLatin1String(DATA_DIR) + QLatin1String("/test.png"))); 0059 QCOMPARE("Hello", backend.displayName()); 0060 QCOMPARE(QUrl(QLatin1String(DATA_DIR) + QLatin1String("/test.png")), backend.avatarUrl()); 0061 QCOMPARE(QUrl(QLatin1String(DATA_DIR) + QLatin1String("/test.png")), backend.backgroundUrl()); 0062 QCOMPARE(QString(), backend.backgroundUrlError()); 0063 QCOMPARE(QString(), backend.avatarUrlError()); 0064 } 0065 0066 private: 0067 MockAccount *account; 0068 }; 0069 0070 QTEST_MAIN(ProfileEditorTest) 0071 #include "profileeditortest.moc"