diff --git a/android/fastlane/metadata/android/id/changelogs/changelogs.txt b/android/fastlane/metadata/android/id/changelogs/changelogs.txt index 01e948e531c43b065a32140e1bec96107932422c..808739560d94c4c8175ab9ca43a2a8427bd25401 100644 --- a/android/fastlane/metadata/android/id/changelogs/changelogs.txt +++ b/android/fastlane/metadata/android/id/changelogs/changelogs.txt @@ -1,5 +1,6 @@ -3.5.2: +3.6.0: - Tersedia nama dan foto profil pada drawer +- Tersedia daftar agenda kegiatan - Pengguna dapat mengganti foto profil - Pengguna dapat mengubah informasi kegiatan yang sudah ada @@ -11,10 +12,4 @@ - Perbaikan bugs 3.2.0: -- Tersedia fitur membagikan informasi fasilitas/kegiatan disabilitas kepada orang lain - -3.1.2: -- Perbaikan masuk dengan Google -- Tersedia fitur pencarian layanan -- Tersedia pilihan kamera ketika menambahkan gambar fasilitas -- Tersedia fitur riwayat pencarian +- Tersedia fitur membagikan informasi fasilitas/kegiatan disabilitas kepada orang lain \ No newline at end of file diff --git a/lib/bloc/kegiatan_search_bloc.dart b/lib/bloc/kegiatan_search_bloc.dart new file mode 100644 index 0000000000000000000000000000000000000000..1f7b3c9a4f66fe89da292e5a9dc58e8632884ec3 --- /dev/null +++ b/lib/bloc/kegiatan_search_bloc.dart @@ -0,0 +1,44 @@ +import 'dart:async'; + +import 'package:bisaGo/network/data/network_model.dart'; +import 'package:bisaGo/repository/kegiatan_repository.dart'; +import 'package:get_it/get_it.dart'; + +class KegiatanSearchBloc { + StreamController _recentSearchController; + KegiatanRepository _kegiatanRepository; + StreamController _kegiatanSearchListController; + + StreamController>> get recentSearchSink => + _recentSearchController.sink; + Stream>> get recentSearchStream => + _recentSearchController.stream; + + StreamSink>> get kegiatanSearchListSink => + _kegiatanSearchListController.sink; + Stream>> get layananListStream => + _kegiatanSearchListController.stream; + + KegiatanSearchBloc() { + _kegiatanSearchListController = + StreamController>>(); + _recentSearchController = + StreamController>>(); + _kegiatanRepository = GetIt.instance.get(); + } + + Future fetchKegiatanSearchList(String search, String sortConfig) async { + kegiatanSearchListSink.add(NetworkModel.loading('Getting Kegiatan')); + try { + final kegiatanSearchListResponse = await _kegiatanRepository.fetchKegiatanSearch(search, sortConfig); + kegiatanSearchListSink.add(NetworkModel.completed(kegiatanSearchListResponse)); + } catch (e) { + kegiatanSearchListSink.add(NetworkModel.error(e.toString())); + } + } + + void dispose() { + _recentSearchController?.close(); + _kegiatanSearchListController?.close(); + } +} \ No newline at end of file diff --git a/lib/bloc/lokasi_response_bloc.dart b/lib/bloc/lokasi_response_bloc.dart index 593be0888682a6bbac62c8c1d3f3a5f30842ebfe..a4024cb0b0e3cd944e952f139bcac4e60d30ad46 100644 --- a/lib/bloc/lokasi_response_bloc.dart +++ b/lib/bloc/lokasi_response_bloc.dart @@ -42,6 +42,15 @@ class LokasiResponseBloc { } } + Future fetchLokasiListById(String placeId) async { + lokasiListSink.add(NetworkModel.loading('Getting Location by Id')); + try { + return await _lokasiRepository.fetchLokasiById(placeId); + } catch (e) { + return Lokasi(); + } + } + Future fetchRecentSearch() async { recentSearchSink.add(NetworkModel.loading('Getting Recent Search')); try { diff --git a/lib/component/bisago_drawer.dart b/lib/component/bisago_drawer.dart index 9fa6a9f597de426df06dadf154d6805cdbc030eb..d00839af682315b8c1b65551fb6e93106cbb4c8d 100644 --- a/lib/component/bisago_drawer.dart +++ b/lib/component/bisago_drawer.dart @@ -1,7 +1,7 @@ import 'dart:convert'; import 'package:bisaGo/model/user.dart'; -import 'package:bisaGo/page/informasi/list_sekolah.dart'; +import 'package:bisaGo/page/informasi/list_kegiatan.dart'; import 'package:bisaGo/page/profile/profile.dart'; import 'package:bisaGo/page/tentang_disabilitas/tentang_disabilitas.dart'; import 'package:flutter/material.dart'; @@ -18,7 +18,8 @@ class BisaGoDrawer extends StatelessWidget { final List> drawerList = [ {'title': 'Beranda', 'icon': Icons.home}, {'title': 'Riwayat Pencarian', 'icon': Icons.history}, - {'title': 'Layanan Disabilitas', 'icon': Icons.group}, + // {'title': 'Layanan Disabilitas', 'icon': Icons.group}, + {'title': 'Agenda Kegiatan', 'icon': Icons.calendar_today}, {'title': 'Tentang Disabilitas', 'icon': Icons.accessible}, {'title': 'Tentang Aplikasi', 'icon': Icons.info}, {'title': 'Login', 'icon': Icons.keyboard_backspace} @@ -263,8 +264,10 @@ class BisaGoDrawer extends StatelessWidget { route = MaterialPageRoute(builder: (_) => const AboutUs()); } else if (page == 'Tentang Disabilitas') { route = MaterialPageRoute(builder: (_) => TentangDisabilitas()); - } else if (page == 'Layanan Disabilitas') { - route = MaterialPageRoute(builder: (_) => ListSekolah()); + // } else if (page == 'Layanan Disabilitas') { + // route = MaterialPageRoute(builder: (_) => ListSekolah()); + } else if (page == 'Agenda Kegiatan') { + route = MaterialPageRoute(builder: (_) => ListKegiatan()); } Navigator.of(context).push(route); } diff --git a/lib/config/strings.dart b/lib/config/strings.dart index 28c22dddda9812554ee610a2b675467ec0073c3b..381e31f482ec705327daf4449ca4f15e9648625b 100644 --- a/lib/config/strings.dart +++ b/lib/config/strings.dart @@ -105,6 +105,12 @@ const zonaWaktu = [ 'WIT', ]; +const sortBy = { + 'time':'Kegiatan Terdekat', + 'name':'Nama Kegiatan', + 'latest-added':'Kegiatan Terbaru' +}; + String getTag(String tag) { return tags[tag]; } diff --git a/lib/model/kegiatan.dart b/lib/model/kegiatan.dart index eab87fdbff76b8563ff014c7af213ceb4fcd5f5e..112ef2cf865a6681e3e8d85788b4fcdd575c4a32 100644 --- a/lib/model/kegiatan.dart +++ b/lib/model/kegiatan.dart @@ -56,4 +56,4 @@ class KegiatanModel { factory KegiatanModel.fromJson(Map json) => _$KegiatanModelFromJson(json); Map toJson() => _$KegiatanModelToJson(this); -} +} \ No newline at end of file diff --git a/lib/page/filter_fasilitas/postingan/detail_post_kegiatan.dart b/lib/page/filter_fasilitas/postingan/detail_post_kegiatan.dart index cc2a752bdfb4de38442c10a95c0e3fa1c53d7d76..05f83acce8991a20c58dc615db4949da62fa4c06 100644 --- a/lib/page/filter_fasilitas/postingan/detail_post_kegiatan.dart +++ b/lib/page/filter_fasilitas/postingan/detail_post_kegiatan.dart @@ -157,6 +157,7 @@ class _DetailPostKegiatanPageState extends State { enlargeCenterPage: true, enableInfiniteScroll: false, initialPage: 0, + autoPlay: true), items: widget.kegiatan.images .map((item) => Container( @@ -517,8 +518,7 @@ class _DetailPostKegiatanPageState extends State { ), ), ], - ), - ), + ),) ); } diff --git a/lib/page/informasi/list_kegiatan.dart b/lib/page/informasi/list_kegiatan.dart new file mode 100644 index 0000000000000000000000000000000000000000..bad46567f6a142a9e94d86741d5061a80105a8a6 --- /dev/null +++ b/lib/page/informasi/list_kegiatan.dart @@ -0,0 +1,246 @@ +import 'package:bisaGo/bloc/kegiatan_search_bloc.dart'; +import 'package:bisaGo/component/bisago_drawer.dart'; +import 'package:bisaGo/config/styles.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:bisaGo/model/kegiatan.dart'; +import 'package:bisaGo/bloc/lokasi_response_bloc.dart'; +import 'package:bisaGo/network/data/network_model.dart'; +import 'package:bisaGo/page/filter_fasilitas/postingan/detail_post_kegiatan.dart'; + + +import 'package:bisaGo/config/strings.dart'; +import 'package:bisaGo/utils/custom_dropdown_sort_kegiatan.dart'; +import 'package:bisaGo/utils/validator.dart'; +import 'package:intl/intl.dart'; + +class ListKegiatan extends StatefulWidget { + const ListKegiatan({Key key}) : super(key: key); + + @override + _ListKegiatanState createState() => _ListKegiatanState(); +} + +class _ListKegiatanState extends State { + /// Search Icon for textFormField + Icon searchIcon = const Icon(Icons.search); + + KegiatanSearchBloc kegiatan_search_bloc = KegiatanSearchBloc(); + LokasiResponseBloc lokasi_bloc = LokasiResponseBloc(); + + @override void initState() { + _sortConfig = 'time'; + kegiatan_search_bloc.fetchKegiatanSearchList(_text,_sortConfig); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Colors.white, + drawer: BisaGoDrawer(), + appBar: AppBar( + backgroundColor: greenPrimary, + leading: IconButton( + icon: const Icon(Icons.arrow_back_ios, size: 25), + key: const Key('Back Icon Key'), + onPressed: () => Navigator.of(context).pop()), + title: Container( + margin: const EdgeInsets.only(top: doubleSpace, bottom: doubleSpace), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: doubleBorderRadius, + boxShadow: regularShadow), + child: TextFormField( + onFieldSubmitted: (text) { + _text = text; + kegiatan_search_bloc.fetchKegiatanSearchList(_text,_sortConfig); + }, + key: const Key('Text Field Cari Kegiatan'), + decoration: InputDecoration( + prefixIcon: const Icon( + Icons.search, + color: greenPrimary, + size: 25, + ), + hintText: 'Cari kegiatan di sini', + ), + ), + ), + ), + body: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Padding( + padding: EdgeInsets.only( + top: doubleSpace, left: doubleSpace, right: doubleSpace), + child: Text( + 'Agenda Kegiatan' ?? '', + style: TextStyle( + fontSize: 25, + fontFamily: 'Muli', + fontWeight: FontWeight.w800), + ), + ), + Container( + child: CustomDropdown( + title: 'Urutkan berdasarkan:', + required: true, + key: const Key('Dropdown Sort Kegiatan'), + validator: FieldValidator.validateDropdown, + dropdownList: sortBy, + hint: 'Kegiatan Terdekat', // hardcoded + onChanged: (value) { + setState(() { + _sortConfig=value; + }); + kegiatan_search_bloc.fetchKegiatanSearchList(_text,_sortConfig); + }, + ), + ), + //BLoC for Kegiatan Search + StreamBuilder>>( + stream: kegiatan_search_bloc.layananListStream, + builder: (context, snapshot) { + if (snapshot.hasData) { + switch (snapshot.data.status) { + case Status.loading: + return const Center( + child: CircularProgressIndicator( + valueColor: + AlwaysStoppedAnimation(greenPrimary), + ), + ); + break; + case Status.completed: + var layanan = snapshot.data.data; + return Column( + children: layanan.map((each) { + return makeKegiatanWidget('kegiatan', each); + }).toList(), + ); + break; + case Status.error: + return Center(child: Container( + padding: const EdgeInsets.only(top: tripleSpace), + child: Text('Tidak ada kegaitan ditemukan', + style: const TextStyle( + fontSize: 18, + color: Colors.black, + fontFamily: 'Muli', + ), + + textAlign: TextAlign.center,),),); + break; + } + } + return Container(); + }, + ), + ], + ), + ), + ); + } + + Widget makeKegiatanWidget(String key, KegiatanModel kegiatan) { + return InkWell( + key: Key('$key-${kegiatan.id}'), + onTap: () { + _navigateToDetailKegiatanPage(context, kegiatan); + }, + child: Container( + decoration: BoxDecoration( + color: Colors.transparent, + border: Border(bottom: BorderSide(color: Colors.grey[400]))), + margin: const EdgeInsets.only(left: doubleSpace, right: doubleSpace), + height: 90, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const CircleAvatar( + backgroundColor: greenPrimary, + child: Icon( + Icons.school, + color: Colors.white, + ), + ), + Expanded( + child: Container( + padding: const EdgeInsets.all(doubleSpace), + child: Row( + //crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Flexible( + child:Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + kegiatan.namaKegiatan, + overflow: TextOverflow.ellipsis, + textAlign: TextAlign.left, + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.w800, + color: Colors.black, + fontFamily: 'Muli', + ), + ), + Text( + kegiatan.penyelenggara, + overflow: TextOverflow.ellipsis, + textAlign: TextAlign.left, + style: const TextStyle( + fontSize: 15, + //fontWeight: FontWeight.w800, + color: Colors.black, + fontFamily: 'Muli', + ), + ), + ] + ), + ), + Text( + DateFormat('dd-MM-yyyy\nhh:mm').format(kegiatan.timeStart), + overflow: TextOverflow.ellipsis, + textAlign: TextAlign.right, + style: const TextStyle( + fontSize: 15, + color: Colors.black, + fontFamily: 'Muli', + ), + ), + ], + ), + ), + ), + Icon( + Icons.arrow_forward_ios, + color: Colors.grey[400], + size: 20, + ) + ], + ), + ), + ); + } + + void _navigateToDetailKegiatanPage( + BuildContext context, KegiatanModel kegiatan) async { + final lokasi = await lokasi_bloc.fetchLokasiListById(kegiatan.placeId); + final route = MaterialPageRoute( + builder: (_) => DetailPostKegiatanPage( + lokasi: lokasi, + kegiatan: kegiatan)); + await Navigator.of(context).push(route); + } + + String getTanggalFormatting(KegiatanModel kegiatan) { + return null; + } + + String _text; + String _sortConfig; +} \ No newline at end of file diff --git a/lib/page/informasi/list_sekolah.dart b/lib/page/informasi/list_sekolah.dart index c522186cb1f1a9b4ffef400e1488f5445d2070db..8409480bac3ca93b4d4b1efb7316a21c11e631fb 100644 --- a/lib/page/informasi/list_sekolah.dart +++ b/lib/page/informasi/list_sekolah.dart @@ -91,7 +91,7 @@ class _ListSekolahState extends State { padding: EdgeInsets.only( top: tripleSpace, left: doubleSpace, right: doubleSpace), child: Text( - 'Jenis Layanan', + 'Agenda Kegiatan', style: TextStyle( fontSize: 25, fontFamily: 'Muli', diff --git a/lib/page/profile/profile.dart b/lib/page/profile/profile.dart index 1be14a3bdcc0217fdc39309c75bcb9b40bbb7fee..5861ecc491d67442171ebe9ba28b0c37d028858c 100644 --- a/lib/page/profile/profile.dart +++ b/lib/page/profile/profile.dart @@ -363,6 +363,7 @@ class _ProfileState extends State { } Color _getFontColor(String fieldName, {Color seenColor = seenColor}) { + if (user == null) return seenColor; if (user.canSeeHiddenFields) return seenColor; final hiddenFields = user.hiddenFields; if (hiddenFields.contains(fieldName)) { diff --git a/lib/repository/kegiatan_repository.dart b/lib/repository/kegiatan_repository.dart index 986d6f6f8efe9f989d04193ce41fbf7045ac8a0d..319d0558be7d9dd93a0a820120310a4c22831906 100644 --- a/lib/repository/kegiatan_repository.dart +++ b/lib/repository/kegiatan_repository.dart @@ -9,6 +9,7 @@ abstract class BaseKegiatanRepository { Future updateKegiatan( Map newKegiatanData, String placeId, int kegiatanId); Future fetchDetailKegiatan(String placeId, int kegiatanId); + Future fetchKegiatanSearch(String search, String sortConfig); } class KegiatanRepository implements BaseKegiatanRepository { @@ -30,6 +31,20 @@ class KegiatanRepository implements BaseKegiatanRepository { return KegiatanList(allKegiatan); } + @override + Future fetchKegiatanSearch(String search, String sortConfig) async { + var url = '/informasi-fasilitas/lokasi/list-kegiatan-by-$sortConfig'; + if(search != null && search!=''){ + url += '/$search'; + } + final response = await _network.get(url: url, isLogin: false); + var list = []; + for (var each in response.entries.toList()) { + list.add(KegiatanModel.fromJson(each.value)); + } + return list; // KegiatanSearchList + } + @override Future> fetchImages(String placeId, int id) async { final url = '/informasi-fasilitas/lokasi/list-foto-kegiatan/$placeId/$id'; diff --git a/lib/repository/lokasi_repository.dart b/lib/repository/lokasi_repository.dart index 502bfab4fea35c81b902ace72fab42129af03123..de2415a17b1bf555696e018e7d3ceb928b324cd1 100644 --- a/lib/repository/lokasi_repository.dart +++ b/lib/repository/lokasi_repository.dart @@ -11,6 +11,8 @@ import 'package:http/http.dart' as http; abstract class BaseLokasiRepository { Future fetchLokasi(); + Future fetchLokasiById(String placeId); + Future fetchRecentSearch(); Future saveRecentSearch(Lokasi recentSearch); @@ -65,6 +67,32 @@ class LokasiRepository implements BaseLokasiRepository { return LokasiListResponse(freqPlaces); } + @override + Future fetchLokasiById(String placeId) async { + final _places = GoogleMapsPlaces(apiKey: DotEnv().env['API_KEY']); + var details = await _places.getDetailsByPlaceId( + placeId, + fields: [ + 'name', + 'formatted_address', + 'formatted_phone_number', + 'photos' + ], + ); + + final result = details.result; + final lokasi = Lokasi() + ..placeId = result.placeId + ..name = result.name ?? 'INVALID' + ..alamat = result.formattedAddress ?? 'LOCATION INVALID' + ..noTelp = result.formattedPhoneNumber ?? '-'; + + final image = fetchPhoto(details.result.photos[0].photoReference, 480, 480) ?? ''; + lokasi.image = image; + + return lokasi; + } + @override Future fetchRecentSearch() async { final response = await CookiesInterface().getSearchHistory(); diff --git a/lib/utils/custom_dropdown_sort_kegiatan.dart b/lib/utils/custom_dropdown_sort_kegiatan.dart new file mode 100644 index 0000000000000000000000000000000000000000..14c3420bd0ac548a5df1ecc7aef5307c3c399aeb --- /dev/null +++ b/lib/utils/custom_dropdown_sort_kegiatan.dart @@ -0,0 +1,106 @@ +import 'package:bisaGo/config/styles.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +class CustomDropdown extends StatefulWidget { + const CustomDropdown({ + this.title, + this.hint, + this.required = false, + this.key, + this.validator, + this.onSaved, + this.dropdownList, + this.onChanged, + this.value, + }) : super(key: key); + final String title; + final String value; + @override + final Key key; + final FormFieldSetter onSaved; + final String hint; + final bool required; + final FormFieldValidator validator; + final Map dropdownList; + final Function onChanged; + + @override + _CustomDropdownState createState() => _CustomDropdownState(); +} + +class _CustomDropdownState extends State { + final List> _dropdownMenuItems = []; + + void loadDropdownList() { + for (final key in widget.dropdownList.keys) { + _dropdownMenuItems.add(DropdownMenuItem( + key: Key('Dropdown Item ${widget.dropdownList[key]}'), + value: key, + child: Text(widget.dropdownList[key]), + )); + } + } + + void setDefaultValue() { + + } + + @override + void initState() { + super.initState(); + loadDropdownList(); + } + + @override + Widget build(BuildContext context) { + return Container( + margin: const EdgeInsets.only( + top: tripleSpace, + left: doubleSpace, + right: doubleSpace,), + child: Row( + //crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + RichText( + key: Key(widget.title), + text: TextSpan( + text: widget.title, + style: TextStyle( + fontSize: widget.title == '' ? 0 : 15, + color: Colors.black, + fontFamily: 'Muli'), + ), + ), + + // Container width and fontSize are bounded, re-adjust required after any change(s) + Container( + width: 170, + child:DropdownButtonFormField( + isExpanded: true, + onSaved: widget.onSaved, + validator: widget.validator, + style: const TextStyle( + color: Colors.black, + fontSize: 15, + fontFamily: 'Muli', + fontWeight: FontWeight.w800, + ), + decoration: InputDecoration.collapsed( + hintStyle: + const TextStyle( + fontSize: 15, + fontFamily: 'Muli', + fontWeight: FontWeight.w800,), + hintText: widget.hint, + ), + value: widget.value, + items: _dropdownMenuItems, + onChanged: widget.onChanged, + ),), + ], + ), + ); + } +} diff --git a/test/bisago_drawer_test.dart b/test/bisago_drawer_test.dart index 507a5ed6e5d268e4ac89e1c02b9fbdf7809b8322..e0ddd6253de68bc6876e2a519eab50aa6778905d 100644 --- a/test/bisago_drawer_test.dart +++ b/test/bisago_drawer_test.dart @@ -116,6 +116,10 @@ void main() { await tester.tap(locateDrawer); await tester.ensureVisible(locateDrawer); await tester.pumpAndSettle(); + expect(find.text('Agenda Kegiatan'), findsOneWidget); + + await tester.tap(find.byKey(agendaKegiatanKey)); + expect(find.text('Lihat Profil'), findsOneWidget); await tester.tap(find.byKey(menuProfileKey)); diff --git a/test/custom_dropdown_sort_kegiatan.dart b/test/custom_dropdown_sort_kegiatan.dart new file mode 100644 index 0000000000000000000000000000000000000000..88d9b2850fba8afd23dca8ff0113e242a7bf4edf --- /dev/null +++ b/test/custom_dropdown_sort_kegiatan.dart @@ -0,0 +1,36 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:bisaGo/utils/custom_dropdown_sort_kegiatan.dart'; + +void main() { + testWidgets('Renders Title and MenuItems -- Positive', + (WidgetTester tester) async { + final list = {'item 1': 'Item 1', 'item 2': 'Item 2'}; + + await tester.pumpWidget( + StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + return MaterialApp( + home: Material( + child: Center( + child: CustomDropdown( + title: 'Title', + required: true, + dropdownList: list, + onChanged: (value) { + setState(() { + value = 'item 1'; + }); + }), + ), + ), + ); + }, + ), + ); + + expect(find.byType(CustomDropdown), findsOneWidget); + expect(find.byKey(Key('Title')), findsOneWidget); + expect(find.text('Item 1'), findsOneWidget); + }); +} diff --git a/test/list_kegiatan_test.dart b/test/list_kegiatan_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..9c797811ad9ca64de5fc9758ba68dc478c3aeb2b --- /dev/null +++ b/test/list_kegiatan_test.dart @@ -0,0 +1,119 @@ +import 'package:bisaGo/repository/kegiatan_repository.dart'; +import 'package:bisaGo/repository/lokasi_repository.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:get_it/get_it.dart'; +import 'package:flutter/material.dart'; +import 'package:bisaGo/page/informasi/list_kegiatan.dart'; + +class MockKegiatanRepository extends Fake implements KegiatanRepository { + 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 mockKegiatan2 = { + 'id': 3, + 'nama_lokasi': 'Margo City', + 'creator': 'Putri Salsabila', + 'nama_kegiatan': 'Rapat Mingguan', + 'penyelenggara': 'DTB Indonesia', + 'narahubung': 'Putsal 08123123123', + 'deskripsi': 'lorem ipsum dolor sit amet', + 'time_start': '10-12-2021 06:30:00', + 'time_end': '10-12-2021 09:30:00' + }; +} + +class MockLokasiRepository extends Fake implements LokasiRepository { + final komunitasData = { + '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, + }; +} + +void main() { + setUpAll(() { + final _getIt = GetIt.instance; + _getIt.registerLazySingleton( + () => MockKegiatanRepository()); + _getIt.registerLazySingleton( + () => MockLokasiRepository()); + }); + + testWidgets('Find Agenda Kegiatan Page', (WidgetTester tester) async { + // Provide the childWidget to the Container. + await tester.pumpWidget(MaterialApp(home: ListKegiatan())); + await tester.pumpAndSettle(); + + // positive test + expect(find.text('Agenda Kegiatan'), findsOneWidget); + + // negative test + expect(find.text('aagenda kkegiatan'), findsNothing); + + // Provide text field + final textFieldKey = Key('Text Field Cari Kegiatan'); + final textFieldKey2 = Key('Text Field Cari Kegiatann'); + + // positive test + expect(find.byKey(textFieldKey), findsOneWidget); + + // negative test + expect(find.byKey(textFieldKey2), findsNothing); + + // input text + await tester.enterText(find.byKey(textFieldKey), 'Kopdar Rutin'); + await tester.pumpAndSettle(); + + // positive test + expect(find.text('Kopdar Rutin'), findsOneWidget); + + // negative test + expect(find.text('Kopdar Rajin'), findsNothing); + + // redirect to detail kegiatan + await tester.tap(find.text('Kopdar Rutin')); + await tester.pumpAndSettle(); + + // positive test + expect(find.text('Kopdar Rutin'), findsOneWidget); + + // negative test + expect(find.text('Kopdar Rajin'), findsNothing); + }); + + testWidgets('Find Sort Kegiatan Dropdown', (WidgetTester tester) async { + final textFieldKey = Key('Dropdown Sort Kegiatan'); + await tester.pumpWidget(MaterialApp(home: ListKegiatan())); + expect(find.byKey(textFieldKey), findsOneWidget); + }); + + testWidgets('Sort Function', (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp(home: ListKegiatan())); + + final sortKey = find.byKey(Key('Dropdown Sort Kegiatan')); + + await tester.ensureVisible( + find.byKey(Key('Dropdown Sort Kegiatan'), skipOffstage: false)); + await tester.pumpAndSettle(const Duration(seconds: 1)); + await tester.tap(sortKey); + await tester.pumpAndSettle(); + await tester.tap(find + .byKey(Key('Dropdown Item Kegiatan Terbaru')) + .last); + await tester.pumpAndSettle(); + await tester.tap(sortKey); + await tester.pumpAndSettle(); + }); +} +