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 #include "discussionstest.h"
0007 #include "discussions/discussion.h"
0008 #include "discussions/discussions.h"
0009 #include "ruqola_autotest_helper.h"
0010 #include <QJsonObject>
0011 
0012 QTEST_GUILESS_MAIN(DiscussionsTest)
0013 
0014 DiscussionsTest::DiscussionsTest(QObject *parent)
0015     : QObject(parent)
0016 {
0017 }
0018 
0019 void DiscussionsTest::shouldHaveDefaultValues()
0020 {
0021     Discussions w;
0022     QVERIFY(w.isEmpty());
0023     QCOMPARE(w.offset(), 0);
0024     QCOMPARE(w.total(), 0);
0025     QCOMPARE(w.discussionsCount(), 0);
0026 }
0027 
0028 void DiscussionsTest::shouldLoadDiscussions_data()
0029 {
0030     QTest::addColumn<QString>("name");
0031     QTest::addColumn<int>("discussionsCount");
0032     QTest::addColumn<int>("total");
0033     QTest::addColumn<int>("offset");
0034 
0035     QTest::addRow("empty") << QStringLiteral("discussions-empty") << 0 << 0 << 0;
0036     QTest::addRow("1-element") << QStringLiteral("discussions-1-element") << 1 << 1 << 0;
0037 }
0038 
0039 void DiscussionsTest::shouldLoadDiscussions()
0040 {
0041     QFETCH(QString, name);
0042     QFETCH(int, discussionsCount);
0043     QFETCH(int, total);
0044     QFETCH(int, offset);
0045     const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/discussions/") + name + QLatin1String(".json");
0046     const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile);
0047     Discussions m;
0048     m.parseDiscussions(obj);
0049     QCOMPARE(m.discussionsCount(), discussionsCount);
0050     QCOMPARE(m.total(), total);
0051     QCOMPARE(m.offset(), offset);
0052 }
0053 
0054 #include "moc_discussionstest.cpp"