Fakultas Ilmu Komputer UI

Commit e925c9a9 authored by Tsamara Esperanti Erwin's avatar Tsamara Esperanti Erwin 🦄
Browse files

Merge branch 'coldfix-pbi7' into 'staging'

Coldfix pbi7

See merge request !95
parents 72cfda3f 2ef18212
Pipeline #61237 passed with stages
in 30 minutes and 22 seconds
...@@ -3,9 +3,11 @@ import 'dart:async'; ...@@ -3,9 +3,11 @@ import 'dart:async';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:home_industry/Pages/Program/model/program.dart';
import 'package:home_industry/Pages/Program/repositories/program_repository.dart'; import 'package:home_industry/Pages/Program/repositories/program_repository.dart';
import 'package:stream_transform/stream_transform.dart'; import 'package:stream_transform/stream_transform.dart';
import '../program_page.dart';
import './bloc.dart'; import './bloc.dart';
class ProgramBloc extends Bloc<ProgramEvent, ProgramState> { class ProgramBloc extends Bloc<ProgramEvent, ProgramState> {
...@@ -63,16 +65,16 @@ class ProgramBloc extends Bloc<ProgramEvent, ProgramState> { ...@@ -63,16 +65,16 @@ class ProgramBloc extends Bloc<ProgramEvent, ProgramState> {
final programs = final programs =
await programRepository.fetchProgram(page: currentState.page + 1); await programRepository.fetchProgram(page: currentState.page + 1);
if (currentState is ListProgramsLoaded || currentState is InitialListProgramState) { if (currentState is ListProgramsLoaded || currentState is InitialListProgramState) {
programs.results.sort((a,b) => b.endDateTime.compareTo(a.endDateTime)); final sort = sortPrograms(programs.results);
yield ListProgramsSortedLoaded( yield ListProgramsSortedLoaded(
programs: programs.results, programs: sort,
hasReachedMax: programs.next == null, hasReachedMax: programs.next == null,
page: currentState.page + 1); page: currentState.page + 1);
return; return;
} else if (currentState is ListProgramsSortedLoaded) { } else if (currentState is ListProgramsSortedLoaded) {
programs.results.sort((a,b) => b.endDateTime.compareTo(a.endDateTime)); final sort = sortPrograms(programs.results);
yield ListProgramsSortedLoaded( yield ListProgramsSortedLoaded(
programs: currentState.programs + programs.results, programs: currentState.programs + sort,
hasReachedMax: programs.next == null, hasReachedMax: programs.next == null,
page: currentState.page + 1); page: currentState.page + 1);
return; return;
...@@ -97,3 +99,24 @@ class ProgramBloc extends Bloc<ProgramEvent, ProgramState> { ...@@ -97,3 +99,24 @@ class ProgramBloc extends Bloc<ProgramEvent, ProgramState> {
); );
} }
} }
List<Program> sortPrograms(List programs) {
final programFinished = [];
final programInProgress = [];
final programNotStarted = [];
for (var i = 0; i < programs.length; i++) {
final program = programs.elementAt(i);
if (program.endDateTime != null &&
program.endDateTime.
compareTo(CustomizableDateTime.current) < 1) {
programFinished.add(program);
} else if (program.startDateTime != null &&
CustomizableDateTime.current.
compareTo(program.startDateTime) < 1) {
programNotStarted.add(program);
} else {
programInProgress.add(program);
}
}
return [...programNotStarted, ...programInProgress, ...programFinished];
}
...@@ -381,12 +381,7 @@ class _ProgramDescription extends StatelessWidget { ...@@ -381,12 +381,7 @@ class _ProgramDescription extends StatelessWidget {
fontSize: 16, fontSize: 16,
), ),
), ),
if ( program.endDateTime != null && statusText()
program.endDateTime.compareTo(CustomizableDateTime.current) < 1)
const Text(
'Selesai',
style: TextStyle(fontWeight: FontWeight.bold),
)
]), ]),
), ),
Expanded( Expanded(
...@@ -398,6 +393,28 @@ class _ProgramDescription extends StatelessWidget { ...@@ -398,6 +393,28 @@ class _ProgramDescription extends StatelessWidget {
], ],
)); ));
} }
Widget statusText() {
if (program.startDateTime != null &&
CustomizableDateTime.current.compareTo(program.startDateTime) < 1) {
return const Text(
'Belum Mulai',
style: TextStyle(fontWeight: FontWeight.bold),
);
}
else if ( program.endDateTime != null &&
program.endDateTime.compareTo(CustomizableDateTime.current) < 1) {
return const Text(
'Selesai',
style: TextStyle(fontWeight: FontWeight.bold),
);
} else {
return const Text(
'Dalam Progress',
style: TextStyle(fontWeight: FontWeight.bold),
);
}
}
} }
class _DonasiButton extends StatelessWidget { class _DonasiButton extends StatelessWidget {
...@@ -429,7 +446,7 @@ class _DonasiButton extends StatelessWidget { ...@@ -429,7 +446,7 @@ class _DonasiButton extends StatelessWidget {
class FilterButton extends StatelessWidget { class FilterButton extends StatelessWidget {
final String sort; final String sort;
FilterButton({Key key, @required this.sort}) const FilterButton({Key key, @required this.sort})
: assert(sort != null), : assert(sort != null),
super(key: key); super(key: key);
......
...@@ -32,6 +32,7 @@ void main() { ...@@ -32,6 +32,7 @@ void main() {
Program programFinished; Program programFinished;
Program programNotFinished; Program programNotFinished;
Program program; Program program;
Program programNotStarted;
setUpAll(() async { setUpAll(() async {
Intl.defaultLocale = 'id'; Intl.defaultLocale = 'id';
...@@ -39,7 +40,7 @@ void main() { ...@@ -39,7 +40,7 @@ void main() {
}); });
setUp(() { setUp(() {
program = programFinished = Program( program = Program(
id: 'yha', id: 'yha',
name: 'Rumah Belajar', name: 'Rumah Belajar',
description: 'Belajar Komputer', description: 'Belajar Komputer',
...@@ -78,10 +79,23 @@ void main() { ...@@ -78,10 +79,23 @@ void main() {
totalDonationAmount: '0', totalDonationAmount: '0',
speaker: 'Sherlock Holmes', speaker: 'Sherlock Holmes',
posterImage: null); posterImage: null);
programNotStarted = Program(
id: 'yha',
name: 'Rumah Belajar',
description: 'Belajar Komputer',
startDateTime: DateTime.parse('2021-07-20 20:18:04'),
endDateTime: DateTime.parse('2021-10-20 20:18:04'),
location: 'Rumah saya',
code: '123',
openDonation: true,
programMinutes: null,
totalDonationAmount: '0',
speaker: 'Sherlock Holmes',
posterImage: null);
listProgram = listProgram =
ListProgram(count: 1, next: null, previous: null, results: [program]); ListProgram(count: 1, next: null, previous: null, results: [program]);
listProgramWithDate = listProgramWithDate =
ListProgram(count: 1, next: null, previous: null, results: [programNotFinished, programFinished]); ListProgram(count: 1, next: null, previous: null, results: [programNotFinished, programFinished, programNotStarted]);
dio = DioMock(); dio = DioMock();
dependenciesRepositories = DependenciesRepositories(dio: dio); dependenciesRepositories = DependenciesRepositories(dio: dio);
widgetTested = MaterialApp( widgetTested = MaterialApp(
...@@ -90,6 +104,11 @@ void main() { ...@@ -90,6 +104,11 @@ void main() {
value: dependenciesRepositories, child: Programs())); value: dependenciesRepositories, child: Programs()));
}); });
test('sort program function', () {
var sortedProgram = sortPrograms(listProgramWithDate.results);
expect(sortedProgram.elementAt(0), listProgramWithDate.results.elementAt(2));
});
testWidgets('Load one program', (WidgetTester tester) async { testWidgets('Load one program', (WidgetTester tester) async {
when(dio.get(urlProgram, queryParameters: queryParamProgram)).thenAnswer( when(dio.get(urlProgram, queryParameters: queryParamProgram)).thenAnswer(
(_) async => Response<Map<dynamic, dynamic>>( (_) async => Response<Map<dynamic, dynamic>>(
...@@ -114,8 +133,12 @@ void main() { ...@@ -114,8 +133,12 @@ void main() {
expect(find.text('Status'), findsOneWidget); expect(find.text('Status'), findsOneWidget);
expect(find.text('Tanggal'), findsOneWidget); expect(find.text('Tanggal'), findsOneWidget);
await tester.tap(find.text('Status')); await tester.tap(find.text('Status'));
await tester.pump(Duration(seconds: 5));
expect(find.byType(CustomCircularIndicator), findsOneWidget);
await tester.pump(Duration(seconds: 5));
expect(find.text('Selesai'), findsOneWidget); expect(find.text('Selesai'), findsOneWidget);
expect(find.text('Belum Mulai'), findsOneWidget);
expect(find.text('Dalam Progress'), findsOneWidget);
}); });
testWidgets('Load programs by date', (WidgetTester tester) async { testWidgets('Load programs by date', (WidgetTester tester) async {
......
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