File indexing completed on 2024-12-01 04:35:23
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "customuserstatusestest.h" 0008 #include "customusers/customuserstatus.h" 0009 #include "customusers/customuserstatuses.h" 0010 #include "ruqola_autotest_helper.h" 0011 #include "utils.h" 0012 0013 QTEST_GUILESS_MAIN(CustomUserStatusesTest) 0014 0015 CustomUserStatusesTest::CustomUserStatusesTest(QObject *parent) 0016 : QObject(parent) 0017 { 0018 } 0019 0020 void CustomUserStatusesTest::shouldHaveDefaultValues() 0021 { 0022 CustomUserStatuses w; 0023 QVERIFY(w.customUserses().isEmpty()); 0024 QVERIFY(w.isEmpty()); 0025 QCOMPARE(w.offset(), 0); 0026 QCOMPARE(w.count(), 0); 0027 QCOMPARE(w.total(), 0); 0028 } 0029 0030 void CustomUserStatusesTest::shouldLoadUserCustomStatuses_data() 0031 { 0032 QTest::addColumn<QString>("name"); 0033 QTest::addColumn<int>("customStatusesCount"); 0034 QTest::addColumn<QVector<CustomUserStatus>>("customUserStatus"); 0035 0036 { 0037 QVector<CustomUserStatus> result; 0038 { 0039 CustomUserStatus f; 0040 f.setIdentifier(QStringLiteral("GZHpA5fENrWHRfaoN")); 0041 f.setName(QStringLiteral("CM")); 0042 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("busy"))); 0043 f.setUpdatedAt(1603106197911); 0044 result << f; 0045 } 0046 { 0047 CustomUserStatus f; 0048 f.setIdentifier(QStringLiteral("tygCbhbgCojk8G28G")); 0049 f.setName(QStringLiteral("Vacation")); 0050 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("away"))); 0051 f.setUpdatedAt(1588199612532); 0052 result << f; 0053 } 0054 QTest::addRow("customuser2") << QStringLiteral("customuser2") << 2 << result; 0055 } 0056 } 0057 0058 void CustomUserStatusesTest::shouldLoadUserCustomStatuses() 0059 { 0060 QFETCH(QString, name); 0061 QFETCH(int, customStatusesCount); 0062 QFETCH(QVector<CustomUserStatus>, customUserStatus); 0063 const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/customuserstatus/") + name + QLatin1String(".json"); 0064 const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile); 0065 0066 CustomUserStatuses r; 0067 r.parseCustomUserStatuses(obj); 0068 bool compareCustom = r.customUserses() == customUserStatus; 0069 if (!compareCustom) { 0070 qDebug() << "current : " << r.customUserses(); 0071 qDebug() << "expected: " << customUserStatus; 0072 } 0073 QVERIFY(compareCustom); 0074 QCOMPARE(r.count(), customStatusesCount); 0075 } 0076 0077 void CustomUserStatusesTest::shouldUpdateUserCustomStatuses_data() 0078 { 0079 QTest::addColumn<QString>("filename"); 0080 QTest::addColumn<QString>("updatefilename"); 0081 QTest::addColumn<QVector<CustomUserStatus>>("customUserStatusInit"); 0082 QTest::addColumn<QVector<CustomUserStatus>>("customUserStatusAfterUpdating"); 0083 0084 { 0085 QVector<CustomUserStatus> result; 0086 { 0087 CustomUserStatus f; 0088 f.setIdentifier(QStringLiteral("GZHpA5fENrWHRfaoN")); 0089 f.setName(QStringLiteral("CM")); 0090 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("busy"))); 0091 f.setUpdatedAt(1603106197911); 0092 result << f; 0093 } 0094 { 0095 CustomUserStatus f; 0096 f.setIdentifier(QStringLiteral("tygCbhbgCojk8G28G")); 0097 f.setName(QStringLiteral("Vacation")); 0098 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("away"))); 0099 f.setUpdatedAt(1588199612532); 0100 result << f; 0101 } 0102 0103 QVector<CustomUserStatus> updating; 0104 { 0105 CustomUserStatus f; 0106 f.setIdentifier(QStringLiteral("GZHpA5fENrWHRfaoN")); 0107 f.setName(QStringLiteral("CMs")); 0108 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("away"))); 0109 f.setUpdatedAt(1603106197911); 0110 updating << f; 0111 } 0112 { 0113 CustomUserStatus f; 0114 f.setIdentifier(QStringLiteral("tygCbhbgCojk8G28G")); 0115 f.setName(QStringLiteral("Vacation")); 0116 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("away"))); 0117 f.setUpdatedAt(1588199612532); 0118 updating << f; 0119 } 0120 0121 QTest::addRow("customuser2") << QStringLiteral("customuser2") << QStringLiteral("customuser2-updating") << result << updating; 0122 } 0123 0124 { 0125 QVector<CustomUserStatus> result; 0126 { 0127 CustomUserStatus f; 0128 f.setIdentifier(QStringLiteral("GZHpA5fENrWHRfaoN")); 0129 f.setName(QStringLiteral("CM")); 0130 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("busy"))); 0131 f.setUpdatedAt(1603106197911); 0132 result << f; 0133 } 0134 { 0135 CustomUserStatus f; 0136 f.setIdentifier(QStringLiteral("tygCbhbgCojk8G28G")); 0137 f.setName(QStringLiteral("Vacation")); 0138 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("away"))); 0139 f.setUpdatedAt(1588199612532); 0140 result << f; 0141 } 0142 0143 QVector<CustomUserStatus> adding; 0144 { 0145 CustomUserStatus f; 0146 f.setIdentifier(QStringLiteral("GZHpA5fENrWHRfaoN")); 0147 f.setName(QStringLiteral("CM")); 0148 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("busy"))); 0149 f.setUpdatedAt(1603106197911); 0150 adding << f; 0151 } 0152 { 0153 CustomUserStatus f; 0154 f.setIdentifier(QStringLiteral("tygCbhbgCojk8G28G")); 0155 f.setName(QStringLiteral("Vacation")); 0156 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("away"))); 0157 f.setUpdatedAt(1588199612532); 0158 adding << f; 0159 } 0160 { 0161 CustomUserStatus f; 0162 f.setIdentifier(QStringLiteral("ycbgxsKtP7sv8HNiS")); 0163 f.setName(QStringLiteral("bla")); 0164 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("away"))); 0165 f.setUpdatedAt(1603108134976); 0166 adding << f; 0167 } 0168 QTest::addRow("customuser2-adding") << QStringLiteral("customuser2") << QStringLiteral("customuser2-adding") << result << adding; 0169 } 0170 } 0171 0172 void CustomUserStatusesTest::shouldUpdateUserCustomStatuses() 0173 { 0174 QFETCH(QString, filename); 0175 QFETCH(QString, updatefilename); 0176 QFETCH(QVector<CustomUserStatus>, customUserStatusInit); 0177 QFETCH(QVector<CustomUserStatus>, customUserStatusAfterUpdating); 0178 const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/customuserstatus/") + filename + QLatin1String(".json"); 0179 const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile); 0180 0181 // Compare init 0182 CustomUserStatuses r; 0183 r.parseCustomUserStatuses(obj); 0184 bool compareCustom = r.customUserses() == customUserStatusInit; 0185 if (!compareCustom) { 0186 qDebug() << "current : " << r.customUserses(); 0187 qDebug() << "expected: " << customUserStatusInit; 0188 } 0189 QVERIFY(compareCustom); 0190 0191 // Compare after updating 0192 const QString updatingJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/customuserstatus/") + updatefilename + QLatin1String(".json"); 0193 const QJsonArray array = AutoTestHelper::loadJsonArrayObject(updatingJsonFile); 0194 0195 r.updateCustomUserStatues(array); 0196 compareCustom = r.customUserses() == customUserStatusAfterUpdating; 0197 if (!compareCustom) { 0198 qDebug() << "current : " << r.customUserses(); 0199 qDebug() << "expected: " << customUserStatusAfterUpdating; 0200 } 0201 QVERIFY(compareCustom); 0202 } 0203 0204 void CustomUserStatusesTest::shouldDeleteUserCustomStatuses_data() 0205 { 0206 QTest::addColumn<QString>("filename"); 0207 QTest::addColumn<QString>("updatefilename"); 0208 QTest::addColumn<QVector<CustomUserStatus>>("customUserStatusInit"); 0209 QTest::addColumn<QVector<CustomUserStatus>>("customUserStatusAfterDeleting"); 0210 0211 { 0212 QVector<CustomUserStatus> result; 0213 { 0214 CustomUserStatus f; 0215 f.setIdentifier(QStringLiteral("GZHpA5fENrWHRfaoN")); 0216 f.setName(QStringLiteral("CM")); 0217 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("busy"))); 0218 f.setUpdatedAt(1603106197911); 0219 result << f; 0220 } 0221 { 0222 CustomUserStatus f; 0223 f.setIdentifier(QStringLiteral("tygCbhbgCojk8G28G")); 0224 f.setName(QStringLiteral("Vacation")); 0225 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("away"))); 0226 f.setUpdatedAt(1588199612532); 0227 result << f; 0228 } 0229 0230 QVector<CustomUserStatus> updating; 0231 { 0232 CustomUserStatus f; 0233 f.setIdentifier(QStringLiteral("tygCbhbgCojk8G28G")); 0234 f.setName(QStringLiteral("Vacation")); 0235 f.setStatusType(Utils::presenceStatusFromString(QStringLiteral("away"))); 0236 f.setUpdatedAt(1588199612532); 0237 updating << f; 0238 } 0239 QTest::addRow("customuser2") << QStringLiteral("customuser2") << QStringLiteral("customuser2-deleting") << result << updating; 0240 } 0241 } 0242 0243 void CustomUserStatusesTest::shouldDeleteUserCustomStatuses() 0244 { 0245 QFETCH(QString, filename); 0246 QFETCH(QString, updatefilename); 0247 QFETCH(QVector<CustomUserStatus>, customUserStatusInit); 0248 QFETCH(QVector<CustomUserStatus>, customUserStatusAfterDeleting); 0249 const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/customuserstatus/") + filename + QLatin1String(".json"); 0250 const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile); 0251 0252 // Compare init 0253 CustomUserStatuses r; 0254 r.parseCustomUserStatuses(obj); 0255 bool compareCustom = r.customUserses() == customUserStatusInit; 0256 if (!compareCustom) { 0257 qDebug() << "current : " << r.customUserses(); 0258 qDebug() << "expected: " << customUserStatusInit; 0259 } 0260 QVERIFY(compareCustom); 0261 0262 // Compare after updating 0263 const QString updatingJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/customuserstatus/") + updatefilename + QLatin1String(".json"); 0264 const QJsonArray array = AutoTestHelper::loadJsonArrayObject(updatingJsonFile); 0265 0266 r.deleteCustomUserStatuses(array); 0267 compareCustom = r.customUserses() == customUserStatusAfterDeleting; 0268 if (!compareCustom) { 0269 qDebug() << "current : " << r.customUserses(); 0270 qDebug() << "expected: " << customUserStatusAfterDeleting; 0271 } 0272 QVERIFY(compareCustom); 0273 } 0274 0275 #include "moc_customuserstatusestest.cpp"