|
| 1 | +import 'package:fluffychat/generated/l10n/app_localizations.dart'; |
| 2 | +import 'package:fluffychat/pages/chat/typing_timer_wrapper.dart'; |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:flutter_test/flutter_test.dart'; |
| 5 | +import 'package:matrix/matrix.dart'; |
| 6 | +import 'package:mockito/annotations.dart'; |
| 7 | +import 'package:mockito/mockito.dart'; |
| 8 | + |
| 9 | +import 'typing_timer_wrapper_test.mocks.dart'; |
| 10 | + |
| 11 | +@GenerateNiceMocks([ |
| 12 | + MockSpec<Room>(), |
| 13 | + MockSpec<Client>(), |
| 14 | + MockSpec<L10n>(), |
| 15 | +]) |
| 16 | +void main() { |
| 17 | + testWidgets('typing timer wrapper should stop showing typing after 30s', |
| 18 | + (tester) async { |
| 19 | + final room = MockRoom(); |
| 20 | + final client = MockClient(); |
| 21 | + final l10n = MockL10n(); |
| 22 | + const typingText = 'typing'; |
| 23 | + const notTypingText = 'not typing'; |
| 24 | + const typingWidget = Text(typingText); |
| 25 | + const notTypingWidget = Text(notTypingText); |
| 26 | + when(client.userID).thenReturn('owner'); |
| 27 | + when(room.client).thenReturn(client); |
| 28 | + when(room.typingUsers).thenReturn([]); |
| 29 | + await tester.pumpWidget( |
| 30 | + MaterialApp( |
| 31 | + home: Scaffold( |
| 32 | + body: TypingTimerWrapper( |
| 33 | + room: room, |
| 34 | + l10n: l10n, |
| 35 | + typingWidget: typingWidget, |
| 36 | + notTypingWidget: notTypingWidget, |
| 37 | + ), |
| 38 | + ), |
| 39 | + ), |
| 40 | + ); |
| 41 | + expect(find.text(notTypingText), findsOneWidget); |
| 42 | + expect(find.text(typingText), findsNothing); |
| 43 | + |
| 44 | + when(room.typingUsers).thenReturn([User('id', room: room)]); |
| 45 | + await tester.pumpWidget( |
| 46 | + MaterialApp( |
| 47 | + home: Scaffold( |
| 48 | + body: TypingTimerWrapper( |
| 49 | + room: room, |
| 50 | + l10n: l10n, |
| 51 | + typingWidget: typingWidget, |
| 52 | + notTypingWidget: notTypingWidget, |
| 53 | + ), |
| 54 | + ), |
| 55 | + ), |
| 56 | + ); |
| 57 | + expect(find.text(typingText), findsOneWidget); |
| 58 | + expect(find.text(notTypingText), findsNothing); |
| 59 | + |
| 60 | + await tester.pump(const Duration(seconds: 30)); |
| 61 | + expect(find.text(notTypingText), findsOneWidget); |
| 62 | + expect(find.text(typingText), findsNothing); |
| 63 | + }); |
| 64 | +} |
0 commit comments