Skip to content

Commit

Permalink
Fix/event calender screen bug (#2405)
Browse files Browse the repository at this point in the history
* fix the event calender bug

* fix failing test case

* fix failing test case

* used on clause

* added test for missing line

* added test for missing line

* fix failinf test

* fix event calender bug

* added test

* fix failing test case

* fix failing test case

* added test

* added more test

* fix failing test case

* fixed formating error
  • Loading branch information
AVtheking authored Mar 11, 2024
1 parent 4a669a4 commit da23331
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 68 deletions.
11 changes: 2 additions & 9 deletions lib/views/after_auth_screens/events/event_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,21 @@ _AppointmentDataSource _getCalendarDataSource(List<Event> eventsList) {
int index = 0;
// looping through all the events created in the organization.
eventsList.forEach((event) {
DateTime? startDate;
DateTime? endDate;

/// change made here, code related to the fix.
DateTime startDate;
DateTime endDate;
if (event.startDate!.contains('/')) {
startDate = DateFormat('MM/dd/yyyy').parse(event.startDate!);
} else {
startDate = DateFormat('yyyy-MM-dd').parse(event.startDate!);
}

/// change made here, code related to the fix.
if (event.endDate!.contains('/')) {
endDate = DateFormat('MM/dd/yyyy').parse(event.endDate!);
} else {
endDate = DateFormat('yyyy-MM-dd').parse(event.endDate!);
}

// final startDate = DateFormat('yMd').parse(event.startDate!);
print("${event.startTime!}##############################");
final startTime = parseTime(event.startTime ?? '14:23:01');
// .parse(event.startTime!);
// final endDate = DateFormat('yMd').parse(event.endDate!);
final endTime = parseTime(event.endTime ?? '21:23:01');

// adding appointments on the calender for event[index] date time.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1715,4 +1715,4 @@ packages:
version: "3.1.2"
sdks:
dart: ">=3.2.0 <3.13.0"
flutter: ">=3.16.0"
flutter: ">=3.16.0"
181 changes: 123 additions & 58 deletions test/widget_tests/after_auth_screens/events/event_calendar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ Widget createEventCalendar() {
);
}

Widget createEventCalender2() {
return MaterialApp(
navigatorKey: navigationService.navigatorKey,
home: EventCalendar([
Event(
title: 'Test2',
startDate: '2022-07-14',
startTime: '14:23:01',
endDate: '2022-07-14',
endTime: '21:23:01',
),
]),
);
}

void main() {
setUp(() {
registerServices();
Expand All @@ -51,66 +66,116 @@ void main() {

expect(expectTime, parsedTime);
});
});
group('Tests for EventCalendar', () {
setUp(() => locator.registerSingleton(EventCalendarViewModel()));
tearDown(() => locator.unregister<EventCalendarViewModel>());
testWidgets('Testing if EventCalendar shows up', (tester) async {
await tester.pumpWidget(createEventCalendar());
await tester.pump();

expect(find.byType(EventCalendar), findsOneWidget);
});
testWidgets('Testing if tapping on date_range shows datePicker',
(tester) async {
await tester.pumpWidget(createEventCalendar());
await tester.pump();

await tester.tap(find.byIcon(Icons.date_range));
await tester.pumpAndSettle();

expect(find.byType(CalendarDatePicker), findsOneWidget);

await tester.tap(find.text('16'));
await tester.tap(find.text('OK'));
await tester.pump();
});

testWidgets('calendarViewSelection', (tester) async {
await tester.pumpWidget(
createEventCalendar(),
);

await tester.pump();

final popupButtonFinder = find.byType(PopupMenuButton<String>);

await tester.tap(popupButtonFinder);
await tester.pumpAndSettle();

await tester.tap(find.text("Day"));
await tester.pumpAndSettle();

await tester.tap(popupButtonFinder);
await tester.pumpAndSettle();

await tester.tap(find.text("Month"));
await tester.pumpAndSettle();

await tester.tap(popupButtonFinder);
await tester.pumpAndSettle();

await tester.tap(find.text("Schedule"));
await tester.pumpAndSettle();

await tester.tap(popupButtonFinder);
await tester.pumpAndSettle();

expect(find.text("Day"), findsOne);
expect(find.text("Month"), findsOne);
expect(find.text("Schedule"), findsOne);
group('Tests for EventCalendar', () {
setUp(() => locator.registerSingleton(EventCalendarViewModel()));
tearDown(() => locator.unregister<EventCalendarViewModel>());
testWidgets('Testing if EventCalendar shows up', (tester) async {
await tester.pumpWidget(createEventCalendar());
await tester.pump();

expect(find.byType(EventCalendar), findsOneWidget);
});
testWidgets('Testing if tapping on date_range shows datePicker',
(tester) async {
await tester.pumpWidget(createEventCalendar());
await tester.pump();

await tester.tap(find.byIcon(Icons.date_range));
await tester.pumpAndSettle();

expect(find.byType(CalendarDatePicker), findsOneWidget);

await tester.tap(find.text('16'));
await tester.tap(find.text('OK'));
await tester.pump();
});

testWidgets('calendarViewSelection', (tester) async {
await tester.pumpWidget(
createEventCalendar(),
);

await tester.pump();

final popupButtonFinder = find.byType(PopupMenuButton<String>);

await tester.tap(popupButtonFinder);
await tester.pumpAndSettle();

await tester.tap(find.text("Day"));
await tester.pumpAndSettle();

await tester.tap(popupButtonFinder);
await tester.pumpAndSettle();

await tester.tap(find.text("Month"));
await tester.pumpAndSettle();

await tester.tap(popupButtonFinder);
await tester.pumpAndSettle();

await tester.tap(find.text("Schedule"));
await tester.pumpAndSettle();

await tester.tap(popupButtonFinder);
await tester.pumpAndSettle();

expect(find.text("Day"), findsOne);
expect(find.text("Month"), findsOne);
expect(find.text("Schedule"), findsOne);
});
testWidgets('Testing if Event model parses dates correctly',
(tester) async {
await tester.pumpWidget(createEventCalendar());
await tester.pump();

final eventCalendar =
tester.widget<EventCalendar>(find.byType(EventCalendar));
final event = eventCalendar.eventList[0];

DateTime startDate;
DateTime endDate;
if (event.startDate!.contains('/')) {
startDate = DateFormat('MM/dd/yyyy').parse(event.startDate!);
} else {
startDate = DateFormat('yyyy-MM-dd').parse(event.startDate!);
}
if (event.endDate!.contains('/')) {
endDate = DateFormat('MM/dd/yyyy').parse(event.endDate!);
} else {
endDate = DateFormat('yyyy-MM-dd').parse(event.endDate!);
}

expect(startDate, DateFormat('MM/dd/yyyy').parse('07/14/2022'));
expect(endDate, DateFormat('MM/dd/yyyy').parse('07/14/2022'));
});
testWidgets("Testing if EventCalendar shows up", (tester) async {
await tester.pumpWidget(createEventCalender2());
await tester.pump();

expect(find.byType(EventCalendar), findsOneWidget);
final eventCalendar =
tester.widget<EventCalendar>(find.byType(EventCalendar));
final event = eventCalendar.eventList[0];

DateTime startDate;
DateTime endDate;
if (event.startDate!.contains('/')) {
startDate = DateFormat('MM/dd/yyyy').parse(event.startDate!);
} else {
startDate = DateFormat('yyyy-MM-dd').parse(event.startDate!);
}
if (event.endDate!.contains('/')) {
endDate = DateFormat('MM/dd/yyyy').parse(event.endDate!);
} else {
endDate = DateFormat('yyyy-MM-dd').parse(event.endDate!);
}

expect(startDate, DateFormat('yyyy-MM-dd').parse('2022-07-14'));
expect(endDate, DateFormat('yyyy-MM-dd').parse('2022-07-14'));
});
});

test("dateRangePickerController getter", () async {
final EventCalendarViewModel model = EventCalendarViewModel();
expect(model.dateRangePickerController, isA<DateRangePickerController>());
Expand Down

0 comments on commit da23331

Please sign in to comment.