Fakultas Ilmu Komputer UI

Commit b85dbf60 authored by Usman Sidiq's avatar Usman Sidiq
Browse files

[RED] Adding test for login

parent 9aa4680b
Pipeline #42163 failed with stages
in 3 minutes and 19 seconds
import 'package:json_annotation/json_annotation.dart';
part 'pengguna.g.dart';
@JsonSerializable()
class UserListResponse {
List<User> listUser;
UserListResponse();
factory UserListResponse.fromJson(Map<String, dynamic> json) => _$UserListResponseFromJson(json);
Map<String, dynamic> toJson() => _$UserListResponseToJson(this);
}
@JsonSerializable(nullable: true)
class User {
String username;
String phonenumber;
String email;
String password;
User();
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
Map<String, dynamic> toJson() => _$UserToJson(this);
}
\ No newline at end of file
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'pengguna.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
UserListResponse _$UserListResponseFromJson(Map<String, dynamic> json) {
return UserListResponse()
..listUser = (json['listUser'] as List)
?.map(
(e) => e == null ? null : User.fromJson(e as Map<String, dynamic>))
?.toList();
}
Map<String, dynamic> _$UserListResponseToJson(UserListResponse instance) =>
<String, dynamic>{
'listUser': instance.listUser,
};
User _$UserFromJson(Map<String, dynamic> json) {
return User()
..username = json['username'] as String
..phonenumber = json['phonenumber'] as String
..email = json['email'] as String
..password = json['password'] as String;
}
Map<String, dynamic> _$UserToJson(User instance) => <String, dynamic>{
'username': instance.username,
'phonenumber': instance.phonenumber,
'email': instance.email,
'password': instance.password,
};
......@@ -23,21 +23,5 @@ void main() {
expect(find.text(textFieldLogin), findsOneWidget);
});
// Future<Null> _navigateToLoginPage(WidgetTester tester) async {
// final textToFind = 'Login';
// await tester.tap(find.text(textToFind));
// await tester.pump();
// }
//
// testWidgets(
// 'when tapping Login in drawer, should navigate to login',
// (WidgetTester tester) async {
// final textFieldLogin = 'Masuk ke Akun';
// await _navigateToLoginPage(tester);
//
// verify(mockObserver.didPush(any, any));
// expect(find.text(textFieldLogin), findsOneWidget);
// });
});
}
\ No newline at end of file
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:ppl_disabilitas/network/network_interface.dart';
import 'package:ppl_disabilitas/page/login/login.dart';
//import 'package:http/http.dart' as http;
class MockNetwork extends Mock implements NetworkInterface {}
void main() {
MockNetwork mockNetwork;
setUp(() {
mockNetwork = MockNetwork();
when(mockNetwork.get(isLogin: false, url: anyNamed('url')))
.thenAnswer((_) async {
await Future.delayed(Duration(milliseconds: 50));
return Future<dynamic>.value([
{
"username": "dummy@mail.com",
"name": "Dummy",
"email": "dummy@mail.com",
"phone_number": "085222333444",
}
]);
});
});
testWidgets('test login with credentials', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: Login()));
expect(find.byKey(const Key("Text Field Akun")), findsOneWidget);
await tester.enterText(
find.byKey(const Key("Text Field Akun")), "dummy@mail.com");
expect(find.byKey(const Key("Text Field Password")), findsOneWidget);
await tester.enterText(
find.byKey(const Key("Text Field Password")), "dummypassword");
await tester.pump();
expect(find.text("Kamu mau kemana?"), findsOneWidget);
});
testWidgets('Find Username Text Field', (WidgetTester tester) async {
final textFieldKey = Key("Text Field Akun");
await tester.pumpWidget(MaterialApp(home: Login()));
......@@ -17,12 +51,4 @@ void main() {
expect(find.byKey(textFieldKey), findsOneWidget);
});
// test('Valid API end point for validating user', () async {
// Map data = {
// 'email' : 'dummy@dummy.com',
// 'password' : 'dummypassword',
// };
// var result = await http.post('https://my.api.mockaroo.com/register.json?key=095ee610', body: data);
// expect(result.statusCode, 200);
// });
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment