File indexing completed on 2024-10-06 12:56:09
0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> 0002 // SPDX-License-Identifier: LGPL-2.1-or-later 0003 0004 #include <QtTest/QtTest> 0005 0006 #include "account/accountmanager.h" 0007 #include "helperreply.h" 0008 #include "mockaccount.h" 0009 #include "editor/posteditorbackend.h" 0010 0011 class PostEditorTest : 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 PostEditorBackend backend; 0031 backend.setAccount(account); 0032 0033 QCOMPARE(backend.account(), account); 0034 QCOMPARE(backend.charactersLeft(), 500); 0035 0036 const QString status{"Hello, world!"}; 0037 backend.setStatus(status); 0038 0039 QCOMPARE(backend.status(), status); 0040 QCOMPARE(backend.charactersLeft(), 487); 0041 0042 const QString longStatus{ 0043 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Duis ultricies lacus " 0044 "sed turpis tincidunt. Vestibulum lectus mauris ultrices eros. Tristique senectus et netus et malesuada fames ac turpis. Fringilla ut morbi " 0045 "tincidunt augue interdum. Ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue eget. Sociis natoque penatibus et magnis dis. Et " 0046 "odio pellentesque diam volutpat commodo. Ligula ullamcorper malesuada proin libero. Curabitur gravida arcu ac tortor dignissim."}; 0047 backend.setStatus(longStatus); 0048 0049 QCOMPARE(backend.charactersLeft(), -57); 0050 0051 const QString urlStatus{"Lorem ipsum dolor sit amet, https://www.google.com/"}; 0052 backend.setStatus(urlStatus); 0053 0054 QCOMPARE(backend.charactersLeft(), 449); 0055 0056 const QString twoUrlStatus{"https://www.google.com/https://www.google.com/"}; 0057 backend.setStatus(twoUrlStatus); 0058 0059 QCOMPARE(backend.charactersLeft(), 477); 0060 } 0061 0062 private: 0063 MockAccount *account; 0064 }; 0065 0066 QTEST_MAIN(PostEditorTest) 0067 #include "posteditortest.moc"