File indexing completed on 2024-12-01 04:35:26
0001 /* 0002 SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "receivetypingnotificationmanagertest.h" 0008 #include "receivetypingnotificationmanager.h" 0009 #include <QSignalSpy> 0010 #include <QTest> 0011 0012 QTEST_GUILESS_MAIN(ReceiveTypingNotificationManagerTest) 0013 0014 ReceiveTypingNotificationManagerTest::ReceiveTypingNotificationManagerTest(QObject *parent) 0015 : QObject(parent) 0016 { 0017 } 0018 0019 void ReceiveTypingNotificationManagerTest::shouldHaveDefaultValues() 0020 { 0021 ReceiveTypingNotificationManager manager; 0022 QVERIFY(manager.typingNotification(QStringLiteral("Foo")).isEmpty()); 0023 } 0024 0025 void ReceiveTypingNotificationManagerTest::shouldAddNotifications() 0026 { 0027 ReceiveTypingNotificationManager manager; 0028 QSignalSpy spy(&manager, &ReceiveTypingNotificationManager::notificationChanged); 0029 0030 manager.insertTypingNotification(QStringLiteral("room1"), QStringLiteral("user1"), false); 0031 QVERIFY(manager.typingNotification(QStringLiteral("room1")).isEmpty()); 0032 QCOMPARE(spy.count(), 0); 0033 spy.clear(); 0034 0035 manager.insertTypingNotification(QStringLiteral("room1"), QStringLiteral("user1"), true); 0036 QCOMPARE(manager.typingNotification(QStringLiteral("room1")), QStringLiteral("<strong>user1</strong> is typing...")); 0037 QCOMPARE(spy.count(), 1); 0038 manager.insertTypingNotification(QStringLiteral("room1"), QStringLiteral("user1"), true); 0039 QCOMPARE(manager.typingNotification(QStringLiteral("room1")), QStringLiteral("<strong>user1</strong> is typing...")); 0040 QCOMPARE(spy.count(), 1); 0041 0042 spy.clear(); 0043 // Add different user. 0044 manager.insertTypingNotification(QStringLiteral("room2"), QStringLiteral("user2"), true); 0045 QCOMPARE(manager.typingNotification(QStringLiteral("room2")), QStringLiteral("<strong>user2</strong> is typing...")); 0046 QCOMPARE(spy.count(), 1); 0047 0048 manager.insertTypingNotification(QStringLiteral("room2"), QStringLiteral("user3"), true); 0049 QCOMPARE(manager.typingNotification(QStringLiteral("room2")), QStringLiteral("<strong>user2 and user3</strong> are typing...")); 0050 QCOMPARE(spy.count(), 2); 0051 0052 manager.insertTypingNotification(QStringLiteral("room2"), QStringLiteral("user1"), true); 0053 QCOMPARE(manager.typingNotification(QStringLiteral("room2")), QStringLiteral("<strong>user2, user3 and user1</strong> are typing...")); 0054 QCOMPARE(spy.count(), 3); 0055 0056 // Remove typing 0057 manager.insertTypingNotification(QStringLiteral("room2"), QStringLiteral("user3"), false); 0058 QCOMPARE(manager.typingNotification(QStringLiteral("room2")), QStringLiteral("<strong>user2 and user1</strong> are typing...")); 0059 QCOMPARE(spy.count(), 4); 0060 0061 manager.insertTypingNotification(QStringLiteral("room2"), QStringLiteral("user1"), false); 0062 QCOMPARE(manager.typingNotification(QStringLiteral("room2")), QStringLiteral("<strong>user2</strong> is typing...")); 0063 QCOMPARE(spy.count(), 5); 0064 0065 manager.insertTypingNotification(QStringLiteral("room2"), QStringLiteral("user3"), false); 0066 QCOMPARE(manager.typingNotification(QStringLiteral("room2")), QStringLiteral("<strong>user2</strong> is typing...")); 0067 QCOMPARE(spy.count(), 5); 0068 0069 manager.insertTypingNotification(QStringLiteral("room2"), QStringLiteral("user2"), false); 0070 QVERIFY(manager.typingNotification(QStringLiteral("room2")).isEmpty()); 0071 QCOMPARE(spy.count(), 6); 0072 0073 // No user/roomId 0074 manager.insertTypingNotification(QStringLiteral("room2"), QStringLiteral("user2"), false); 0075 QVERIFY(manager.typingNotification(QStringLiteral("room2")).isEmpty()); 0076 QCOMPARE(spy.count(), 6); 0077 0078 spy.clear(); 0079 QVERIFY(manager.typingNotification(QStringLiteral("room5")).isEmpty()); 0080 QCOMPARE(spy.count(), 0); 0081 } 0082 0083 #include "moc_receivetypingnotificationmanagertest.cpp"