File indexing completed on 2024-12-01 04:35:29
0001 /* 0002 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "typingnotificationtest.h" 0008 #include "libruqola_private_export.h" 0009 #include "typingnotification.h" 0010 #include <QSignalSpy> 0011 0012 #include <QTest> 0013 QTEST_GUILESS_MAIN(TypingNotificationTest) 0014 0015 extern LIBRUQOLACORE_TESTS_EXPORT int timerTimeOutValueMs; 0016 0017 TypingNotificationTest::TypingNotificationTest(QObject *parent) 0018 : QObject(parent) 0019 { 0020 } 0021 0022 void TypingNotificationTest::shouldNotEmitSignalByDefault() 0023 { 0024 timerTimeOutValueMs = 100; // 100ms 0025 TypingNotification t; 0026 QSignalSpy signal(&t, &TypingNotification::informTypingStatus); 0027 // Wait 500ms 0028 QTest::qSleep(200); 0029 QCOMPARE(signal.count(), 0); 0030 } 0031 0032 void TypingNotificationTest::shouldEmitSignalWhenTyping() 0033 { 0034 timerTimeOutValueMs = 100; // 100ms 0035 TypingNotification t; 0036 QSignalSpy signal(&t, &TypingNotification::informTypingStatus); 0037 t.textNotificationChanged(QStringLiteral("foo"), false); 0038 // Wait 500ms 0039 QTest::qWait(50); 0040 QCOMPARE(signal.count(), 1); 0041 } 0042 0043 void TypingNotificationTest::shouldEmitSignalWhenTypingAndEmitTypingFalseAfterTimeout() 0044 { 0045 timerTimeOutValueMs = 100; // 100ms 0046 TypingNotification t; 0047 QSignalSpy signal(&t, &TypingNotification::informTypingStatus); 0048 t.textNotificationChanged(QStringLiteral("foo"), false); 0049 // Wait 50ms 0050 QTest::qWait(50); 0051 QCOMPARE(signal.count(), 1); 0052 0053 QTest::qWait(150); // 150 ms 0054 QCOMPARE(signal.count(), 2); 0055 } 0056 0057 void TypingNotificationTest::shouldDontEmitSignalWhenTypingSeveralTextBeforeTimeOut() 0058 { 0059 timerTimeOutValueMs = 100; // 100ms 0060 TypingNotification t; 0061 QSignalSpy signal(&t, &TypingNotification::informTypingStatus); 0062 t.textNotificationChanged(QStringLiteral("foo"), false); 0063 // Wait 50ms 0064 QTest::qWait(50); 0065 QCOMPARE(signal.count(), 1); 0066 t.textNotificationChanged(QStringLiteral("foo"), false); 0067 QTest::qWait(50); 0068 QCOMPARE(signal.count(), 1); 0069 t.textNotificationChanged(QStringLiteral("foo"), false); 0070 QTest::qWait(50); 0071 QCOMPARE(signal.count(), 1); 0072 0073 QTest::qWait(150); // 150 ms 0074 QCOMPARE(signal.count(), 2); 0075 } 0076 0077 void TypingNotificationTest::shouldEmitTwoSignalWhenChangeRoom() 0078 { 0079 timerTimeOutValueMs = 100; // 100ms 0080 TypingNotification t; 0081 QSignalSpy signal(&t, &TypingNotification::informTypingStatus); 0082 QString room1 = QStringLiteral("room1"); 0083 QString room2 = QStringLiteral("room2"); 0084 t.textNotificationChanged(room1, false); 0085 // Wait 50ms 0086 QTest::qWait(50); 0087 QCOMPARE(signal.count(), 1); 0088 0089 t.textNotificationChanged(room2, false); 0090 // Wait 50ms 0091 QTest::qWait(50); 0092 QCOMPARE(signal.count(), 3); // Two signal send. 0093 } 0094 0095 #include "moc_typingnotificationtest.cpp"