File indexing completed on 2024-05-12 05:13:47
0001 /* 0002 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "testhelper.h" 0008 0009 #include "applicationcontroller.h" 0010 #include "locationinformation.h" 0011 #include "reservationmanager.h" 0012 #include "tripgroup.h" 0013 #include "tripgroupmanager.h" 0014 #include "tripgroupinfoprovider.h" 0015 #include "weatherforecast.h" 0016 #include "weatherforecastmanager.h" 0017 0018 #include <QtTest/qtest.h> 0019 #include <QSignalSpy> 0020 #include <QStandardPaths> 0021 0022 class TripGroupInfoProviderTest : public QObject 0023 { 0024 Q_OBJECT 0025 private Q_SLOTS: 0026 void initTestCase() 0027 { 0028 qputenv("TZ", "UTC"); 0029 QStandardPaths::setTestModeEnabled(true); 0030 } 0031 0032 void testInfoProvider() 0033 { 0034 ReservationManager resMgr; 0035 Test::clearAll(&resMgr); 0036 TripGroupManager::clear(); 0037 TripGroupManager mgr; 0038 mgr.setReservationManager(&resMgr); 0039 WeatherForecastManager fcMgr; 0040 fcMgr.setTestModeEnabled(true); 0041 auto ctrl = Test::makeAppController(); 0042 ctrl->setReservationManager(&resMgr); 0043 0044 ctrl->importFromUrl(QUrl::fromLocalFile(QLatin1StringView(SOURCE_DIR "/../tests/randa2017.json"))); 0045 QCOMPARE(mgr.tripGroups().size(), 1); 0046 0047 TripGroupInfoProvider provider; 0048 provider.setReservationManager(&resMgr); 0049 provider.setWeatherForecastManager(&fcMgr); 0050 QVERIFY(!provider.weatherForecast({}).isValid()); 0051 const auto fc = provider.weatherForecast(mgr.tripGroup(mgr.tripGroups().at(0))); 0052 QVERIFY(fc.isValid()); 0053 QCOMPARE(fc.minimumTemperature(), 7.74224f); 0054 QCOMPARE(fc.maximumTemperature(), 47.4647f); 0055 0056 const auto countries = provider.locationInformation(mgr.tripGroup(mgr.tripGroups().at(0)), QStringLiteral("DE")); 0057 QCOMPARE(countries.size(), 1); 0058 const auto country = countries.at(0).value<LocationInformation>(); 0059 QCOMPARE(country.isoCode(), QStringLiteral("CH")); 0060 QCOMPARE(country.powerPlugCompatibility(), LocationInformation::PartiallyCompatible); 0061 0062 QCOMPARE(provider.currencies(mgr.tripGroup(mgr.tripGroups().at(0)), QStringLiteral("EUR")), QStringList({QStringLiteral("CHF")})); 0063 QCOMPARE(provider.currencies(mgr.tripGroup(mgr.tripGroups().at(0)), QStringLiteral("NZD")), QStringList({QStringLiteral("CHF"), QStringLiteral("EUR")})); 0064 } 0065 0066 }; 0067 0068 QTEST_GUILESS_MAIN(TripGroupInfoProviderTest) 0069 0070 #include "tripgroupinfoprovidertest.moc"