Warning, file /network/neochat/autotests/neochatroomtest.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 <QObject>
0005 #include <QSignalSpy>
0006 #include <QTest>
0007 
0008 #include "neochatroom.h"
0009 
0010 #include <Quotient/connection.h>
0011 #include <Quotient/quotient_common.h>
0012 #include <Quotient/syncdata.h>
0013 
0014 using namespace Quotient;
0015 
0016 class TestRoom : public NeoChatRoom
0017 {
0018 public:
0019     using NeoChatRoom::NeoChatRoom;
0020 
0021     void update(SyncRoomData &&data, bool fromCache = false)
0022     {
0023         Room::updateData(std::move(data), fromCache);
0024     }
0025 };
0026 
0027 class NeoChatRoomTest : public QObject {
0028     Q_OBJECT
0029 
0030 private:
0031     Connection *connection = nullptr;
0032     TestRoom *room = nullptr;
0033 
0034 private Q_SLOTS:
0035     void initTestCase();
0036     void subtitleTextTest();
0037     void eventTest();
0038 };
0039 
0040 void NeoChatRoomTest::initTestCase()
0041 {
0042     connection = Connection::makeMockConnection(QStringLiteral("@bob:kde.org"));
0043     room = new TestRoom(connection, QStringLiteral("#myroom:kde.org"), JoinState::Join);
0044 
0045     auto json = QJsonDocument::fromJson(R"EVENT({
0046   "account_data": {
0047     "events": [
0048       {
0049         "content": {
0050           "tags": {
0051             "u.work": {
0052               "order": 0.9
0053             }
0054           }
0055         },
0056         "type": "m.tag"
0057       },
0058       {
0059         "content": {
0060           "custom_config_key": "custom_config_value"
0061         },
0062         "type": "org.example.custom.room.config"
0063       }
0064     ]
0065   },
0066   "ephemeral": {
0067     "events": [
0068       {
0069         "content": {
0070           "user_ids": [
0071             "@alice:matrix.org",
0072             "@bob:example.com"
0073           ]
0074         },
0075         "room_id": "!jEsUZKDJdhlrceRyVU:example.org",
0076         "type": "m.typing"
0077       }
0078     ]
0079   },
0080   "state": {
0081     "events": [
0082       {
0083         "content": {
0084           "avatar_url": "mxc://example.org/SEsfnsuifSDFSSEF",
0085           "displayname": "Alice Margatroid",
0086           "membership": "join",
0087           "reason": "Looking for support"
0088         },
0089         "event_id": "$143273582443PhrSn:example.org",
0090         "origin_server_ts": 1432735824653,
0091         "room_id": "!jEsUZKDJdhlrceRyVU:example.org",
0092         "sender": "@example:example.org",
0093         "state_key": "@alice:example.org",
0094         "type": "m.room.member",
0095         "unsigned": {
0096           "age": 1234
0097         }
0098       }
0099     ]
0100   },
0101   "summary": {
0102     "m.heroes": [
0103       "@alice:example.com",
0104       "@bob:example.com"
0105     ],
0106     "m.invited_member_count": 0,
0107     "m.joined_member_count": 2
0108   },
0109   "timeline": {
0110     "events": [
0111       {
0112         "content": {
0113           "body": "This is an **example** text message",
0114           "format": "org.matrix.custom.html",
0115           "formatted_body": "<b>This is an example text message</b>",
0116           "msgtype": "m.text"
0117         },
0118         "event_id": "$143273582443PhrSn:example.org",
0119         "origin_server_ts": 1432735824654,
0120         "room_id": "!jEsUZKDJdhlrceRyVU:example.org",
0121         "sender": "@example:example.org",
0122         "type": "m.room.message",
0123         "unsigned": {
0124           "age": 1235
0125         }
0126       }
0127     ],
0128     "limited": true,
0129     "prev_batch": "t34-23535_0_0"
0130   }
0131 })EVENT");
0132     SyncRoomData roomData(QStringLiteral("@bob:kde.org"), JoinState::Join, json.object());
0133     room->update(std::move(roomData));
0134 }
0135 
0136 void NeoChatRoomTest::subtitleTextTest()
0137 {
0138     QCOMPARE(room->timelineSize(), 1);
0139     QCOMPARE(room->lastEventToString(), QStringLiteral("@example:example.org: This is an example text message"));
0140 }
0141 
0142 void NeoChatRoomTest::eventTest()
0143 {
0144     QCOMPARE(room->timelineSize(), 1);
0145 }
0146 
0147 QTEST_GUILESS_MAIN(NeoChatRoomTest)
0148 #include "neochatroomtest.moc"