Fakultas Ilmu Komputer UI

Commit 667b0d72 authored by jovi_013's avatar jovi_013
Browse files

[RED] Move test & add mock

parent 87af57dc
Pipeline #77150 failed with stages
in 4 minutes and 32 seconds
import 'package:bisaGo/config/strings.dart';
// import 'package:bisaGo/config/strings.dart';
import 'package:bisaGo/model/kegiatan.dart';
import 'package:bisaGo/model/lokasi.dart';
import 'package:bisaGo/page/filter_fasilitas/postingan/detail_post_kegiatan.dart';
// import 'package:bisaGo/page/filter_fasilitas/postingan/detail_post_kegiatan.dart';
import 'package:bisaGo/repository/kegiatan_repository.dart';
import 'package:bisaGo/repository/lokasi_repository.dart';
import 'package:flutter/material.dart';
// import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:get_it/get_it.dart';
// import 'package:get_it/get_it.dart';
class MockDetailPostKegiatan extends Fake implements KegiatanRepository {
final mockKegiatan = {
......@@ -26,13 +26,13 @@ class MockDetailPostKegiatan extends Fake implements KegiatanRepository {
return Future.value(KegiatanList([KegiatanModel.fromJson(mockKegiatan)]));
}
@override
Future<dynamic> updateKegiatan(Map<String, dynamic> newKegiatanData,
String namaLokasi, int id, String token) async {
final responseBody = {'response': 'Fasilitas updated'};
final statusCode = 202;
return Future.value(Response(responseBody.toString(), statusCode));
}
// @override
// Future<dynamic> updateKegiatan(Map<String, dynamic> newKegiatanData,
// String namaLokasi, int id, String token) async {
// final responseBody = {'response': 'Fasilitas updated'};
// final statusCode = 202;
// return Future.value(Response(responseBody.toString(), statusCode));
// }
}
class MockLokasi extends Fake implements LokasiRepository {
......@@ -50,74 +50,74 @@ class MockLokasi extends Fake implements LokasiRepository {
}
}
class MockKomentarPostingKegiatan extends Fake implements KomentarPostingKegiatanRepository {}
// class MockKomentarPostingKegiatan extends Fake implements KomentarPostingKegiatanRepository {}
void main() {
final mockLokasi = {
'name': 'Margo City',
'alamat': 'Jl. Margonda Raya No.358, Kemiri Muka, Kecamatan Beji, Kota Depok, Jawa Barat 16423',
'image': 'Margo.jpg',
'no_telp': '02178870888',
'counter': 69,
};
// final mockLokasi = {
// 'name': 'Margo City',
// 'alamat': 'Jl. Margonda Raya No.358, Kemiri Muka, Kecamatan Beji, Kota Depok, Jawa Barat 16423',
// 'image': 'Margo.jpg',
// 'no_telp': '02178870888',
// 'counter': 69,
// };
final mockKegiatan = {
'id': 2,
'nama_lokasi': 'Margo City',
'creator': 'Putri Salsabila',
'nama_kegiatan': 'Kopdar Rutin',
'penyelenggara': 'DTB Indonesia',
'narahubung': 'Putsal 08123123123',
'deskripsi': 'lorem ipsum dolor sit amet',
'time_start': '12-12-2021 06:30:00',
'time_end': '12-12-2021 09:30:00'
};
// final mockKegiatan = {
// 'id': 2,
// 'nama_lokasi': 'Margo City',
// 'creator': 'Putri Salsabila',
// 'nama_kegiatan': 'Kopdar Rutin',
// 'penyelenggara': 'DTB Indonesia',
// 'narahubung': 'Putsal 08123123123',
// 'deskripsi': 'lorem ipsum dolor sit amet',
// 'time_start': '12-12-2021 06:30:00',
// 'time_end': '12-12-2021 09:30:00'
// };
setUpAll(() {
final _getIt = GetIt.instance;
_getIt.registerLazySingleton<BaseKegiatanRepository>(
() => MockDetailPostKegiatan());
_getIt.registerLazySingleton<BaseLokasiRepository>(
() => MockLokasi());
_getIt.registerLazySingleton<BaseKomentarPostingKegiatanRepository>(
() => MockKomentarPostingKegiatan());
});
// setUpAll(() {
// final _getIt = GetIt.instance;
// _getIt.registerLazySingleton<BaseKegiatanRepository>(
// () => MockDetailPostKegiatan());
// _getIt.registerLazySingleton<BaseLokasiRepository>(
// () => MockLokasi());
// _getIt.registerLazySingleton<BaseKomentarPostingKegiatanRepository>(
// () => MockKomentarPostingKegiatan());
// });
testWidgets(
'Detail Post Kegiatan Page - Positive Test', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: DetailPostKegiatanPage(
lokasi: Lokasi.fromJson(mockLokasi),
kegiatan: KegiatanModel.fromJson(mockKegiatan)
)
));
await tester.pump();
expect(find.byType(DetailPostKegiatanPage), findsOneWidget);
expect(find.text('Kopdar Rutin'), findsOneWidget);
expect(find.text('oleh DTB Indonesia'), findsOneWidget);
expect(find.text('lorem ipsum dolor sit amet'), findsOneWidget);
expect(find.text('Putsal 08123123123'), findsOneWidget);
expect(find.text('Putri Salsabila'), findsOneWidget);
expect(find.text('Komentar'), findsOneWidget);
expect(find.text('Tambah Komentar'), findsOneWidget);
});
// testWidgets(
// 'Detail Post Kegiatan Page - Positive Test', (WidgetTester tester) async {
// await tester.pumpWidget(MaterialApp(
// home: DetailPostKegiatanPage(
// lokasi: Lokasi.fromJson(mockLokasi),
// kegiatan: KegiatanModel.fromJson(mockKegiatan)
// )
// ));
// await tester.pump();
// expect(find.byType(DetailPostKegiatanPage), findsOneWidget);
// expect(find.text('Kopdar Rutin'), findsOneWidget);
// expect(find.text('oleh DTB Indonesia'), findsOneWidget);
// expect(find.text('lorem ipsum dolor sit amet'), findsOneWidget);
// expect(find.text('Putsal 08123123123'), findsOneWidget);
// expect(find.text('Putri Salsabila'), findsOneWidget);
// expect(find.text('Komentar'), findsOneWidget);
// expect(find.text('Tambah Komentar'), findsOneWidget);
// });
testWidgets(
'Detail Post Kegiatan Page - Negative Test', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: DetailPostKegiatanPage(
lokasi: Lokasi.fromJson(mockLokasi),
kegiatan: KegiatanModel.fromJson(mockKegiatan)
)
));
await tester.pump();
expect(find.byType(DetailPostKegiatanPage), findsOneWidget);
expect(find.text('Kopdar Rajin'), findsOneWidget);
expect(find.text('oleh DTB'), findsOneWidget);
expect(find.text('lorem ipsum'), findsOneWidget);
expect(find.text('Putra 08123123123'), findsOneWidget);
expect(find.text('Putri Putra'), findsOneWidget);
expect(find.text('Komentar Review'), findsOneWidget);
expect(find.text('Post Komentar'), findsOneWidget);
});
// testWidgets(
// 'Detail Post Kegiatan Page - Negative Test', (WidgetTester tester) async {
// await tester.pumpWidget(MaterialApp(
// home: DetailPostKegiatanPage(
// lokasi: Lokasi.fromJson(mockLokasi),
// kegiatan: KegiatanModel.fromJson(mockKegiatan)
// )
// ));
// await tester.pump();
// expect(find.byType(DetailPostKegiatanPage), findsOneWidget);
// expect(find.text('Kopdar Rajin'), findsOneWidget);
// expect(find.text('oleh DTB'), findsOneWidget);
// expect(find.text('lorem ipsum'), findsOneWidget);
// expect(find.text('Putra 08123123123'), findsOneWidget);
// expect(find.text('Putri Putra'), findsOneWidget);
// expect(find.text('Komentar Review'), findsOneWidget);
// expect(find.text('Post Komentar'), findsOneWidget);
// });
}
\ No newline at end of file
......@@ -203,32 +203,4 @@ void main() {
await tester.tap(find.text('Tidak'));
await tester.pump();
});
testWidgets('Test Kegiatan in Lokasi - Positive',
(WidgetTester tester) async {
await mockNetworkImagesFor(() => tester.pumpWidget(
MaterialApp(home: Fasilitas(lokasi: Lokasi.fromJson(mockLokasi)))));
await tester.pump();
await tester.tap(find.byType(Tab).at(1));
await tester.pump();
expect(find.text('Margo City'), findsOneWidget);
expect(find.byType(TabBar), findsOneWidget);
expect(find.byType(Tab), findsWidgets);
expect(find.text('Kegiatan'), findsOneWidget);
await tester.drag(find.text('Tambah Informasi'), Offset(-500, 0));
await tester.pump();
expect(find.text('Kegiatan yang diadakan'), findsOneWidget);
}
);
// testWidgets('Test Kegiatan in Lokasi - Negative',
// (WidgetTester tester) async {
// await mockNetworkImagesFor(() => tester.pumpWidget(
// MaterialApp(home: Fasilitas(lokasi: Lokasi.fromJson(mockLokasi)))));
// await tester.pump();
// await tester.drag(find.text('Tambah Informasi'), Offset(-500, 0));
// await tester.pump();
// expect(find.text('Belum ada informasi'), findsOneWidget);
// }
// );
}
import 'dart:async';
import 'package:bisaGo/model/kegiatan.dart';
import 'package:bisaGo/model/lokasi.dart';
import 'package:bisaGo/page/filter_fasilitas/fasilitas.dart';
import 'package:bisaGo/repository/kegiatan_repository.dart';
import 'package:bisaGo/repository/komentar_posting_repository.dart';
import 'package:bisaGo/repository/komentar_repository.dart';
import 'package:bisaGo/repository/lokasi_repository.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:get_it/get_it.dart';
import 'package:mockito/mockito.dart';
import 'package:network_image_mock/network_image_mock.dart';
const mockFasilitas = {
'id': 119,
'nama_lokasi': 'Margo City',
'deskripsi': 'loremipsum ipsmum',
'creator': 'Putra Novial',
'date_time': '12-11-2020 02:56:49',
'tag': 'JI',
'disabilitas': ['DS'],
'image': 'static/img/2669211407.jpg',
'is_verified': false,
'jumlah': 2,
'rating': 5
};
class MockKomentarRepository extends Fake implements KomentarRepository {}
class MockLokasiRepository extends Fake implements LokasiRepository {
final mockLokasi = {
'placeId': 'lKHBIUnKLJnKjnKLN',
'name': 'Margo City',
'alamat':
'Jl. Margonda Raya No.358, Kemiri Muka, Kecamatan Beji, Kota Depok, Jawa Barat 16423',
'image': 'static/img/2669211407.jpg',
'no_telp': '02178870888',
'counter': 69,
};
@override
Future<LokasiListResponse> fetchLokasi() async {
return Future.value(LokasiListResponse([Lokasi.fromJson(mockLokasi)]));
}
}
class MockKomentarPostingRepository extends Fake
implements KomentarPostingRepository {}
class MockKegiatanRepository extends Fake implements KegiatanRepository {
final mockKegiatan = {
'id': 1,
'place_id': 'asdfghjkl',
'creator': 'Jovi',
'nama_kegiatan': 'Jalan Sehat',
'penyelenggara': 'Gubernur',
'narahubung': 'Rafif (0880123456123456)',
'deskripsi': 'Jalan sehat keliling kota',
'time_start': '16-05-2021 06:00:00',
'time_end': '',
'image': '',
};
@override
Future<KegiatanList> fetchKegiatan(String placeId) {
return Future.value(KegiatanList([KegiatanModel.fromJson(mockKegiatan)]));
}
}
void main() {
final mockLokasi = {
'name': 'Margo City',
'alamat':
'Jl. Margonda Raya No.358, Kemiri Muka, Kecamatan Beji, Kota Depok, Jawa Barat 16423',
'image': 'static/img/2669211407.jpg',
'no_telp': '02178870888',
'counter': 69,
};
final mockKegiatan = {
'id': 1,
'place_id': 'asdfghjkl',
'creator': 'Jovi',
'nama_kegiatan': 'Jalan Sehat',
'penyelenggara': 'Gubernur',
'narahubung': 'Rafif (0880123456123456)',
'deskripsi': 'Jalan sehat keliling kota',
'time_start': '2021-05-15 06:00:00',
'time_end': '2021-05-15 10:00:00',
'image': ['a', 'b', 'c'],
};
setUpAll(() {
final _getIt = GetIt.instance;
_getIt.registerLazySingleton<BaseKomentarRepository>(
() => MockKomentarRepository());
_getIt.registerLazySingleton<BaseKomentarPostingRepository>(
() => MockKomentarPostingRepository());
_getIt.registerLazySingleton<BaseLokasiRepository>(
() => MockLokasiRepository());
_getIt.registerLazySingleton<BaseKegiatanRepository>(
() => MockKegiatanRepository());
});
testWidgets('Test Kegiatan in Lokasi - Positive',
(WidgetTester tester) async {
await mockNetworkImagesFor(() => tester.pumpWidget(
MaterialApp(
home: Fasilitas(
lokasi: Lokasi.fromJson(mockLokasi),
kegiatan: KegiatanModel.fromJson(mockKegiatan),
)
)
));
await tester.pump();
await tester.tap(find.byType(Tab).at(1));
await tester.pump();
expect(find.text('Margo City'), findsOneWidget);
expect(find.byType(TabBar), findsOneWidget);
expect(find.byType(Tab), findsWidgets);
expect(find.text('Kegiatan'), findsOneWidget);
await tester.drag(find.text('Tambah Informasi'), Offset(-500, 0));
await tester.pump();
expect(find.text('Kegiatan yang diadakan'), findsOneWidget);
}
);
testWidgets('Test Kegiatan in Lokasi - Negative',
(WidgetTester tester) async {
await mockNetworkImagesFor(() => tester.pumpWidget(
MaterialApp(home: Fasilitas(lokasi: Lokasi.fromJson(mockLokasi)))));
await tester.pump();
await tester.drag(find.text('Tambah Informasi'), Offset(-500, 0));
await tester.pump();
expect(find.text('Belum ada informasi'), findsOneWidget);
}
);
}
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