-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
How to use: $ flutter drive --driver=test/test_driver/perf_driver.dart --target=test/scenarios/scenarios.dart -d chrome
- Loading branch information
1 parent
0022315
commit 4c6d688
Showing
7 changed files
with
260 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
|
||
import 'package:thingsboard_app/models/user_provider.dart'; | ||
import 'package:thingsboard_app/pages/pages.dart'; | ||
|
||
Widget createLoginScreen() => ChangeNotifierProvider<UserBaseProvider>( | ||
create: (context) => UserBaseProvider(), | ||
child: const MaterialApp( | ||
home: Login(), | ||
localizationsDelegates: AppLocalizations.localizationsDelegates, | ||
supportedLocales: [ | ||
Locale('en', ''), | ||
], | ||
), | ||
); | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
group('Login Page Widget Tests : ', () { | ||
testWidgets('Testing if SingleChildScrollView shows up', (tester) async { | ||
// Build the widget | ||
await tester.pumpWidget(createLoginScreen()); | ||
expect(find.byType(SingleChildScrollView), findsOneWidget); | ||
}); | ||
|
||
testWidgets('Testing Scrolling', (tester) async { | ||
await tester.pumpWidget(createLoginScreen()); | ||
expect(find.widgetWithText(TextFormField, 'Username(email)'), | ||
findsOneWidget); | ||
// Scroll until the item to be found appears. | ||
await tester.fling( | ||
find.byType(SingleChildScrollView), const Offset(0, -200), 3000); | ||
await tester.pumpAndSettle(); | ||
expect(find.byIcon(Icons.login), findsWidgets); | ||
}); | ||
|
||
testWidgets('validating error message when username input error', | ||
(tester) async { | ||
await tester.pumpWidget(createLoginScreen()); | ||
/* | ||
Steps: | ||
1. Enter 'test' into the username TextFormField | ||
2. Tap the login button | ||
3. Expect to show the snackbar on screen. | ||
*/ | ||
await tester.enterText( | ||
find.widgetWithText(TextFormField, 'Username(email)'), 'test'); | ||
await tester.tap(find.byIcon(Icons.login)); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('Please fix the errors in red before submitting.'), | ||
findsOneWidget); | ||
expect(find.text('Username(email) need @ character'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('validating error message when password input error', | ||
(tester) async { | ||
var inputText = '12'; | ||
await tester.pumpWidget(createLoginScreen()); | ||
/* | ||
Steps: | ||
1. Enter 'test' into the password TextFormField | ||
2. Tap the visibility_off icon, verify inputText and visibility icon | ||
2. Tap the login button | ||
3. Expect to show the snackbar on screen. | ||
*/ | ||
await tester.enterText( | ||
find.widgetWithText(TextFormField, 'Password'), inputText); | ||
await tester.tap(find.byIcon(Icons.visibility_off)); | ||
expect(find.text(inputText), findsOneWidget); | ||
await tester.pumpAndSettle(); | ||
expect(find.byIcon(Icons.visibility), findsOneWidget); | ||
await tester.tap(find.byIcon(Icons.login)); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('Please fix the errors in red before submitting.'), | ||
findsOneWidget); | ||
expect(find.text('Minimum character length is 6'), findsOneWidget); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import 'login.dart' as login; | ||
import 'userapi.dart' as userapi; | ||
|
||
void main() { | ||
//login.main(); | ||
userapi.main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:http/http.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
//import 'package:dio/dio.dart'; | ||
//import 'package:http_mock_adapter/http_mock_adapter.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
/*late Dio dio; | ||
late DioAdapter dioAdapter; | ||
Response<dynamic> response; | ||
group('RestApi Tests', () { | ||
setUp(() { | ||
dio = Dio(BaseOptions(baseUrl: 'http://localhost:3000')); | ||
dioAdapter = DioAdapter( | ||
dio: dio, | ||
matcher: const FullHttpRequestMatcher(), | ||
); | ||
}); | ||
tearDown(() { | ||
dioAdapter.close(); | ||
dio.close(force: true); | ||
}); | ||
test('Testing getUser', () async { | ||
const route = '/api/users?query=user1@test.com'; | ||
const userInformation = <String, dynamic>{ | ||
"userName": "user1", | ||
"email": "user1@test.com", | ||
"role": "user" | ||
}; | ||
dioAdapter.onGet(route, (server) { | ||
server.reply(200, userInformation); | ||
}); | ||
response = await dio.get(route); | ||
print(response.data); | ||
expect(response.statusCode, 200); | ||
expect(response.data, userInformation); | ||
}); | ||
});*/ | ||
|
||
late String apiUrl; | ||
late String userName; | ||
|
||
group('RestAPI Test: ', () { | ||
setUpAll(() { | ||
HttpOverrides.global = null; | ||
apiUrl = 'http://localhost:3000'; | ||
userName = 'test@test.com'; | ||
}); | ||
|
||
test('Testing signup', () async { | ||
var userInformation = <String, dynamic>{ | ||
"userName": "test", | ||
"email": userName, | ||
"password": "string", | ||
"role": "user" | ||
}; | ||
var client = Client(); | ||
await client.delete(Uri.parse('$apiUrl/api/users/$userName')); | ||
var response = await client.post( | ||
Uri.parse('$apiUrl/api/users/signup'), | ||
body: userInformation, | ||
); | ||
client.close(); | ||
final extractedData = json.decode(response.body); | ||
expect(response.statusCode, 200); | ||
expect(extractedData['email'], userName); | ||
await Future.delayed(const Duration(seconds: 2)); | ||
}); | ||
|
||
test('Testing getUser', () async { | ||
var client = Client(); | ||
var response = | ||
await client.get(Uri.parse('$apiUrl/api/users?query=$userName')); | ||
client.close(); | ||
final extractedData = json.decode(response.body); | ||
expect(response.statusCode, 200); | ||
expect(extractedData['email'], userName); | ||
await Future.delayed(const Duration(seconds: 5)); | ||
}); | ||
|
||
test('Testing delete user', () async { | ||
var client = Client(); | ||
var response = | ||
await client.delete(Uri.parse('$apiUrl/api/users/$userName')); | ||
client.close(); | ||
expect(response.statusCode, 200); | ||
expect(response.body, 'OK'); | ||
await Future.delayed(const Duration(seconds: 1)); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import 'package:integration_test/integration_test_driver.dart'; | ||
|
||
Future<void> main() async => await integrationDriver(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters