// SPDX-FileCopyrightText: 2024 Tobias Fella // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL #include #include #include "chatbarcache.h" #include "models/actionsmodel.h" #include "testutils.h" using namespace Quotient; class ActionsTest : public QObject { Q_OBJECT private: Connection *connection = nullptr; TestUtils::TestRoom *room = nullptr; private Q_SLOTS: void initTestCase(); void testActions(); void testActions_data(); }; void ActionsTest::initTestCase() { connection = Connection::makeMockConnection(QStringLiteral("@bob:kde.org")); room = new TestUtils::TestRoom(connection, QStringLiteral("#myroom:kde.org"), QLatin1String("test-min-sync.json")); } void ActionsTest::testActions_data() { QTest::addColumn("command"); QTest::addColumn>("resultText"); QTest::addColumn>("type"); QTest::newRow("shrug") << u"/shrug Hello"_s << std::make_optional(u"¯\\\\_(ツ)_/¯ Hello"_s) << std::optional(); QTest::newRow("lenny") << u"/lenny Hello"_s << std::make_optional(u"( ͡° ͜ʖ ͡°) Hello"_s) << std::optional(); QTest::newRow("tableflip") << u"/tableflip Hello"_s << std::make_optional(u"(╯°□°)╯︵ ┻━┻ Hello"_s) << std::optional(); QTest::newRow("unflip") << u"/unflip Hello"_s << std::make_optional(u"┬──┬ ノ( ゜-゜ノ) Hello"_s) << std::optional(); QTest::newRow("rainbow") << u"/rainbow Hello"_s << std::optional() << std::optional(); QTest::newRow("rainbowme") << u"/rainbowme Hello"_s << std::optional() << std::optional(); QTest::newRow("plain") << u"/plain Hello"_s << std::optional() << std::optional(); QTest::newRow("spoiler") << u"/spoiler Hello"_s << std::optional() << std::optional(); QTest::newRow("me") << u"/me Hello"_s << std::make_optional(u"Hello"_s) << std::make_optional(Quotient::RoomMessageEvent::MsgType::Emote), QTest::newRow("notice") << u"/notice Hello"_s << std::make_optional(u"Hello"_s) << std::make_optional(Quotient::RoomMessageEvent::MsgType::Notice), QTest::newRow("message") << u"Hello"_s << std::make_optional(u"Hello"_s) << std::optional(); } void ActionsTest::testActions() { QFETCH(QString, command); QFETCH(std::optional, resultText); QFETCH(std::optional, type); auto cache = new ChatBarCache(); cache->setText(command); auto result = ActionsModel::handleAction(room, cache); QCOMPARE(resultText, std::get>(result)); QCOMPARE(type, std::get>(result)); } QTEST_MAIN(ActionsTest) #include "actionstest.moc"