File indexing completed on 2024-12-01 04:35:26

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "reactionstest.h"
0008 #include "messages/reactions.h"
0009 #include "ruqola_autotest_helper.h"
0010 #include <QDebug>
0011 #include <QJsonObject>
0012 
0013 QTEST_GUILESS_MAIN(ReactionsTest)
0014 
0015 ReactionsTest::ReactionsTest(QObject *parent)
0016     : QObject(parent)
0017 {
0018 }
0019 
0020 void ReactionsTest::shouldHaveDefaultValue()
0021 {
0022     Reactions reacts;
0023     QVERIFY(reacts.reactions().isEmpty());
0024     QVERIFY(reacts.isEmpty());
0025 }
0026 
0027 void ReactionsTest::shouldParseReactions_data()
0028 {
0029     QTest::addColumn<QString>("name");
0030     QTest::addColumn<Reactions>("expectedReactions");
0031     {
0032         Reactions reactionsRef;
0033         Reaction react;
0034         react.setReactionName(QStringLiteral(":ok_hand:"));
0035         react.setUserNames(QStringList() << QStringLiteral("foo") << QStringLiteral("bla") << QStringLiteral("bli"));
0036         reactionsRef.setReactions({react});
0037         QTest::addRow("reactions") << QStringLiteral("reactions") << reactionsRef;
0038     }
0039     {
0040         Reactions reactionsRef;
0041         Reaction react;
0042         react.setReactionName(QStringLiteral(":mrs_claus:"));
0043         react.setUserNames(QStringList() << QStringLiteral("bla"));
0044         Reaction react2;
0045         react2.setReactionName(QStringLiteral(":right_facing_fist:"));
0046         react2.setUserNames(QStringList() << QStringLiteral("bli"));
0047         reactionsRef.setReactions({react, react2});
0048         QTest::addRow("reactions2") << QStringLiteral("reactions2") << reactionsRef;
0049     }
0050 }
0051 
0052 void ReactionsTest::shouldParseReactions()
0053 {
0054     QFETCH(QString, name);
0055     QFETCH(Reactions, expectedReactions);
0056     const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/json/") + name + QLatin1String(".json");
0057     const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile);
0058     Reactions originalReactions;
0059     originalReactions.parseReactions(obj);
0060     const bool emojiIsEqual = (originalReactions == expectedReactions);
0061     if (!emojiIsEqual) {
0062         qDebug() << "originalReactions " << originalReactions;
0063         qDebug() << "expectedReactions " << expectedReactions;
0064     }
0065     QVERIFY(emojiIsEqual);
0066 }
0067 
0068 #include "moc_reactionstest.cpp"