Changeset View
Changeset View
Standalone View
Standalone View
src/tests/matrix-sticker-pack-test.cpp
| Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | "content": { | ||||
| "pack": { | "pack": { | ||||
| "display_name": "Awesome Pack", | "display_name": "Awesome Pack", | ||||
| "usage": ["emoticon"] | "usage": ["emoticon"] | ||||
| } | } | ||||
| }, | }, | ||||
| "type": "im.ponies.user_emotes" | "type": "im.ponies.user_emotes" | ||||
| })"_json}; | })"_json}; | ||||
| static const auto imagePackRoomsEvent = Event(R"({ | |||||
| "content": { | |||||
| "rooms": { | |||||
| "!someroom:example.org": { | |||||
| "": {}, | |||||
| "de.sorunome.mx-puppet-bridge.discord": {} | |||||
| }, | |||||
| "!someotherroom:example.org": { | |||||
| "": {} | |||||
| } | |||||
| } | |||||
| }, | |||||
| "type": "im.ponies.emote_rooms" | |||||
| })"_json); | |||||
| static Event getRoomStickersEvent(std::string stateKey, std::string name) | |||||
| { | |||||
| auto j = R"({ | |||||
| "content": { | |||||
| "images": { | |||||
| "myemote": { | |||||
| "url": "mxc://example.org/blah" | |||||
| }, | |||||
| "mysticker": { | |||||
| "body": "my sticker", | |||||
| "url": "mxc://example.org/sticker", | |||||
| "usage": ["sticker"], | |||||
| "info": { | |||||
| "mimetype": "image/png" | |||||
| } | |||||
| } | |||||
| }, | |||||
| "pack": { | |||||
| "usage": ["emoticon"] | |||||
| } | |||||
| }, | |||||
| "type": "im.ponies.room_emotes" | |||||
| })"_json; | |||||
| j["state_key"] = stateKey; | |||||
| j["content"]["pack"]["display_name"] = name; | |||||
| return Event(j); | |||||
| } | |||||
| void MatrixStickerPackTest::testStickerPack() | void MatrixStickerPackTest::testStickerPack() | ||||
| { | { | ||||
| auto sourceCursor = lager::make_state(MatrixStickerPackSource{ | auto sourceCursor = lager::make_state(MatrixStickerPackSource{ | ||||
| MatrixStickerPackSource::AccountData, | MatrixStickerPackSource::AccountData, | ||||
| "im.ponies.user_emotes", | "im.ponies.user_emotes", | ||||
| stickerPackEvent, | stickerPackEvent, | ||||
| }, lager::automatic_tag{}); | }, lager::automatic_tag{}); | ||||
| Show All 30 Lines | QCOMPARE(sticker1->makeEventJson(), (QJsonObject{ | ||||
| {u"url"_s, u"mxc://example.org/sticker"_s}, | {u"url"_s, u"mxc://example.org/sticker"_s}, | ||||
| {u"info"_s, QJsonObject{{u"mimetype"_s, u"image/png"_s}}}, | {u"info"_s, QJsonObject{{u"mimetype"_s, u"image/png"_s}}}, | ||||
| }}, | }}, | ||||
| })); | })); | ||||
| } | } | ||||
| void MatrixStickerPackTest::testStickerPackList() | void MatrixStickerPackTest::testStickerPackList() | ||||
| { | { | ||||
| auto model = makeClient(withAccountData({stickerPackEvent})); | auto model = makeClient( | ||||
| withAccountData({stickerPackEvent, imagePackRoomsEvent}) | |||||
| | withRoom(makeRoom( | |||||
| withRoomId("!someroom:example.org") | |||||
| | withRoomState({ | |||||
| getRoomStickersEvent("", "Pack 1"), | |||||
| getRoomStickersEvent("de.sorunome.mx-puppet-bridge.discord", "Pack 2"), | |||||
| }) | |||||
| )) | |||||
| | withRoom(makeRoom( | |||||
| withRoomId("!someotherroom:example.org") | |||||
| | withRoomState({getRoomStickersEvent("", "Pack 3")}) | |||||
| )) | |||||
| ); | |||||
| std::unique_ptr<MatrixSdk> sdk{makeTestSdk(SdkModel{model})}; | std::unique_ptr<MatrixSdk> sdk{makeTestSdk(SdkModel{model})}; | ||||
| auto stickerPackList = toUniquePtr(sdk->stickerPackList()); | auto stickerPackList = toUniquePtr(sdk->stickerPackList()); | ||||
| QCOMPARE(stickerPackList->rowCount(QModelIndex()), 1); | QCOMPARE(stickerPackList->rowCount(QModelIndex()), 4); | ||||
| QCOMPARE(stickerPackList->count(), 1); | QCOMPARE(stickerPackList->count(), 4); | ||||
| auto stickerPack = toUniquePtr(stickerPackList->at(0)); | auto packs = std::array<std::unique_ptr<MatrixStickerPack>, 4>{ | ||||
| QCOMPARE(stickerPack->count(), 2); | toUniquePtr(stickerPackList->at(0)), | ||||
| toUniquePtr(stickerPackList->at(1)), | |||||
| toUniquePtr(stickerPackList->at(2)), | |||||
| toUniquePtr(stickerPackList->at(3)), | |||||
| }; | |||||
| auto hasPack = [&packs](const QString &name) { | |||||
| return std::any_of(packs.begin(), packs.end(), [&name](const auto &pack) { | |||||
| return pack->packName() == name; | |||||
| }); | |||||
| }; | |||||
| QVERIFY(hasPack(u"Awesome Pack"_s)); | |||||
| QVERIFY(hasPack(u"Pack 1"_s)); | |||||
| QVERIFY(hasPack(u"Pack 2"_s)); | |||||
| QVERIFY(hasPack(u"Pack 3"_s)); | |||||
| } | } | ||||
| void MatrixStickerPackTest::testAddToPack() | void MatrixStickerPackTest::testAddToPack() | ||||
| { | { | ||||
| using namespace nlohmann::literals; | using namespace nlohmann::literals; | ||||
| auto sourceCursor = lager::make_state(MatrixStickerPackSource{ | auto sourceCursor = lager::make_state(MatrixStickerPackSource{ | ||||
| MatrixStickerPackSource::AccountData, | MatrixStickerPackSource::AccountData, | ||||
| Show All 27 Lines | |||||