|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:shared_preferences/shared_preferences.dart'; |
| 4 | +import 'package:example/main.dart'; |
| 5 | +import 'package:integration_test/integration_test.dart'; |
| 6 | + |
| 7 | +void main() { |
| 8 | + // Initialize the integration test bindings. |
| 9 | + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); |
| 10 | + |
| 11 | + testWidgets('Runs the app, taps on the settings icon, enters the URL, and runs the Data Channel example', (WidgetTester tester) async { |
| 12 | + // Mock initial values for shared preferences. |
| 13 | + SharedPreferences.setMockInitialValues({}); |
| 14 | + |
| 15 | + // Launch the app. |
| 16 | + await tester.pumpWidget(const MaterialApp( |
| 17 | + home: Scaffold( |
| 18 | + body: MyApp(), |
| 19 | + ))); |
| 20 | + |
| 21 | + // Ensure the app has built. |
| 22 | + await tester.pumpAndSettle(); |
| 23 | + |
| 24 | + // Verify the settings icon is present. |
| 25 | + expect(find.byIcon(Icons.settings), findsOneWidget); |
| 26 | + |
| 27 | + // Tap the settings icon. |
| 28 | + await tester.tap(find.byIcon(Icons.settings)); |
| 29 | + await tester.pumpAndSettle(); |
| 30 | + |
| 31 | + // Check if the AlertDialog appears after tapping settings. |
| 32 | + expect(find.byType(AlertDialog), findsOneWidget); |
| 33 | + |
| 34 | + // Enter the server URL in the TextField inside the dialog. |
| 35 | + await tester.enterText(find.byType(TextField), 'wss://test.antmedia.io:5443/FlutterCICDtest/websocket'); |
| 36 | + await tester.pumpAndSettle(); |
| 37 | + |
| 38 | + // Ensure the "Set Server Ip" button is present and enabled. |
| 39 | + final setServerIpButton = find.widgetWithText(MaterialButton, 'Set Server Ip'); |
| 40 | + expect(setServerIpButton, findsOneWidget); |
| 41 | + |
| 42 | + // Tap the "Set Server Ip" button. |
| 43 | + await tester.tap(setServerIpButton); |
| 44 | + await tester.pumpAndSettle(); |
| 45 | + |
| 46 | + // Verify that a SnackBar appears after setting the server IP. |
| 47 | + expect(find.byType(SnackBar), findsOneWidget); |
| 48 | + |
| 49 | + // Tap the 'Conference' button. |
| 50 | + await tester.tap(find.text('Data Channel')); |
| 51 | + await tester.pumpAndSettle(); |
| 52 | + |
| 53 | + // Enter Room ID and tap OK. |
| 54 | + await tester.enterText(find.byType(TextField), '24x7test'); |
| 55 | + await tester.tap(find.text('OK')); |
| 56 | + await tester.pumpAndSettle(const Duration(seconds: 5)); |
| 57 | + }); |
| 58 | +} |
0 commit comments