Changeset View
Changeset View
Standalone View
Standalone View
src/tests/matrix-room-timeline-test.cpp
| Show All 28 Lines | |||||
| class MatrixRoomTimelineTest : public QObject | class MatrixRoomTimelineTest : public QObject | ||||
| { | { | ||||
| Q_OBJECT | Q_OBJECT | ||||
| private Q_SLOTS: | private Q_SLOTS: | ||||
| void testLocalEcho(); | void testLocalEcho(); | ||||
| void testReadReceipts(); | void testReadReceipts(); | ||||
| void testEdits(); | |||||
| }; | }; | ||||
| void MatrixRoomTimelineTest::testLocalEcho() | void MatrixRoomTimelineTest::testLocalEcho() | ||||
| { | { | ||||
| auto model = makeTestModel(); | auto model = makeTestModel(); | ||||
| std::unique_ptr<MatrixSdk> sdk{makeTestSdk(model)}; | std::unique_ptr<MatrixSdk> sdk{makeTestSdk(model)}; | ||||
| auto roomList = toUniquePtr(sdk->roomList()); | auto roomList = toUniquePtr(sdk->roomList()); | ||||
| auto room = toUniquePtr(roomList->room("!foo:tusooa.xyz")); | auto room = toUniquePtr(roomList->room("!foo:tusooa.xyz")); | ||||
| Show All 39 Lines | void MatrixRoomTimelineTest::testReadReceipts() | ||||
| } | } | ||||
| { | { | ||||
| auto event = toUniquePtr(timeline->at(0)); | auto event = toUniquePtr(timeline->at(0)); | ||||
| QCOMPARE(event->eventId(), "$2"); | QCOMPARE(event->eventId(), "$2"); | ||||
| auto readers = toUniquePtr(event->readers()); | auto readers = toUniquePtr(event->readers()); | ||||
| QCOMPARE(readers->count(), 0); | QCOMPARE(readers->count(), 0); | ||||
| } | } | ||||
| } | |||||
| void MatrixRoomTimelineTest::testEdits() | |||||
| { | |||||
| auto r = makeRoom(withRoomTimeline({ | |||||
| makeEvent(withEventId("$0")), | |||||
| makeEvent(withEventId("$1") | withEventRelationship("moe.kazv.mxc.some-rel", "$0")), | |||||
| makeEvent(withEventId("$2") | withEventContent(json{{"body", "first"}}) | withEventRelationship("m.replace", "$1")), | |||||
| // valid | |||||
| makeEvent(withEventId("$3") | withEventContent(json{{"m.new_content", {{"body", "second"}}}}) | withEventRelationship("m.replace", "$1")), | |||||
| // also valid | |||||
| makeEvent(withEventId("$4") | withEventContent(json{{"m.new_content", {{"body", "third"}}}}) | withEventRelationship("m.replace", "$1")), | |||||
| // invalid, changed event type | |||||
| makeEvent(withEventId("$5") | withEventContent(json{{"m.new_content", {{"body", "fourth"}}}}) | withEventRelationship("m.replace", "$1") | withEventType("moe.kazv.mxc.some-other-type")), | |||||
| // invalid, changed event sender | |||||
| makeEvent(withEventId("$6") | withEventContent(json{{"m.new_content", {{"body", "fifth"}}}}) | withEventRelationship("m.replace", "$1") | withEventType("moe.kazv.mxc.some-other-type") | withEventSenderId("@othersender:example.com")), | |||||
| // invalid, has state key | |||||
| makeEvent(withEventId("$7") | withEventContent(json{{"m.new_content", {{"body", "sixth"}}}}) | withEventRelationship("m.replace", "$1") | withEventType("moe.kazv.mxc.some-other-type") | withStateKey("")), | |||||
| // invalid, no m.new_content | |||||
| makeEvent(withEventId("$8") | withEventContent(json{{"body", "seventh"}}) | withEventRelationship("m.replace", "$1") | withEventType("moe.kazv.mxc.some-other-type")), | |||||
| })); | |||||
| auto model = SdkModel{makeClient(withRoom(r))}; | |||||
| std::unique_ptr<MatrixSdk> sdk{makeTestSdk(model)}; | |||||
| auto roomList = toUniquePtr(sdk->roomList()); | |||||
| auto room = toUniquePtr(roomList->room(QString::fromStdString(r.roomId))); | |||||
| auto timeline = toUniquePtr(room->timeline()); | |||||
| auto event = toUniquePtr(timeline->at(7)); | |||||
| QCOMPARE(event->eventId(), "$1"); | |||||
| // the content is taken from the newest valid edit | |||||
| qDebug() << event->content(); | |||||
| QCOMPARE(event->content(), (QJsonObject{{"body", "third"}})); | |||||
| // the relation is taken from the original content | |||||
| QCOMPARE(event->relationType(), "moe.kazv.mxc.some-rel"); | |||||
| QCOMPARE(event->relatedEventId(), "$0"); | |||||
| QVERIFY(event->isEdited()); | |||||
| } | } | ||||
| QTEST_MAIN(MatrixRoomTimelineTest) | QTEST_MAIN(MatrixRoomTimelineTest) | ||||
| #include "matrix-room-timeline-test.moc" | #include "matrix-room-timeline-test.moc" | ||||