File indexing completed on 2024-05-12 16:25:22

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #include "bannerinfotest.h"
0007 #include "bannerinfo/bannerinfo.h"
0008 #include "ruqola_autotest_helper.h"
0009 
0010 QTEST_GUILESS_MAIN(BannerInfoTest)
0011 BannerInfoTest::BannerInfoTest(QObject *parent)
0012     : QObject{parent}
0013 {
0014 }
0015 
0016 void BannerInfoTest::shouldHaveDefaultValues()
0017 {
0018     BannerInfo w;
0019     QVERIFY(!w.read());
0020     QVERIFY(w.text().isEmpty());
0021     QVERIFY(w.title().isEmpty());
0022     QVERIFY(w.link().isEmpty());
0023     QVERIFY(w.textArguments().isEmpty());
0024     QVERIFY(w.identifier().isEmpty());
0025     QCOMPARE(w.priority(), -1);
0026 }
0027 
0028 void BannerInfoTest::shouldBannerInfo()
0029 {
0030     QFETCH(QString, name);
0031     QFETCH(BannerInfo, bannerInfo);
0032     const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/bannerinfo/") + name + QLatin1String(".json");
0033     const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile);
0034 
0035     BannerInfo result;
0036     result.parseBannerInfo(obj);
0037     const bool equal = result == bannerInfo;
0038     if (!equal) {
0039         qDebug() << " result " << result;
0040         qDebug() << " bannerInfo " << bannerInfo;
0041     }
0042     QVERIFY(equal);
0043 }
0044 
0045 void BannerInfoTest::shouldBannerInfo_data()
0046 {
0047     QTest::addColumn<QString>("name");
0048     QTest::addColumn<BannerInfo>("bannerInfo");
0049     QTest::addRow("bannerinfoempty") << QStringLiteral("bannerinfoempty") << BannerInfo();
0050     {
0051         BannerInfo info;
0052         info.setIdentifier(QStringLiteral("alert-5fcc1f02f5204d09050943d2"));
0053         info.setLink(QStringLiteral("https://github.com/RocketChat/Rocket.Chat/releases/tag/3.9.1"));
0054         info.setPriority(10);
0055         info.setRead(true);
0056         info.setText(QStringLiteral("For all installations using SAML Please upgrade as soon as possible.  3.9.1 / 3.8.3 / 3.7.3 / 2.4.13 / 1.3.4 / 0.74.4"));
0057         info.setTitle(QStringLiteral("Attn: Important Security fix"));
0058         QTest::addRow("bannerinfo1") << QStringLiteral("bannerinfo1") << info;
0059     }
0060     {
0061         BannerInfo info;
0062         info.setIdentifier(QStringLiteral("versionUpdate-4_4_1"));
0063         info.setLink(QStringLiteral("https://github.com/RocketChat/Rocket.Chat/releases/tag/4.4.1"));
0064         info.setPriority(10);
0065         info.setText(QStringLiteral("New_version_available_(s)"));
0066         info.setTextArguments(QStringList({QStringLiteral("4.4.1")}));
0067         info.setTitle(QStringLiteral("Update_your_RocketChat"));
0068         QTest::addRow("bannerinfo2") << QStringLiteral("bannerinfo2") << info;
0069     }
0070 }
0071 
0072 #include "moc_bannerinfotest.cpp"