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

0001 /*
0002    SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "discussiontest.h"
0008 #include "discussions/discussion.h"
0009 #include "ruqola_autotest_helper.h"
0010 #include <QJsonObject>
0011 
0012 QTEST_GUILESS_MAIN(DiscussionTest)
0013 DiscussionTest::DiscussionTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void DiscussionTest::shouldHaveDefaultValue()
0019 {
0020     Discussion discussion;
0021     QVERIFY(discussion.description().isEmpty());
0022     QVERIFY(discussion.parentRoomId().isEmpty());
0023     QCOMPARE(discussion.numberMessages(), 0);
0024     QCOMPARE(discussion.lastMessage(), -1);
0025     QVERIFY(discussion.discussionRoomId().isEmpty());
0026     QCOMPARE(discussion.timeStamp(), -1);
0027     QVERIFY(discussion.timeStampDisplay().isEmpty());
0028     QVERIFY(discussion.fname().isEmpty());
0029     QVERIFY(discussion.userName().isEmpty());
0030 }
0031 
0032 void DiscussionTest::shouldLoadDiscussion_data()
0033 {
0034     QTest::addColumn<QString>("name");
0035     QTest::addColumn<Discussion>("discussion");
0036 
0037     QTest::addRow("empty") << QStringLiteral("discussion-empty") << Discussion();
0038     Discussion discussion;
0039 
0040     discussion.setNumberMessages(0);
0041     discussion.setDiscussionRoomId(QStringLiteral("652e69986a344bea24b4ce55"));
0042     discussion.setTimeStamp(1697540504599);
0043     discussion.setUserName(QStringLiteral("bla"));
0044     QTest::addRow("one-discussion") << QStringLiteral("one-discussion") << discussion;
0045 }
0046 
0047 void DiscussionTest::shouldLoadDiscussion()
0048 {
0049     QFETCH(QString, name);
0050     QFETCH(Discussion, discussion);
0051     const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/discussion/") + name + QLatin1String(".json");
0052     const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile);
0053     Discussion m;
0054     m.parseDiscussion(obj);
0055     QCOMPARE(m, discussion);
0056 }
0057 
0058 #include "moc_discussiontest.cpp"