|
1 | 1 | import 'package:flutter/material.dart';
|
2 | 2 | import 'package:flutter_test/flutter_test.dart';
|
3 | 3 | import 'package:mocktail/mocktail.dart';
|
| 4 | +import 'package:record/record.dart'; |
| 5 | +import 'package:rxdart/rxdart.dart'; |
| 6 | +import 'package:stream_chat_flutter/src/attachment/audio/audio_player_compose_message.dart'; |
| 7 | +import 'package:stream_chat_flutter/src/message_input/record/record_field.dart'; |
4 | 8 | import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
5 | 9 |
|
6 | 10 | import '../mocks.dart';
|
@@ -215,7 +219,7 @@ void main() {
|
215 | 219 | );
|
216 | 220 |
|
217 | 221 | testWidgets(
|
218 |
| - 'Test that start button is possible to write a message in default mode', |
| 222 | + 'Test that is possible to write a message in default mode', |
219 | 223 | (WidgetTester tester) async {
|
220 | 224 | final client = MockClient();
|
221 | 225 | final clientState = MockClientState();
|
@@ -285,95 +289,179 @@ void main() {
|
285 | 289 | },
|
286 | 290 | );
|
287 | 291 |
|
288 |
| - // testWidgets( |
289 |
| - // 'Test that start the audio input is correctly appears', |
290 |
| - // (WidgetTester tester) async { |
291 |
| - // |
292 |
| - // final client = MockClient(); |
293 |
| - // final clientState = MockClientState(); |
294 |
| - // final channel = MockChannel(); |
295 |
| - // final channelState = MockChannelState(); |
296 |
| - // final lastMessageAt = DateTime.parse('2020-06-22 12:00:00'); |
297 |
| - // final mockRecordController = MockStreamRecordController(); |
298 |
| - // |
299 |
| - // when(() => client.state).thenReturn(clientState); |
300 |
| - // when(() => clientState.currentUser).thenReturn(OwnUser(id: 'user-id')); |
301 |
| - // when(() => channel.lastMessageAt).thenReturn(lastMessageAt); |
302 |
| - // when(() => channel.state).thenReturn(channelState); |
303 |
| - // when(() => channel.client).thenReturn(client); |
304 |
| - // when(() => channel.isMuted).thenReturn(false); |
305 |
| - // when(() => channel.isMutedStream).thenAnswer((i) => Stream.value(false)); |
306 |
| - // when(() => channel.extraDataStream).thenAnswer( |
307 |
| - // (i) => Stream.value({ |
308 |
| - // 'name': 'test', |
309 |
| - // }), |
310 |
| - // ); |
311 |
| - // when(() => channel.extraData).thenReturn({ |
312 |
| - // 'name': 'test', |
313 |
| - // }); |
314 |
| - // when(() => channelState.membersStream).thenAnswer( |
315 |
| - // (i) => Stream.value([ |
316 |
| - // Member( |
317 |
| - // userId: 'user-id', |
318 |
| - // user: User(id: 'user-id'), |
319 |
| - // ) |
320 |
| - // ]), |
321 |
| - // ); |
322 |
| - // when(() => channelState.members).thenReturn([ |
323 |
| - // Member( |
324 |
| - // userId: 'user-id', |
325 |
| - // user: User(id: 'user-id'), |
326 |
| - // ), |
327 |
| - // ]); |
328 |
| - // when(() => channelState.messages).thenReturn([ |
329 |
| - // Message( |
330 |
| - // text: 'hello', |
331 |
| - // user: User(id: 'other-user'), |
332 |
| - // ) |
333 |
| - // ]); |
334 |
| - // when(() => channelState.messagesStream).thenAnswer( |
335 |
| - // (i) => Stream.value([ |
336 |
| - // Message( |
337 |
| - // text: 'hello', |
338 |
| - // user: User(id: 'other-user'), |
339 |
| - // ) |
340 |
| - // ]), |
341 |
| - // ); |
342 |
| - // |
343 |
| - // final recordStateController = BehaviorSubject<RecordState>(); |
344 |
| - // when(() => mockRecordController.recordState) |
345 |
| - // .thenAnswer((_) => recordStateController.stream); |
346 |
| - // |
347 |
| - // await tester.pumpWidget(MaterialApp( |
348 |
| - // home: StreamChat( |
349 |
| - // client: client, |
350 |
| - // child: StreamChannel( |
351 |
| - // channel: channel, |
352 |
| - // child: Scaffold( |
353 |
| - // body: StreamMessageInput( |
354 |
| - // enableAudioRecord: false, |
355 |
| - // // recordController: mockRecordController, |
356 |
| - // ), |
357 |
| - // ), |
358 |
| - // ), |
359 |
| - // ), |
360 |
| - // )); |
361 |
| - // |
362 |
| - // await tester.runAsync(() async { |
363 |
| - // recordStateController.add(RecordState.record); |
364 |
| - // |
365 |
| - // await Future<void>.delayed(const Duration(milliseconds: 100)); |
366 |
| - // |
367 |
| - // // expect(find.byKey(const Key('startRecord')), findsNothing); |
368 |
| - // // expect( |
369 |
| - // // find.byWidgetPredicate((widget) => widget is RecordField), |
370 |
| - // // findsOneWidget, |
371 |
| - // // ); |
372 |
| - // recordStateController.close(); |
373 |
| - // } |
374 |
| - // ); |
375 |
| - // }, |
376 |
| - // ); |
| 292 | + testWidgets( |
| 293 | + 'Test that is possible to add a audio message in default mode', |
| 294 | + (WidgetTester tester) async { |
| 295 | + final client = MockClient(); |
| 296 | + final clientState = MockClientState(); |
| 297 | + final channel = MockChannel(); |
| 298 | + final channelState = MockChannelState(); |
| 299 | + final lastMessageAt = DateTime.parse('2020-06-22 12:00:00'); |
| 300 | + |
| 301 | + when(() => client.state).thenReturn(clientState); |
| 302 | + when(() => clientState.currentUser).thenReturn(OwnUser(id: 'user-id')); |
| 303 | + when(() => channel.lastMessageAt).thenReturn(lastMessageAt); |
| 304 | + when(() => channel.state).thenReturn(channelState); |
| 305 | + when(() => channel.client).thenReturn(client); |
| 306 | + when(() => channel.isMuted).thenReturn(false); |
| 307 | + when(() => channel.isMutedStream).thenAnswer((i) => Stream.value(false)); |
| 308 | + when(() => channel.extraDataStream).thenAnswer( |
| 309 | + (i) => Stream.value({ |
| 310 | + 'name': 'test', |
| 311 | + }), |
| 312 | + ); |
| 313 | + when(() => channel.extraData).thenReturn({ |
| 314 | + 'name': 'test', |
| 315 | + }); |
| 316 | + when(() => channelState.membersStream).thenAnswer( |
| 317 | + (i) => Stream.value([ |
| 318 | + Member( |
| 319 | + userId: 'user-id', |
| 320 | + user: User(id: 'user-id'), |
| 321 | + ) |
| 322 | + ]), |
| 323 | + ); |
| 324 | + when(() => channelState.members).thenReturn([ |
| 325 | + Member( |
| 326 | + userId: 'user-id', |
| 327 | + user: User(id: 'user-id'), |
| 328 | + ), |
| 329 | + ]); |
| 330 | + when(() => channelState.messages).thenReturn([ |
| 331 | + Message( |
| 332 | + text: 'hello', |
| 333 | + user: User(id: 'other-user'), |
| 334 | + ) |
| 335 | + ]); |
| 336 | + when(() => channelState.messagesStream).thenAnswer( |
| 337 | + (i) => Stream.value([ |
| 338 | + Message( |
| 339 | + text: 'hello', |
| 340 | + user: User(id: 'other-user'), |
| 341 | + ) |
| 342 | + ]), |
| 343 | + ); |
| 344 | + |
| 345 | + final messageInputController = StreamMessageInputController(); |
| 346 | + |
| 347 | + await tester.pumpWidget(MaterialApp( |
| 348 | + home: StreamChat( |
| 349 | + client: client, |
| 350 | + child: StreamChannel( |
| 351 | + channel: channel, |
| 352 | + child: Scaffold( |
| 353 | + body: StreamMessageInput( |
| 354 | + enableAudioRecord: false, |
| 355 | + messageInputController: messageInputController, |
| 356 | + ), |
| 357 | + ), |
| 358 | + ), |
| 359 | + ), |
| 360 | + )); |
| 361 | + |
| 362 | + messageInputController.attachments += [ |
| 363 | + Attachment(type: 'audio_recording'), |
| 364 | + Attachment(type: 'audio_recording'), |
| 365 | + ]; |
| 366 | + |
| 367 | + await tester.pump(); |
| 368 | + |
| 369 | + expect( |
| 370 | + find.byWidgetPredicate((widget) => widget is AudioPlayerComposeMessage), |
| 371 | + findsWidgets, |
| 372 | + ); |
| 373 | + }, |
| 374 | + ); |
| 375 | + |
| 376 | + testWidgets( |
| 377 | + 'Test that start the audio input correctly appears', |
| 378 | + (WidgetTester tester) async { |
| 379 | + final client = MockClient(); |
| 380 | + final clientState = MockClientState(); |
| 381 | + final channel = MockChannel(); |
| 382 | + final channelState = MockChannelState(); |
| 383 | + final lastMessageAt = DateTime.parse('2020-06-22 12:00:00'); |
| 384 | + final mockRecordController = MockStreamRecordController(); |
| 385 | + |
| 386 | + when(() => client.state).thenReturn(clientState); |
| 387 | + when(() => clientState.currentUser).thenReturn(OwnUser(id: 'user-id')); |
| 388 | + when(() => channel.lastMessageAt).thenReturn(lastMessageAt); |
| 389 | + when(() => channel.state).thenReturn(channelState); |
| 390 | + when(() => channel.client).thenReturn(client); |
| 391 | + when(() => channel.isMuted).thenReturn(false); |
| 392 | + when(() => channel.isMutedStream).thenAnswer((i) => Stream.value(false)); |
| 393 | + when(() => channel.extraDataStream).thenAnswer( |
| 394 | + (i) => Stream.value({ |
| 395 | + 'name': 'test', |
| 396 | + }), |
| 397 | + ); |
| 398 | + when(() => channel.extraData).thenReturn({ |
| 399 | + 'name': 'test', |
| 400 | + }); |
| 401 | + when(() => channelState.membersStream).thenAnswer( |
| 402 | + (i) => Stream.value([ |
| 403 | + Member( |
| 404 | + userId: 'user-id', |
| 405 | + user: User(id: 'user-id'), |
| 406 | + ) |
| 407 | + ]), |
| 408 | + ); |
| 409 | + when(() => channelState.members).thenReturn([ |
| 410 | + Member( |
| 411 | + userId: 'user-id', |
| 412 | + user: User(id: 'user-id'), |
| 413 | + ), |
| 414 | + ]); |
| 415 | + when(() => channelState.messages).thenReturn([ |
| 416 | + Message( |
| 417 | + text: 'hello', |
| 418 | + user: User(id: 'other-user'), |
| 419 | + ) |
| 420 | + ]); |
| 421 | + when(() => channelState.messagesStream).thenAnswer( |
| 422 | + (i) => Stream.value([ |
| 423 | + Message( |
| 424 | + text: 'hello', |
| 425 | + user: User(id: 'other-user'), |
| 426 | + ) |
| 427 | + ]), |
| 428 | + ); |
| 429 | + |
| 430 | + final recordStateController = BehaviorSubject<RecordState>(); |
| 431 | + final amplitudeController = BehaviorSubject<Amplitude>(); |
| 432 | + when(() => mockRecordController.recordState) |
| 433 | + .thenAnswer((_) => recordStateController.stream); |
| 434 | + |
| 435 | + when(() => mockRecordController.amplitudeStream) |
| 436 | + .thenAnswer((_) => amplitudeController.stream); |
| 437 | + |
| 438 | + await tester.pumpWidget(MaterialApp( |
| 439 | + home: StreamChat( |
| 440 | + client: client, |
| 441 | + child: StreamChannel( |
| 442 | + channel: channel, |
| 443 | + child: Scaffold( |
| 444 | + body: StreamMessageInput( |
| 445 | + recordController: mockRecordController, |
| 446 | + ), |
| 447 | + ), |
| 448 | + ), |
| 449 | + ), |
| 450 | + )); |
| 451 | + |
| 452 | + recordStateController.add(RecordState.record); |
| 453 | + |
| 454 | + await tester.pump(); |
| 455 | + |
| 456 | + expect(find.byKey(const Key('startRecord')), findsNothing); |
| 457 | + expect( |
| 458 | + find.byWidgetPredicate((widget) => widget is RecordField), |
| 459 | + findsOneWidget, |
| 460 | + ); |
| 461 | + recordStateController.close(); |
| 462 | + amplitudeController.close(); |
| 463 | + }, |
| 464 | + ); |
377 | 465 |
|
378 | 466 | testWidgets(
|
379 | 467 | 'checks message input slow mode',
|
|
0 commit comments