From b4ae4e6b345b54c758ab180abf936bd8b7cf56a9 Mon Sep 17 00:00:00 2001 From: Mathias Jakobsen <58025878+BicaniWolfie@users.noreply.github.com> Date: Mon, 13 Nov 2023 14:20:39 +0100 Subject: [PATCH] Issue #931 (#962) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed issue with choice boards Fixed issue with choice boards becoming regular activity cards when a pictogram is selected in the choice board by a citizen * Fixed weekplan_screen_test.dart * Update weekplanner_choiceboard_selector.dart --------- Co-authored-by: Jacob Søndergaard --- .../activity_card.dart | 200 +-- .../weekplan_day_column.dart | 145 +- .../weekplanner_choiceboard_selector.dart | 152 ++- test/screens/weekplan_screen_test.dart | 1162 +++++++++-------- 4 files changed, 850 insertions(+), 809 deletions(-) diff --git a/lib/widgets/weekplan_screen_widgets/activity_card.dart b/lib/widgets/weekplan_screen_widgets/activity_card.dart index fa6f4ec2f..ff9815f2a 100644 --- a/lib/widgets/weekplan_screen_widgets/activity_card.dart +++ b/lib/widgets/weekplan_screen_widgets/activity_card.dart @@ -21,7 +21,7 @@ import '../../style/custom_color.dart' as theme; /// Widget used for activities in the weekplan screen. class ActivityCard extends StatelessWidget { /// Constructor - ActivityCard(this._activity,this._timerBloc, this._user) { + ActivityCard(this._activity, this._timerBloc, this._user) { _settingsBloc.loadSettings(_user); } @@ -129,52 +129,98 @@ class ActivityCard extends StatelessWidget { ), ); } - return Container( - decoration: BoxDecoration( + + if (_activity.chosenActivity != -1 && + weekModeSnapShot.data != WeekplanMode.guardian) { + return Opacity( + opacity: _shouldActivityBeVisible(weekModeSnapShot, settingsSnapShot) + ? 1.0 + : 0, + child: Container( color: theme.GirafColors.white, - border: Border.all( - color: Colors.black, - width: MediaQuery.of(context).size.width * 0.01)), - margin: EdgeInsets.all(MediaQuery.of(context).size.width * 0.02), - child: FittedBox( - child: Column( - children: [ - Stack( + margin: EdgeInsets.all(MediaQuery.of(context).size.width * 0.02), + child: FittedBox( + child: Column( children: [ Stack( - alignment: AlignmentDirectional.topEnd, children: [ - SizedBox( - width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.width, - child: FittedBox( - child: Stack( - alignment: AlignmentDirectional.center, - children: [ - SizedBox( - key: const Key('WeekPlanScreenChoiceBoard'), - width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.width, - child: returnGridView(pictograms)), - ], - )), + Stack( + alignment: AlignmentDirectional.topEnd, + children: [ + SizedBox( + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.width, + child: FittedBox( + child: _getPictogram(_activity + .pictograms[_activity.chosenActivity]), + ), + ), + _buildActivityStateIcon(context, _activityState, + weekModeSnapShot, settingsSnapShot), + _buildTimerIcon(context, _activity), + ], + ), + Stack( + alignment: AlignmentDirectional.topStart, + children: [ + _buildAvatarIcon(context), + ], ), - _buildActivityStateIcon(context, _activityState, - weekModeSnapShot, settingsSnapShot), - _buildTimerIcon(context, _activity), ], ), - Stack( - alignment: AlignmentDirectional.topStart, - children: [ - _buildAvatarIcon(context), - ]) + PictogramText(_activity, _user), ], ), - PictogramText(_activity, _user), - ], - ), - )); + )), + ); + } else { + return Container( + decoration: BoxDecoration( + color: theme.GirafColors.white, + border: Border.all( + color: Colors.black, + width: MediaQuery.of(context).size.width * 0.01)), + margin: EdgeInsets.all(MediaQuery.of(context).size.width * 0.02), + child: FittedBox( + child: Column( + children: [ + Stack( + children: [ + Stack( + alignment: AlignmentDirectional.topEnd, + children: [ + SizedBox( + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.width, + child: FittedBox( + child: Stack( + alignment: AlignmentDirectional.center, + children: [ + SizedBox( + key: const Key('WeekPlanScreenChoiceBoard'), + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.width, + child: returnGridView(pictograms)), + ], + )), + ), + _buildActivityStateIcon(context, _activityState, + weekModeSnapShot, settingsSnapShot), + _buildTimerIcon(context, _activity), + ], + ), + Stack( + alignment: AlignmentDirectional.topStart, + children: [ + _buildAvatarIcon(context), + ]) + ], + ), + PictogramText(_activity, _user), + ], + ), + )); + } } ///Returns the correct gridview @@ -225,8 +271,8 @@ class ActivityCard extends StatelessWidget { AsyncSnapshot settingsSnapShot) { return StreamBuilder( stream: _timerBloc.timerRunningMode, - builder: (BuildContext context, - AsyncSnapshot snapshot1) { + builder: + (BuildContext context, AsyncSnapshot snapshot1) { if (weekModeSnapShot.hasData && settingsSnapShot.hasData) { final WeekplanMode role = weekModeSnapShot.data; final SettingsModel settings = settingsSnapShot.data; @@ -237,25 +283,17 @@ class ActivityCard extends StatelessWidget { snapshot1.data != TimerRunningMode.running) { break; } - return Container(child: TimerPiechart(_timerBloc), - width: MediaQuery - .of(context) - .size - .width, - height: MediaQuery - .of(context) - .size - .height); + return Container( + child: TimerPiechart(_timerBloc), + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.height); case ActivityState.Completed: if (role == WeekplanMode.guardian) { return Icon( Icons.check, key: const Key('IconComplete'), color: theme.GirafColors.green, - size: MediaQuery - .of(context) - .size - .width, + size: MediaQuery.of(context).size.width, ); } else if (role == WeekplanMode.citizen) { if (settings.completeMark == null) { @@ -267,23 +305,14 @@ class ActivityCard extends StatelessWidget { Icons.check, key: const Key('IconComplete'), color: theme.GirafColors.green, - size: MediaQuery - .of(context) - .size - .width, + size: MediaQuery.of(context).size.width, ); } else if (settings.completeMark == CompleteMark.MovedRight) { return Container( key: const Key('GreyOutBox'), color: theme.GirafColors.transparentGrey, - height: MediaQuery - .of(context) - .size - .width, - width: MediaQuery - .of(context) - .size - .width); + height: MediaQuery.of(context).size.width, + width: MediaQuery.of(context).size.width); } else if (settings.completeMark == CompleteMark.Removed) { //This case should be handled by _shouldActivityBeVisiblei return Container( @@ -293,17 +322,13 @@ class ActivityCard extends StatelessWidget { } } - return const Center(child: CircularProgressIndicator()); case ActivityState.Canceled: return Icon( Icons.clear, key: const Key('IconCanceled'), color: theme.GirafColors.red, - size: MediaQuery - .of(context) - .size - .width, + size: MediaQuery.of(context).size.width, ); break; case ActivityState.Active: @@ -313,10 +338,7 @@ class ActivityCard extends StatelessWidget { Icons.brightness_1_outlined, key: const Key('IconActive'), color: theme.GirafColors.amber, - size: MediaQuery - .of(context) - .size - .width, + size: MediaQuery.of(context).size.width, ); } if (role == WeekplanMode.citizen && @@ -325,10 +347,7 @@ class ActivityCard extends StatelessWidget { Icons.brightness_1_outlined, key: const Key('IconActive'), color: theme.GirafColors.amber, - size: MediaQuery - .of(context) - .size - .width, + size: MediaQuery.of(context).size.width, ); } else { return Container( @@ -337,21 +356,20 @@ class ActivityCard extends StatelessWidget { ); } - break; - default: + break; + default: + return Container( + width: 0, + height: 0, + ); + } + } + //If no settings/role have been loaded then we just make an empty overlay return Container( - width: 0, - height: 0 - , + width: 0, + height: 0, ); - } - } - //If no settings/role have been loaded then we just make an empty overlay - return Container( - width: 0, - height: 0, - ); - }); + }); } Widget _buildTimerIcon(BuildContext context, ActivityModel activity) { diff --git a/lib/widgets/weekplan_screen_widgets/weekplan_day_column.dart b/lib/widgets/weekplan_screen_widgets/weekplan_day_column.dart index 2fafcb5d4..b01b8e47e 100644 --- a/lib/widgets/weekplan_screen_widgets/weekplan_day_column.dart +++ b/lib/widgets/weekplan_screen_widgets/weekplan_day_column.dart @@ -29,12 +29,11 @@ import 'activity_card.dart'; /// Widget used to create a single column in the weekplan screen. class WeekplanDayColumn extends StatelessWidget { /// Constructor - WeekplanDayColumn({ - @required this.color, - @required this.user, - @required this.weekplanBloc, - @required this.streamIndex - }) { + WeekplanDayColumn( + {@required this.color, + @required this.user, + @required this.weekplanBloc, + @required this.streamIndex}) { _settingsBloc.loadSettings(user); } @@ -51,21 +50,18 @@ class WeekplanDayColumn extends StatelessWidget { /// Index of the weekday in the weekdayStreams list final int streamIndex; - final AuthBloc _authBloc = di.get(); final SettingsBloc _settingsBloc = di.get(); final ActivityBloc _activityBloc = di.get(); final List _timerBloc = []; + /// Method used to create TimerBlocs. void createTimerBlocs(int numOfTimeBlocs) { - for (int i = 0; i <= numOfTimeBlocs- _timerBloc.length; i++) { + for (int i = 0; i <= numOfTimeBlocs - _timerBloc.length; i++) { _timerBloc.add(di.get()); } } - - - @override Widget build(BuildContext context) { return StreamBuilder( @@ -137,9 +133,8 @@ class WeekplanDayColumn extends StatelessWidget { fontWeight: FontWeight.bold, fontSize: isToday(day) ? 40 : 30, foreground: Paint() - ..style = isToday(day) - ? PaintingStyle.stroke - : PaintingStyle.fill + ..style = + isToday(day) ? PaintingStyle.stroke : PaintingStyle.fill ..strokeWidth = 5 ..color = Colors.black, ), @@ -228,8 +223,8 @@ class WeekplanDayColumn extends StatelessWidget { /// Returns true if the field dayOfTheWeek matches with today's date /// This function is mainly used for highlighting today's date on the weekplan - bool isToday(Weekday weekday){ - return DateTime.now().weekday.toInt()-1 == weekday.index; + bool isToday(Weekday weekday) { + return DateTime.now().weekday.toInt() - 1 == weekday.index; } /// Unmarks all activities for a given day @@ -242,10 +237,10 @@ class WeekplanDayColumn extends StatelessWidget { } /// Marks the first Normal activity to Active - void markCurrent(WeekdayModel weekdayModel){ - if(isToday(weekdayModel.day)){ - for (ActivityModel activity in weekdayModel.activities){ - if(activity.state == ActivityState.Normal){ + void markCurrent(WeekdayModel weekdayModel) { + if (isToday(weekdayModel.day)) { + for (ActivityModel activity in weekdayModel.activities) { + if (activity.state == ActivityState.Normal) { activity.state = ActivityState.Active; break; } @@ -254,17 +249,16 @@ class WeekplanDayColumn extends StatelessWidget { } /// Sets all activites to Normal state - void resetActiveMarks(WeekdayModel weekdayModel){ - for (ActivityModel activity in weekdayModel.activities){ - if(activity.state == ActivityState.Active){ + void resetActiveMarks(WeekdayModel weekdayModel) { + for (ActivityModel activity in weekdayModel.activities) { + if (activity.state == ActivityState.Active) { activity.state = ActivityState.Normal; } } } /// Builds a day's activities - StreamBuilder> _buildDayActivities( WeekdayModel weekday){ - + StreamBuilder> _buildDayActivities(WeekdayModel weekday) { return StreamBuilder>( stream: weekplanBloc.markedActivities, builder: (BuildContext context, @@ -274,11 +268,10 @@ class WeekplanDayColumn extends StatelessWidget { stream: weekplanBloc.editMode, builder: (BuildContext context, AsyncSnapshot editModeSnapshot) { - return StreamBuilder( - stream: _settingsBloc.settings, - builder: (BuildContext context, - AsyncSnapshot settingsSnapshot) - { + return StreamBuilder( + stream: _settingsBloc.settings, + builder: (BuildContext context, + AsyncSnapshot settingsSnapshot) { return Expanded( child: ListView.builder( itemBuilder: (BuildContext context, int index) { @@ -286,8 +279,8 @@ class WeekplanDayColumn extends StatelessWidget { markCurrent(weekday); if (index >= weekday.activities.length) { return StreamBuilder( - stream: weekplanBloc - .activityPlaceholderVisible, + stream: + weekplanBloc.activityPlaceholderVisible, initialData: false, builder: (BuildContext context, AsyncSnapshot snapshot) { @@ -298,8 +291,7 @@ class WeekplanDayColumn extends StatelessWidget { index, weekday), ); }); - } - else { + } else { return StreamBuilder( stream: _authBloc.mode, initialData: WeekplanMode.guardian, @@ -308,13 +300,14 @@ class WeekplanDayColumn extends StatelessWidget { if (snapshot.data == WeekplanMode.guardian) { return _dragTargetPictogram( - index, weekday, - editModeSnapshot.data, context); + index, + weekday, + editModeSnapshot.data, + context); } return _pictogramIconStack(context, index, weekday, editModeSnapshot.data); - } - ); + }); } }, itemCount: weekday.activities.length + 1, @@ -354,7 +347,6 @@ class WeekplanDayColumn extends StatelessWidget { // Returns the draggable pictograms, which also function as drop targets. DragTarget> _dragTargetPictogram( int index, WeekdayModel weekday, bool inEditMode, BuildContext context) { - return DragTarget>( key: const Key('DragTarget'), builder: (BuildContext context, @@ -388,9 +380,9 @@ class WeekplanDayColumn extends StatelessWidget { return true; }, onAccept: (Tuple2 data) { - weekplanBloc.reorderActivities( - data.item1, data.item2, weekday.day, index) - .catchError((Object error){ + weekplanBloc + .reorderActivities(data.item1, data.item2, weekday.day, index) + .catchError((Object error) { creatingNotifyDialog(error, context); }); }, @@ -402,7 +394,6 @@ class WeekplanDayColumn extends StatelessWidget { BuildContext context, int index, WeekdayModel weekday, bool inEditMode) { final ActivityModel currActivity = weekday.activities[index]; - final bool isMarked = weekplanBloc.isActivityMarked(currActivity); return FittedBox( @@ -427,10 +418,10 @@ class WeekplanDayColumn extends StatelessWidget { key: Key(weekday.day.index.toString() + currActivity.id.toString()), onTap: () { - if (modeSnapshot.data == WeekplanMode.guardian - || - modeSnapshot.data == WeekplanMode.trustee) - { + if (modeSnapshot.data == + WeekplanMode.guardian || + modeSnapshot.data == + WeekplanMode.trustee) { _handleOnTapActivity( inEditMode, isMarked, @@ -469,25 +460,23 @@ class WeekplanDayColumn extends StatelessWidget { ), ); } + void _handleActivity( - List activities, - int index, - WeekdayModel weekday) { + List activities, int index, WeekdayModel weekday) { final ActivityModel activistModel = activities[index]; - if(activistModel.state == ActivityState.Completed || - (activistModel.timer != null && - activistModel.timer.paused == false)) { - return; + if (activistModel.state == ActivityState.Completed || + (activistModel.timer != null && activistModel.timer.paused == false)) { + return; } _activityBloc.load(activistModel, user); _activityBloc.accesWeekPlanBloc(weekplanBloc, weekday); - _timerBloc[index].load(activistModel,user: user); + _timerBloc[index].load(activistModel, user: user); _timerBloc[index].setActivityBloc(_activityBloc); _activityBloc.addHandlerToActivityStateOnce(); _timerBloc[index].addHandlerToRunningModeOnce(); _timerBloc[index].initTimer(); - if (activistModel.timer == null) { + if (activistModel.timer == null || activistModel.chosenActivity != null) { _activityBloc.completeActivity(); } else { _timerBloc[index].playTimer(); @@ -521,17 +510,16 @@ class WeekplanDayColumn extends StatelessWidget { activities[index], _activityBloc, user); }); } else if (isCitizen) { - _handleActivity(activities,index,weekday); - } - else if(!inEditMode){ - - Routes().push(context, ShowActivityScreen(activities[index], - user, weekplanBloc,_timerBloc[index], weekday)) - - - .whenComplete(() {weekplanBloc.getWeekday(weekday.day) - .catchError((Object error) { - creatingNotifyDialog(error, context); + _handleActivity(activities, index, weekday); + } else if (!inEditMode) { + Routes() + .push( + context, + ShowActivityScreen(activities[index], user, weekplanBloc, + _timerBloc[index], weekday)) + .whenComplete(() { + weekplanBloc.getWeekday(weekday.day).catchError((Object error) { + creatingNotifyDialog(error, context); }); }); } @@ -540,10 +528,8 @@ class WeekplanDayColumn extends StatelessWidget { /// Builds activity card with a status icon if it is marked StatelessWidget _buildIsMarked(bool isMarked, BuildContext context, WeekdayModel weekday, List activities, int index) { - if(index >= activities.length){ - return Container( - child: const CircularProgressIndicator() - ); + if (index >= activities.length) { + return Container(child: const CircularProgressIndicator()); } if (isMarked) { return Container( @@ -564,7 +550,8 @@ class WeekplanDayColumn extends StatelessWidget { backgroundColor: theme.GirafColors.buttonColor, ); - Container _buildAddActivityButton(WeekdayModel weekday, BuildContext context){ + Container _buildAddActivityButton( + WeekdayModel weekday, BuildContext context) { return Container( padding: EdgeInsets.symmetric( horizontal: @@ -581,11 +568,16 @@ class WeekplanDayColumn extends StatelessWidget { return Visibility( visible: snapshot.data == WeekplanMode.guardian, child: ElevatedButton( - style: addActivityStyle, + style: addActivityStyle, key: const Key('AddActivityButton'), child: Image.asset('assets/icons/add.png'), onPressed: () async { - Routes().push(context, PictogramSearch(user: user,)) + Routes() + .push( + context, + PictogramSearch( + user: user, + )) .then((Object object) { if (object is PictogramModel) { final PictogramModel newPictogram = object; @@ -615,12 +607,11 @@ class WeekplanDayColumn extends StatelessWidget { /// Show the new NotifyDialog String message = ''; Key key; - if(error is ApiException){ + if (error is ApiException) { message = error.errorMessage; // ignore: avoid_as key = error.errorKey as Key; - } - else{ + } else { message = error.toString(); key = const Key('UnknownError'); } diff --git a/lib/widgets/weekplanner_choiceboard_selector.dart b/lib/widgets/weekplanner_choiceboard_selector.dart index 165bb4b2c..18927d576 100644 --- a/lib/widgets/weekplanner_choiceboard_selector.dart +++ b/lib/widgets/weekplanner_choiceboard_selector.dart @@ -17,8 +17,8 @@ import 'giraf_confirm_dialog.dart'; ///This is a class class WeekplannerChoiceboardSelector extends StatelessWidget { ///Constructor - WeekplannerChoiceboardSelector(this._activity, this._activityBloc, - this._user) { + WeekplannerChoiceboardSelector( + this._activity, this._activityBloc, this._user) { _activityBloc.load(_activity, _user); _settingsBloc.loadSettings(_user); } @@ -117,79 +117,89 @@ class WeekplannerChoiceboardSelector extends StatelessWidget { Widget _displayPictogram( BuildContext context, List pictograms, int index) { - return StreamBuilder( - stream: _settingsBloc.settings, - builder: (BuildContext context, - AsyncSnapshot settingSnapshot) { - return SizedBox( - height: MediaQuery.of(context).size.height * 0.2, - width: MediaQuery.of(context).size.height * 0.2, - child: FittedBox( - child: GestureDetector( - onTap: () { - if(settingSnapshot.data.showPopup) { - _selectPictogramFromChoiceBoardPopup(context, - pictograms, index) - .then((_) { - Routes().pop(context); - }); - } - else{ - _selectPictogramFromChoiceboard(context, index); - } - }, - child: Container( - constraints: const BoxConstraints( - maxWidth: double.infinity, - maxHeight: double.infinity, - ), - decoration: BoxDecoration( - border: Border.all( - color: theme.GirafColors.blueBorderColor, width: 1)), - child: pictograms[index], - )), - ), - ); - } - ); + return StreamBuilder( + stream: _settingsBloc.settings, + builder: (BuildContext context, + AsyncSnapshot settingSnapshot) { + return SizedBox( + height: MediaQuery.of(context).size.height * 0.2, + width: MediaQuery.of(context).size.height * 0.2, + child: FittedBox( + child: GestureDetector( + onTap: () { + if (settingSnapshot.data.showPopup) { + _selectPictogramFromChoiceBoardPopup( + context, pictograms, index) + .then((_) { + Routes().pop(context); + }); + } else { + _selectPictogramFromChoiceboard(context, index); + } + }, + child: Container( + constraints: const BoxConstraints( + maxWidth: double.infinity, + maxHeight: double.infinity, + ), + decoration: BoxDecoration( + border: Border.all( + color: theme.GirafColors.blueBorderColor, + width: 1)), + child: pictograms[index], + )), + ), + ); + }); } //Shows a popup when selecting a pictogram on a choiceboard Future
_selectPictogramFromChoiceBoardPopup( BuildContext context, List pictograms, int index) { - return showDialog
( - barrierDismissible: false, - context: context, - builder: (BuildContext context) { - return GirafConfirmDialog( - key: const Key('PictogramSelectorConfirmDialog'), - title: 'Vælg aktivitet', - description: 'Vil du vælge aktiviteten ' + - _activity.pictograms[index].title, - confirmButtonText: 'Ja', - confirmButtonIcon: - const ImageIcon(AssetImage('assets/icons/accept.png')), - confirmOnPressed: () { - _selectPictogramFromChoiceboard(context, index); - }, - cancelOnPressed: () {}); - }); - } + return showDialog
( + barrierDismissible: false, + context: context, + builder: (BuildContext context) { + return GirafConfirmDialog( + key: const Key('PictogramSelectorConfirmDialog'), + title: 'Vælg aktivitet', + description: 'Vil du vælge aktiviteten ' + + _activity.pictograms[index].title, + confirmButtonText: 'Ja', + confirmButtonIcon: + const ImageIcon(AssetImage('assets/icons/accept.png')), + confirmOnPressed: () { + _selectPictogramFromChoiceboard(context, index); + }, + cancelOnPressed: () {}); + }); + } - //Changes activity type so it is not a choiceboard, and only keeps the - //selected pictogram in the activity - void _selectPictogramFromChoiceboard(BuildContext context, int index){ - _activity.isChoiceBoard = false; - final List _pictogramModels = < - PictogramModel>[ - _activity.pictograms[index] - ]; - _activity.pictograms = _pictogramModels; - - _activityBloc.update(); - _activityBloc.activityModelStream.skip(1).take(1).listen((_) { - Routes().pop(context); - }); - //Closes the dialog box - } + //Changes activity type so it is not a choiceboard, and only keeps the + //selected pictogram in the activity + void _selectPictogramFromChoiceboard(BuildContext context, int index) { + // if (!_activity.pictograms + // .any((PictogramModel element) => element.isCompleted == false)) { + // _activity.state = ActivityState.Completed; + // } + // if (_activity.pictograms.length == 1) { + // _activity.isChoiceBoard = false; + // } else { + // _activity.pictograms.removeAt(index); + // } + + // final List _pictogramModels = [ + // _activity.pictograms[index] + // ]; + // _activity.pictograms = _pictogramModels; + _activity.chosenActivity = index; + _activityBloc.load(_activity, _user); + _activityBloc.completeActivity(); + + _activityBloc.update(); + _activityBloc.activityModelStream.skip(1).take(1).listen((_) { + Routes().pop(context); + }); + //Closes the dialog box + } } diff --git a/test/screens/weekplan_screen_test.dart b/test/screens/weekplan_screen_test.dart index 5c729fde0..0b52d85a2 100644 --- a/test/screens/weekplan_screen_test.dart +++ b/test/screens/weekplan_screen_test.dart @@ -73,7 +73,7 @@ void main() { mockPictograms = mockData.mockPictograms; user = mockData.mockUser; api = mockData.mockApi; - api.pictogram=MockPictogramApi(); + api.pictogram = MockPictogramApi(); authBloc = AuthBloc(api); authBloc.setMode(WeekplanMode.guardian); weekplanBloc = WeekplanBloc(api); @@ -111,23 +111,21 @@ void main() { }); testWidgets('Activity selector pops up when choiceBoard activity is tapped', - (WidgetTester tester) async { - authBloc.setMode(WeekplanMode.citizen); - mockActivities[0].state = ActivityState.Normal; - mockActivities[0].isChoiceBoard = true; - mockActivities[0].pictograms = mockPictograms; - mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - - await tester.tap(find.byKey(const Key('WeekPlanScreenChoiceBoard'))); - await tester.pumpAndSettle(); - - expect( - find.byKey(const Key('ChoiceBoardActivitySelector')), - findsOneWidget); - }); + (WidgetTester tester) async { + authBloc.setMode(WeekplanMode.citizen); + mockActivities[0].state = ActivityState.Normal; + mockActivities[0].isChoiceBoard = true; + mockActivities[0].pictograms = mockPictograms; + mockWeek.days[0].activities.add(mockActivities[0]); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key('WeekPlanScreenChoiceBoard'))); + await tester.pumpAndSettle(); + + expect( + find.byKey(const Key('ChoiceBoardActivitySelector')), findsOneWidget); + }); testWidgets('Has Giraf App Bar', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); @@ -142,328 +140,315 @@ void main() { }); testWidgets('Click on edit icon toggles edit mode', - (WidgetTester tester) async { - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - - bool currentEditMode = false; - weekplanBloc.editMode.listen((bool editMode) { - currentEditMode = editMode; - }); - // Initial edit mode should be false - expect(currentEditMode, false); - - await tester.tap(find.byTooltip('Rediger')); - await tester.pump(); - - weekplanBloc.editMode.listen((bool editMode) { - currentEditMode = editMode; - }); - // After tapping the button edit mode should be true - expect(currentEditMode, true); - - await tester.tap(find.byTooltip('Rediger')); - await tester.pump(); - weekplanBloc.editMode.listen((bool editMode) { - currentEditMode = editMode; - }); - // After tapping the button agian it should be false - expect(currentEditMode, false); - }); + (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + bool currentEditMode = false; + weekplanBloc.editMode.listen((bool editMode) { + currentEditMode = editMode; + }); + // Initial edit mode should be false + expect(currentEditMode, false); + + await tester.tap(find.byTooltip('Rediger')); + await tester.pump(); + + weekplanBloc.editMode.listen((bool editMode) { + currentEditMode = editMode; + }); + // After tapping the button edit mode should be true + expect(currentEditMode, true); + + await tester.tap(find.byTooltip('Rediger')); + await tester.pump(); + weekplanBloc.editMode.listen((bool editMode) { + currentEditMode = editMode; + }); + // After tapping the button agian it should be false + expect(currentEditMode, false); + }); testWidgets('No activity cards when no activities are added', - (WidgetTester tester) async { - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - // After tapping the button edit mode should be true - expect(find.byType(ActivityCard), findsNothing); - }); + (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + // After tapping the button edit mode should be true + expect(find.byType(ActivityCard), findsNothing); + }); testWidgets('Each added activity gets an activity card', - (WidgetTester tester) async { - // We add an activity to monday and one to tuesday - mockWeek.days[0].activities.add(mockActivities[0]); - mockWeek.days[1].activities.add(mockActivities[1]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - - // After tapping the button edit mode should be true - expect(find.byType(ActivityCard), findsNWidgets(2)); - }); + (WidgetTester tester) async { + // We add an activity to monday and one to tuesday + mockWeek.days[0].activities.add(mockActivities[0]); + mockWeek.days[1].activities.add(mockActivities[1]); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + // After tapping the button edit mode should be true + expect(find.byType(ActivityCard), findsNWidgets(2)); + }); testWidgets('Tapping activity when not in edit mode pushes activity screen', - (WidgetTester tester) async { - mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - - await tester.tap(find.byType(ActivityCard)); - await tester.pumpAndSettle(); - expect(find.byType(ShowActivityScreen), findsOneWidget); - }); + (WidgetTester tester) async { + mockWeek.days[0].activities.add(mockActivities[0]); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + await tester.tap(find.byType(ActivityCard)); + await tester.pumpAndSettle(); + expect(find.byType(ShowActivityScreen), findsOneWidget); + }); testWidgets('Tapping activity in edit mode selects/deselects it', - (WidgetTester tester) async { - mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); + (WidgetTester tester) async { + mockWeek.days[0].activities.add(mockActivities[0]); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); - //We enter edit mode. - await tester.tap(find.byTooltip('Rediger')); - await tester.pump(); + //We enter edit mode. + await tester.tap(find.byTooltip('Rediger')); + await tester.pump(); - expect(weekplanBloc.getNumberOfMarkedActivities(), 0); + expect(weekplanBloc.getNumberOfMarkedActivities(), 0); - await tester.tap(find.byType(ActivityCard)); - await tester.pumpAndSettle(); - expect(weekplanBloc.getNumberOfMarkedActivities(), 1); + await tester.tap(find.byType(ActivityCard)); + await tester.pumpAndSettle(); + expect(weekplanBloc.getNumberOfMarkedActivities(), 1); - await tester.tap(find.byType(ActivityCard)); - await tester.pumpAndSettle(); - expect(weekplanBloc.getNumberOfMarkedActivities(), 0); - }); + await tester.tap(find.byType(ActivityCard)); + await tester.pumpAndSettle(); + expect(weekplanBloc.getNumberOfMarkedActivities(), 0); + }); testWidgets('Marking activity in edit mode renders a black box around it', - (WidgetTester tester) async { - mockWeek.days[0].activities.add(mockActivities[0]); + (WidgetTester tester) async { + mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); - await tester.tap(find.byTooltip('Rediger')); - await tester.pumpAndSettle(); + await tester.tap(find.byTooltip('Rediger')); + await tester.pumpAndSettle(); - await tester.tap(find.byType(ActivityCard)); - await tester.pumpAndSettle(); + await tester.tap(find.byType(ActivityCard)); + await tester.pumpAndSettle(); - expect(find.byKey(const Key('isSelectedKey')), findsOneWidget); - }); + expect(find.byKey(const Key('isSelectedKey')), findsOneWidget); + }); testWidgets( 'Cancel/Copy/Delete/Undo buttons not built when edit mode is false', - (WidgetTester tester) async { - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); + (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Aflys' && - widget.buttonKey == 'CancelActivtiesButton'), - findsNothing); + widget.buttonText == 'Aflys' && + widget.buttonKey == 'CancelActivtiesButton'), + findsNothing); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Kopier' && - widget.buttonKey == 'CopyActivtiesButton'), - findsNothing); + widget.buttonText == 'Kopier' && + widget.buttonKey == 'CopyActivtiesButton'), + findsNothing); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Slet' && - widget.buttonKey == 'DeleteActivtiesButton'), - findsNothing); + widget.buttonText == 'Slet' && + widget.buttonKey == 'DeleteActivtiesButton'), + findsNothing); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Genoptag' && - widget.buttonKey == 'GenoptagActivtiesButton'), - findsNothing); - }); + widget.buttonText == 'Genoptag' && + widget.buttonKey == 'GenoptagActivtiesButton'), + findsNothing); + }); testWidgets( 'Cancel/Copy/Delete/Undo buttons are built when edit mode is true', - (WidgetTester tester) async { - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); + (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); - // Toggle edit mode by pressing the edit mode button - await tester.tap(find.byTooltip('Rediger')); - await tester.pump(); + // Toggle edit mode by pressing the edit mode button + await tester.tap(find.byTooltip('Rediger')); + await tester.pump(); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Aflys' && - widget.buttonKey == 'CancelActivtiesButton'), - findsOneWidget); + widget.buttonText == 'Aflys' && + widget.buttonKey == 'CancelActivtiesButton'), + findsOneWidget); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Kopier' && - widget.buttonKey == 'CopyActivtiesButton'), - findsOneWidget); + widget.buttonText == 'Kopier' && + widget.buttonKey == 'CopyActivtiesButton'), + findsOneWidget); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Slet' && - widget.buttonKey == 'DeleteActivtiesButton'), - findsOneWidget); + widget.buttonText == 'Slet' && + widget.buttonKey == 'DeleteActivtiesButton'), + findsOneWidget); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Genoptag' && - widget.buttonKey == 'GenoptagActivtiesButton'), - findsOneWidget); - }); + widget.buttonText == 'Genoptag' && + widget.buttonKey == 'GenoptagActivtiesButton'), + findsOneWidget); + }); testWidgets( 'Cancel/Copy/Delete/Undo buttons do not open dialog when no activites are selected', - (WidgetTester tester) async { - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); + (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); - await tester.tap(find.byTooltip('Rediger')); - await tester.pump(); + await tester.tap(find.byTooltip('Rediger')); + await tester.pump(); - await tester.tap(find.byWidgetPredicate((Widget widget) => + await tester.tap(find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Aflys' && - widget.buttonKey == 'CancelActivtiesButton')); - await tester.pumpAndSettle(); + widget.buttonText == 'Aflys' && + widget.buttonKey == 'CancelActivtiesButton')); + await tester.pumpAndSettle(); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is GirafConfirmDialog && - widget.title == 'Aflys aktiviteter'), - findsNothing); + widget.title == 'Aflys aktiviteter'), + findsNothing); - await tester.tap(find.byWidgetPredicate((Widget widget) => + await tester.tap(find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Kopier' && - widget.buttonKey == 'CopyActivtiesButton')); - await tester.pumpAndSettle(); + widget.buttonText == 'Kopier' && + widget.buttonKey == 'CopyActivtiesButton')); + await tester.pumpAndSettle(); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is GirafCopyActivitiesDialog && - widget.title == 'Kopier aktiviteter'), - findsNothing); + widget.title == 'Kopier aktiviteter'), + findsNothing); - await tester.tap(find.byWidgetPredicate((Widget widget) => + await tester.tap(find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Slet' && - widget.buttonKey == 'DeleteActivtiesButton')); - await tester.pumpAndSettle(); + widget.buttonText == 'Slet' && + widget.buttonKey == 'DeleteActivtiesButton')); + await tester.pumpAndSettle(); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is GirafConfirmDialog && widget.title == 'Slet aktiviteter'), - findsNothing); + findsNothing); - await tester.tap(find.byWidgetPredicate((Widget widget) => + await tester.tap(find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Genoptag' && - widget.buttonKey == 'GenoptagActivtiesButton')); - await tester.pumpAndSettle(); + widget.buttonText == 'Genoptag' && + widget.buttonKey == 'GenoptagActivtiesButton')); + await tester.pumpAndSettle(); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is GirafConfirmDialog && widget.title == 'Genoptag'), - findsNothing - ); - }); + findsNothing); + }); testWidgets('Cancel activity button opens dialog when activity is selected', - (WidgetTester tester) async { - mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - - // Toggle edit mode by pressing the edit mode button - await tester.tap(find.byTooltip('Rediger')); - await tester.pump(); - - // Selecting an activity - await tester.tap(find.byType(ActivityCard)); - await tester.pumpAndSettle(); - - // Tapping cancel activities button - await tester.tap(find.byWidgetPredicate((Widget widget) => + (WidgetTester tester) async { + mockWeek.days[0].activities.add(mockActivities[0]); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + // Toggle edit mode by pressing the edit mode button + await tester.tap(find.byTooltip('Rediger')); + await tester.pump(); + + // Selecting an activity + await tester.tap(find.byType(ActivityCard)); + await tester.pumpAndSettle(); + + // Tapping cancel activities button + await tester.tap(find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Aflys' && - widget.buttonKey == 'CancelActivtiesButton')); - await tester.pumpAndSettle(); + widget.buttonText == 'Aflys' && + widget.buttonKey == 'CancelActivtiesButton')); + await tester.pumpAndSettle(); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is GirafConfirmDialog && - widget.title == 'Aflys aktiviteter'), - findsOneWidget); - }); + widget.title == 'Aflys aktiviteter'), + findsOneWidget); + }); testWidgets('Copy activity button opens dialog when activity is selected', - (WidgetTester tester) async { - mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - - // Toggle edit mode by pressing the edit mode button - await tester.tap(find.byTooltip('Rediger')); - await tester.pump(); - - // Selecting an activity - await tester.tap(find.byType(ActivityCard)); - await tester.pumpAndSettle(); - - // Tapping copy activities button - await tester.tap(find.byWidgetPredicate((Widget widget) => + (WidgetTester tester) async { + mockWeek.days[0].activities.add(mockActivities[0]); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + // Toggle edit mode by pressing the edit mode button + await tester.tap(find.byTooltip('Rediger')); + await tester.pump(); + + // Selecting an activity + await tester.tap(find.byType(ActivityCard)); + await tester.pumpAndSettle(); + + // Tapping copy activities button + await tester.tap(find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Kopier' && - widget.buttonKey == 'CopyActivtiesButton')); - await tester.pumpAndSettle(); + widget.buttonText == 'Kopier' && + widget.buttonKey == 'CopyActivtiesButton')); + await tester.pumpAndSettle(); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is GirafCopyActivitiesDialog && - widget.title == 'Kopier aktiviteter'), - findsOneWidget); - }); + widget.title == 'Kopier aktiviteter'), + findsOneWidget); + }); testWidgets('Delete activity button opens dialog when activity is selected', - (WidgetTester tester) async { - mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - - // Toggle edit mode by pressing the edit mode button - await tester.tap(find.byTooltip('Rediger')); - await tester.pump(); - - // Selecting an activity - await tester.tap(find.byType(ActivityCard)); - await tester.pumpAndSettle(); - - // Tapping copy activities button - await tester.tap(find.byWidgetPredicate((Widget widget) => + (WidgetTester tester) async { + mockWeek.days[0].activities.add(mockActivities[0]); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + // Toggle edit mode by pressing the edit mode button + await tester.tap(find.byTooltip('Rediger')); + await tester.pump(); + + // Selecting an activity + await tester.tap(find.byType(ActivityCard)); + await tester.pumpAndSettle(); + + // Tapping copy activities button + await tester.tap(find.byWidgetPredicate((Widget widget) => widget is BottomAppBarButton && - widget.buttonText == 'Slet' && - widget.buttonKey == 'DeleteActivtiesButton')); - await tester.pumpAndSettle(); + widget.buttonText == 'Slet' && + widget.buttonKey == 'DeleteActivtiesButton')); + await tester.pumpAndSettle(); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is GirafConfirmDialog && widget.title == 'Slet aktiviteter'), - findsOneWidget); - }); + findsOneWidget); + }); testWidgets('Canceling an activity works', (WidgetTester tester) async { mockWeek.days[0].activities.add(mockActivities[0]); @@ -477,7 +462,7 @@ void main() { await tester.pumpAndSettle(); await tester.tap(find.byWidgetPredicate((Widget widget) => - widget is BottomAppBarButton && + widget is BottomAppBarButton && widget is BottomAppBarButton && widget.buttonText == 'Aflys' && widget.buttonKey == 'CancelActivtiesButton')); @@ -492,9 +477,9 @@ void main() { }); testWidgets('Marking an activity as current and updating work', - (WidgetTester tester) async { + (WidgetTester tester) async { mockSettings.nrOfDaysToDisplayLandscape = 1; - final int weekDay = DateTime.now().weekday.toInt()-1; + final int weekDay = DateTime.now().weekday.toInt() - 1; mockWeek.days[weekDay].activities.add(mockActivities[0]); mockWeek.days[weekDay].activities.add(mockActivities[1]); await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); @@ -509,7 +494,7 @@ void main() { await tester.pumpAndSettle(); await tester.tap(find.byWidgetPredicate((Widget widget) => - widget is BottomAppBarButton && + widget is BottomAppBarButton && widget is BottomAppBarButton && widget.buttonText == 'Aflys' && widget.buttonKey == 'CancelActivtiesButton')); @@ -531,7 +516,7 @@ void main() { await tester.pumpAndSettle(); await tester.tap(find.byWidgetPredicate((Widget widget) => - widget is BottomAppBarButton && + widget is BottomAppBarButton && widget is BottomAppBarButton && widget.buttonText == 'Genoptag' && widget.buttonKey == 'GenoptagActivtiesButton')); @@ -562,7 +547,7 @@ void main() { await tester.pumpAndSettle(); await tester.tap(find.byWidgetPredicate((Widget widget) => - widget is BottomAppBarButton && + widget is BottomAppBarButton && widget is BottomAppBarButton && widget.buttonText == 'Genoptag' && widget.buttonKey == 'GenoptagActivtiesButton')); @@ -576,7 +561,6 @@ void main() { }); testWidgets('Copying an activity works', (WidgetTester tester) async { - mockWeek.days[0].activities.add(mockActivities[0]); await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); await tester.pumpAndSettle(); @@ -594,7 +578,7 @@ void main() { // Tapping copy activities button await tester.tap(find.byWidgetPredicate((Widget widget) => - widget is BottomAppBarButton && + widget is BottomAppBarButton && widget.buttonText == 'Kopier' && widget.buttonKey == 'CopyActivtiesButton')); await tester.pumpAndSettle(); @@ -626,7 +610,7 @@ void main() { // Tapping copy activities button await tester.tap(find.byWidgetPredicate((Widget widget) => - widget is BottomAppBarButton && + widget is BottomAppBarButton && widget.buttonText == 'Slet' && widget.buttonKey == 'DeleteActivtiesButton')); await tester.pumpAndSettle(); @@ -660,60 +644,59 @@ void main() { }); testWidgets('Marks all and unmarks all activities for a given day', - (WidgetTester tester) async { - // Adding two activities too monday - mockWeek.days[0].activities.add(mockActivities[0]); - mockWeek.days[0].activities.add(mockActivities[1]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - - await tester.tap(find.byTooltip('Rediger')); - await tester.pump(); - expect(weekplanBloc.getNumberOfMarkedActivities(), 0); - - // Checking that the select all activities button works - await tester.tap(find.byKey(const Key('SelectAllButton')).first); - await tester.pump(); - expect(weekplanBloc.getNumberOfMarkedActivities(), 2); - - // Checking that the Deselect all activities button works - await tester.tap(find.byKey(const Key('DeselectAllButton')).first); - await tester.pump(); - expect(weekplanBloc.getNumberOfMarkedActivities(), 0); - }); + (WidgetTester tester) async { + // Adding two activities too monday + mockWeek.days[0].activities.add(mockActivities[0]); + mockWeek.days[0].activities.add(mockActivities[1]); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + await tester.tap(find.byTooltip('Rediger')); + await tester.pump(); + expect(weekplanBloc.getNumberOfMarkedActivities(), 0); + + // Checking that the select all activities button works + await tester.tap(find.byKey(const Key('SelectAllButton')).first); + await tester.pump(); + expect(weekplanBloc.getNumberOfMarkedActivities(), 2); + + // Checking that the Deselect all activities button works + await tester.tap(find.byKey(const Key('DeselectAllButton')).first); + await tester.pump(); + expect(weekplanBloc.getNumberOfMarkedActivities(), 0); + }); /// All tests test in landscape mode by default. Preferably, we would test /// in portrait mode as well, but we are unsure how to do so - testWidgets('When showing one day in landscape mode for citizen,' - ' one weekday row is created', - (WidgetTester tester) async { + testWidgets( + 'When showing one day in landscape mode for citizen,' + ' one weekday row is created', (WidgetTester tester) async { mockSettings.nrOfDaysToDisplayLandscape = 1; authBloc.setMode(WeekplanMode.citizen); final WeekplanScreen weekplanScreen = WeekplanScreen(mockWeek, user); - await tester.pumpWidget(MaterialApp(home: weekplanScreen)); - await tester.pumpAndSettle(); + await tester.pumpWidget(MaterialApp(home: weekplanScreen)); + await tester.pumpAndSettle(); - expect(find.byKey(const Key('SingleWeekdayRow')), findsOneWidget); - }); + expect(find.byKey(const Key('SingleWeekdayRow')), findsOneWidget); + }); - testWidgets('When showing 5 days in landscape mode for citizen, ' - '5 weekday columns are created', - (WidgetTester tester) async { + testWidgets( + 'When showing 5 days in landscape mode for citizen, ' + '5 weekday columns are created', (WidgetTester tester) async { mockSettings.nrOfDaysToDisplayLandscape = 5; authBloc.setMode(WeekplanMode.citizen); final WeekplanScreen weekplanScreen = WeekplanScreen(mockWeek, user); - await tester.pumpWidget(MaterialApp(home: weekplanScreen)); - await tester.pumpAndSettle(); - expect(find.byKey(const Key('SingleWeekdayRow')), findsNothing); - expect(find.byType(WeekplanDayColumn), findsNWidgets(5)); - }); + await tester.pumpWidget(MaterialApp(home: weekplanScreen)); + await tester.pumpAndSettle(); + expect(find.byKey(const Key('SingleWeekdayRow')), findsNothing); + expect(find.byType(WeekplanDayColumn), findsNWidgets(5)); + }); - testWidgets('When showing 7 days in landscape mode for citizen, ' - '7 weekday columns are created', - (WidgetTester tester) async { + testWidgets( + 'When showing 7 days in landscape mode for citizen, ' + '7 weekday columns are created', (WidgetTester tester) async { mockSettings.nrOfDaysToDisplayLandscape = 7; authBloc.setMode(WeekplanMode.citizen); final WeekplanScreen weekplanScreen = WeekplanScreen(mockWeek, user); @@ -724,15 +707,14 @@ void main() { }); testWidgets('7 weekday columns are always created for guardian', - (WidgetTester tester) async { - authBloc.setMode(WeekplanMode.guardian); - final WeekplanScreen weekplanScreen = WeekplanScreen(mockWeek, user); - await tester.pumpWidget(MaterialApp(home: weekplanScreen)); - await tester.pumpAndSettle(); - expect(find.byKey(const Key('SingleWeekdayRow')), findsNothing); - expect(find.byType(WeekplanDayColumn), findsNWidgets(7)); - }); - + (WidgetTester tester) async { + authBloc.setMode(WeekplanMode.guardian); + final WeekplanScreen weekplanScreen = WeekplanScreen(mockWeek, user); + await tester.pumpWidget(MaterialApp(home: weekplanScreen)); + await tester.pumpAndSettle(); + expect(find.byKey(const Key('SingleWeekdayRow')), findsNothing); + expect(find.byType(WeekplanDayColumn), findsNWidgets(7)); + }); testWidgets( 'Week day colors should be in correct order regardless of order in DB', @@ -769,7 +751,7 @@ void main() { testWidgets( 'Pictogram text renders when settings are set to display ' - 'pictogram text', (WidgetTester tester) async { + 'pictogram text', (WidgetTester tester) async { // Enable the setting that displays pictogram text mockSettings.pictogramText = true; @@ -796,13 +778,13 @@ void main() { await tester.pumpAndSettle(); await tester.tap(find.byWidgetPredicate((Widget widget) => - widget is IconButton && widget.tooltip == 'Skift til borger tilstand')); + widget is IconButton && widget.tooltip == 'Skift til borger tilstand')); await tester.pumpAndSettle(); expect(find.byType(GirafConfirmDialog), findsOneWidget); await tester.tap(find.byWidgetPredicate((Widget widget) => - widget is GirafButton && + widget is GirafButton && widget.key == const Key('ConfirmDialogConfirmButton'))); await tester.pumpAndSettle(); @@ -818,17 +800,17 @@ void main() { expect( find.byWidgetPredicate((Widget widget) => - widget is IconButton && + widget is IconButton && widget.tooltip == 'Skift til værge tilstand'), findsOneWidget); await tester.tap(find.byWidgetPredicate((Widget widget) => - widget is IconButton && widget.tooltip == 'Skift til værge tilstand')); + widget is IconButton && widget.tooltip == 'Skift til værge tilstand')); await tester.pumpAndSettle(); expect( find.byWidgetPredicate((Widget widget) => - widget is DialogButton && + widget is DialogButton && widget.key == const Key('SwitchToGuardianSubmit')), findsOneWidget); @@ -840,9 +822,8 @@ void main() { }); testWidgets('Add Activity buttons work', (WidgetTester tester) async { - when(api.pictogram.getAll(page: 1, - pageSize: pageSize, query: '')).thenAnswer( - (_) => rx_dart.BehaviorSubject>.seeded( + when(api.pictogram.getAll(page: 1, pageSize: pageSize, query: '')) + .thenAnswer((_) => rx_dart.BehaviorSubject>.seeded( [mockPictograms[0]])); mockSettings.nrOfDaysToDisplayLandscape = 7; await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); @@ -855,151 +836,138 @@ void main() { expect(find.byType(PictogramSearch), findsOneWidget); await tester.pump(const Duration(milliseconds: 11000)); - }); testWidgets('Completed activities displayed correctly in Guardian Mode', - (WidgetTester tester) async { - mockActivities[0].state = ActivityState.Completed; + (WidgetTester tester) async { + mockActivities[0].state = ActivityState.Completed; - // Added the activity that is completed with checkmark - mockWeek.days[0].activities.add(mockActivities[0]); + // Added the activity that is completed with checkmark + mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); - // Find checkmark icon by key - expect(find.byKey(const Key('IconComplete')), findsOneWidget); - }); + // Find checkmark icon by key + expect(find.byKey(const Key('IconComplete')), findsOneWidget); + }); testWidgets('Cancelled activities displayed correctly in Guardian Mode', - (WidgetTester tester) async { - mockActivities[0].state = ActivityState.Canceled; + (WidgetTester tester) async { + mockActivities[0].state = ActivityState.Canceled; - // Added Cancelled activity with a cross - mockWeek.days[0].activities.add(mockActivities[0]); + // Added Cancelled activity with a cross + mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); - // Find cross (cancelled) icon by key - expect(find.byKey(const Key('IconCanceled')), findsOneWidget); - }); + // Find cross (cancelled) icon by key + expect(find.byKey(const Key('IconCanceled')), findsOneWidget); + }); testWidgets('Timer icon displayed correctly in Guardian Mode', - (WidgetTester tester) async { - // Activity with a timer - mockWeek.days[0].activities.add(mockActivities[2]); + (WidgetTester tester) async { + // Activity with a timer + mockWeek.days[0].activities.add(mockActivities[2]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); - // Find timer icon - expect( - find.byWidgetPredicate((Widget widget) => + // Find timer icon + expect( + find.byWidgetPredicate((Widget widget) => widget is Image && - widget.image == const AssetImage('assets/timer/piechart_icon.png')), - findsOneWidget); - }); + widget.image == const AssetImage('assets/timer/piechart_icon.png')), + findsOneWidget); + }); testWidgets('Check mark completed activity mode works in Citizen Mode', - (WidgetTester tester) async { - authBloc.setMode(WeekplanMode.citizen); - mockSettings.completeMark = CompleteMark.Checkmark; - mockActivities[0].state = ActivityState.Completed; - // Added the activity that is completed with checkmark - mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - - // Find checkmark icon by key - expect(find.byKey(const Key('IconComplete')), findsOneWidget); - }); + (WidgetTester tester) async { + authBloc.setMode(WeekplanMode.citizen); + mockSettings.completeMark = CompleteMark.Checkmark; + mockActivities[0].state = ActivityState.Completed; + // Added the activity that is completed with checkmark + mockWeek.days[0].activities.add(mockActivities[0]); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + // Find checkmark icon by key + expect(find.byKey(const Key('IconComplete')), findsOneWidget); + }); testWidgets('Greyed out completed activity mode works in Citizen Mode', - (WidgetTester tester) async { - authBloc.setMode(WeekplanMode.citizen); - mockSettings.completeMark = CompleteMark.MovedRight; - mockActivities[0].state = ActivityState.Completed; - // Added the activity that is completed with checkmark - mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - - // Find greyed out box by key - expect( - find.byWidgetPredicate((Widget widget) => + (WidgetTester tester) async { + authBloc.setMode(WeekplanMode.citizen); + mockSettings.completeMark = CompleteMark.MovedRight; + mockActivities[0].state = ActivityState.Completed; + // Added the activity that is completed with checkmark + mockWeek.days[0].activities.add(mockActivities[0]); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + // Find greyed out box by key + expect( + find.byWidgetPredicate((Widget widget) => widget is Container && widget.key == const Key('GreyOutBox')), - findsOneWidget); - }); + findsOneWidget); + }); testWidgets('Remove completed activity mode works in Citizen Mode', - (WidgetTester tester) async { - authBloc.setMode(WeekplanMode.citizen); - mockSettings.completeMark = CompleteMark.Removed; - mockActivities[0].state = ActivityState.Completed; - // Added the activity that is completed with checkmark - mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - - // Check that the opacity of the activity card is set to zero. - expect( - find.byWidgetPredicate( - (Widget widget) => widget is - Opacity && widget.opacity == 0.0), - findsOneWidget); - }); + (WidgetTester tester) async { + authBloc.setMode(WeekplanMode.citizen); + mockSettings.completeMark = CompleteMark.Removed; + mockActivities[0].state = ActivityState.Completed; + // Added the activity that is completed with checkmark + mockWeek.days[0].activities.add(mockActivities[0]); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + // Check that the opacity of the activity card is set to zero. + expect( + find.byWidgetPredicate( + (Widget widget) => widget is Opacity && widget.opacity == 0.0), + findsOneWidget); + }); testWidgets('Not completed activities are not hidden', - (WidgetTester tester) async { - authBloc.setMode(WeekplanMode.citizen); - mockSettings.completeMark = CompleteMark.Removed; - mockActivities[0].state = ActivityState.Normal; - // Added the activity that is completed with checkmark - mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - - // Check that the opacity of the activity card is set to zero. - expect( - find.byWidgetPredicate( - (Widget widget) => widget is - Opacity && widget.opacity == 1.0), - findsOneWidget); - }); + (WidgetTester tester) async { + authBloc.setMode(WeekplanMode.citizen); + mockSettings.completeMark = CompleteMark.Removed; + mockActivities[0].state = ActivityState.Normal; + // Added the activity that is completed with checkmark + mockWeek.days[0].activities.add(mockActivities[0]); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + // Check that the opacity of the activity card is set to zero. + expect( + find.byWidgetPredicate( + (Widget widget) => widget is Opacity && widget.opacity == 1.0), + findsOneWidget); + }); testWidgets('Check mark completed activity mode works in Citizen Mode', - (WidgetTester tester) async { - authBloc.setMode(WeekplanMode.citizen); - mockSettings.completeMark = CompleteMark.Checkmark; - mockActivities[0].state = ActivityState.Completed; - // Added the activity that is completed with checkmark - mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); - - // Find checkmark icon by key - expect(find.byKey(const Key('IconComplete')), findsOneWidget); - }); + (WidgetTester tester) async { + authBloc.setMode(WeekplanMode.citizen); + mockSettings.completeMark = CompleteMark.Checkmark; + mockActivities[0].state = ActivityState.Completed; + // Added the activity that is completed with checkmark + mockWeek.days[0].activities.add(mockActivities[0]); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + // Find checkmark icon by key + expect(find.byKey(const Key('IconComplete')), findsOneWidget); + }); - testWidgets('Tests if the correct number of activities' + testWidgets( + 'Tests if the correct number of activities' ' is displayed', (WidgetTester tester) async { authBloc.setMode(WeekplanMode.citizen); mockSettings.showOnlyActivities = true; mockSettings.nrOfActivitiesToDisplay = 2; - final int weekDay = DateTime - .now() - .weekday - .toInt() - 1; + final int weekDay = DateTime.now().weekday.toInt() - 1; mockWeek.days[weekDay].activities.add(mockActivities[0]); mockWeek.days[weekDay].activities.add(mockActivities[1]); mockWeek.days[weekDay].activities.add(mockActivities[2]); @@ -1011,15 +979,13 @@ void main() { expect(find.byType(ActivityCard), findsNWidgets(2)); }); - testWidgets('Tests if two activities still show up after completing and ' + testWidgets( + 'Tests if two activities still show up after completing and ' 'cancelling first and last activity', (WidgetTester tester) async { authBloc.setMode(WeekplanMode.citizen); mockSettings.showOnlyActivities = true; mockSettings.nrOfActivitiesToDisplay = 2; - final int weekDay = DateTime - .now() - .weekday - .toInt() - 1; + final int weekDay = DateTime.now().weekday.toInt() - 1; mockActivities[0].state = ActivityState.Completed; mockActivities[2].state = ActivityState.Canceled; mockWeek.days[weekDay].activities.add(mockActivities[0]); @@ -1033,15 +999,13 @@ void main() { expect(find.byType(ActivityCard), findsNWidgets(2)); }); - testWidgets('Tests if two activities still show up after completing and ' + testWidgets( + 'Tests if two activities still show up after completing and ' 'cancelling first and last activity', (WidgetTester tester) async { authBloc.setMode(WeekplanMode.citizen); mockSettings.showOnlyActivities = true; mockSettings.nrOfActivitiesToDisplay = 2; - final int weekDay = DateTime - .now() - .weekday - .toInt() - 1; + final int weekDay = DateTime.now().weekday.toInt() - 1; mockActivities[0].state = ActivityState.Completed; mockActivities[1].state = ActivityState.Completed; mockActivities[2].state = ActivityState.Canceled; @@ -1056,15 +1020,13 @@ void main() { expect(find.byType(ActivityCard), findsOneWidget); }); - testWidgets('Tests if two activities still show up after completing and ' + testWidgets( + 'Tests if two activities still show up after completing and ' 'cancelling first and last activity', (WidgetTester tester) async { authBloc.setMode(WeekplanMode.citizen); mockSettings.showOnlyActivities = true; mockSettings.nrOfActivitiesToDisplay = 2; - final int weekDay = DateTime - .now() - .weekday - .toInt() - 1; + final int weekDay = DateTime.now().weekday.toInt() - 1; mockActivities[0].state = ActivityState.Completed; mockActivities[1].state = ActivityState.Completed; mockActivities[2].state = ActivityState.Canceled; @@ -1094,163 +1056,223 @@ void main() { }); testWidgets('Cancelled activities displayed correctly in Citizen Mode', - (WidgetTester tester) async { - authBloc.setMode(WeekplanMode.citizen); - mockActivities[0].state = ActivityState.Canceled; - + (WidgetTester tester) async { + authBloc.setMode(WeekplanMode.citizen); + mockActivities[0].state = ActivityState.Canceled; - // Added Cancelled activity with a cross - mockWeek.days[0].activities.add(mockActivities[0]); + // Added Cancelled activity with a cross + mockWeek.days[0].activities.add(mockActivities[0]); - await tester.pumpWidget(MaterialApp( - home: WeekplanScreen(mockWeek, user))); - await tester.pumpAndSettle(); + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); - // Find cross (cancelled) icon by key - expect(find.byKey(const Key('IconCanceled')), findsOneWidget); - }); + // Find cross (cancelled) icon by key + expect(find.byKey(const Key('IconCanceled')), findsOneWidget); + }); - testWidgets('When showing 7 days in landscape mode for citizen, ' + testWidgets( + 'When showing 7 days in landscape mode for citizen, ' 'the 7 weekdays with their corresponding colors are present', (WidgetTester tester) async { mockSettings.nrOfDaysToDisplayLandscape = 7; - authBloc.setMode(WeekplanMode.citizen); - final WeekplanScreen weekplanScreen = WeekplanScreen(mockWeek, user); - await tester.pumpWidget(MaterialApp(home: weekplanScreen)); - await tester.pumpAndSettle(); + authBloc.setMode(WeekplanMode.citizen); + final WeekplanScreen weekplanScreen = WeekplanScreen(mockWeek, user); + await tester.pumpWidget(MaterialApp(home: weekplanScreen)); + await tester.pumpAndSettle(); - final List expectedColors = - mockSettings.weekDayColors; - expect( - find.byWidgetPredicate((Widget widget) => + final List expectedColors = mockSettings.weekDayColors; + expect( + find.byWidgetPredicate((Widget widget) => widget is WeekplanDayColumn && widget.color == getColorFromWeekdayColorModel(expectedColors[0])), findsOneWidget); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is WeekplanDayColumn && widget.color == getColorFromWeekdayColorModel(expectedColors[1])), findsOneWidget); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is WeekplanDayColumn && widget.color == getColorFromWeekdayColorModel(expectedColors[2])), findsOneWidget); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is WeekplanDayColumn && widget.color == getColorFromWeekdayColorModel(expectedColors[3])), findsOneWidget); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is WeekplanDayColumn && widget.color == getColorFromWeekdayColorModel(expectedColors[4])), findsOneWidget); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is WeekplanDayColumn && widget.color == getColorFromWeekdayColorModel(expectedColors[5])), findsOneWidget); - expect( - find.byWidgetPredicate((Widget widget) => + expect( + find.byWidgetPredicate((Widget widget) => widget is WeekplanDayColumn && widget.color == getColorFromWeekdayColorModel(expectedColors[6])), findsOneWidget); }); - testWidgets('Aciticy card starts time when activated' - ' and shows it for citizen', - (WidgetTester tester) async { - await tester.runAsync(() async { - final Completer checkCompleted = Completer(); - - mockActivities[2].state = ActivityState.Normal; - mockActivities[2].timer.paused = true; - mockActivities[2].timer.fullLength = 100; - mockWeek.days[0].activities.add(mockActivities[2]); - authBloc.setMode(WeekplanMode.citizen); - final WeekplanScreen weekplanScreen = WeekplanScreen(mockWeek, user); - await tester.pumpWidget(MaterialApp(home: weekplanScreen)); - - await tester.pumpAndSettle(); - await tester.tap(find.byKey(Key(mockWeek.days[0].day.index.toString() + + testWidgets( + 'Aciticy card starts time when activated' + ' and shows it for citizen', (WidgetTester tester) async { + await tester.runAsync(() async { + final Completer checkCompleted = Completer(); + + mockActivities[2].state = ActivityState.Normal; + mockActivities[2].timer.paused = true; + mockActivities[2].timer.fullLength = 100; + mockWeek.days[0].activities.add(mockActivities[2]); + authBloc.setMode(WeekplanMode.citizen); + final WeekplanScreen weekplanScreen = WeekplanScreen(mockWeek, user); + await tester.pumpWidget(MaterialApp(home: weekplanScreen)); + + await tester.pumpAndSettle(); + await tester.tap(find.byKey(Key(mockWeek.days[0].day.index.toString() + mockActivities[2].id.toString()))); - await tester.pumpAndSettle(); - - expect(find.byKey(const Key('TimerInitKey')), findsNothing); - // ignore: always_specify_types - Future.delayed(const Duration(seconds: 2), () async { - checkCompleted.complete(); - await checkCompleted.future; - expect(find.byKey(const Key('IconComplete')), findsOneWidget); - }); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('TimerInitKey')), findsNothing); + // ignore: always_specify_types + Future.delayed(const Duration(seconds: 2), () async { + checkCompleted.complete(); + await checkCompleted.future; + expect(find.byKey(const Key('IconComplete')), findsOneWidget); }); + }); }); testWidgets('Aciticy card has completed icon when activity is completed', - (WidgetTester tester) async { - await tester.runAsync(() async { - mockActivities[0].state = ActivityState.Normal; - mockWeek.days[0].activities.add(mockActivities[0]); - authBloc.setMode(WeekplanMode.citizen); - final WeekplanScreen weekplanScreen = WeekplanScreen( - mockWeek, user); - await tester.pumpWidget(MaterialApp(home: weekplanScreen)); - - await tester.pumpAndSettle(); - await tester.tap( - find.byKey(Key(mockWeek.days[0].day.index.toString() + - mockActivities[0].id.toString()))); - await tester.pumpAndSettle(); - expect(find.byKey(const Key('IconComplete')), findsOneWidget); - }); + (WidgetTester tester) async { + await tester.runAsync(() async { + mockActivities[0].state = ActivityState.Normal; + mockWeek.days[0].activities.add(mockActivities[0]); + authBloc.setMode(WeekplanMode.citizen); + final WeekplanScreen weekplanScreen = WeekplanScreen(mockWeek, user); + await tester.pumpWidget(MaterialApp(home: weekplanScreen)); + + await tester.pumpAndSettle(); + await tester.tap(find.byKey(Key(mockWeek.days[0].day.index.toString() + + mockActivities[0].id.toString()))); + await tester.pumpAndSettle(); + expect(find.byKey(const Key('IconComplete')), findsOneWidget); + }); }); - testWidgets('click actitivty card for citizen does nothing ' + testWidgets( + 'click actitivty card for citizen does nothing ' 'if the activity is completed or the timer is running', - (WidgetTester tester) async { - await tester.runAsync(() async { - final Completer checkCompleted = Completer(); - - mockActivities[2].state = ActivityState.Normal; - mockActivities[2].timer.paused = true; - mockActivities[2].timer.fullLength = 100; - mockWeek.days[0].activities.add(mockActivities[2]); - authBloc.setMode(WeekplanMode.citizen); - final WeekplanScreen weekplanScreen = WeekplanScreen(mockWeek, user); - await tester.pumpWidget(MaterialApp(home: weekplanScreen)); - - await tester.pumpAndSettle(); - await tester.tap(find.byKey(Key(mockWeek.days[0].day.index.toString() - + mockActivities[2].id.toString()))); - await tester.pumpAndSettle(); - - expect(find.byKey(const Key('TimerInitKey')), findsNothing); - await tester.tap(find.byKey(Key(mockWeek.days[0].day.index.toString() - + mockActivities[2].id.toString()))); - - expect(find.byKey(const Key('TimerInitKey')), findsNothing); - // ignore: always_specify_types - Future.delayed(const Duration(seconds: 2), () async { - checkCompleted.complete(); - await checkCompleted.future; - - expect(find.byKey(const Key('IconComplete')), findsOneWidget); - await tester.tap(find.byKey(Key( - mockWeek.days[0].day.index.toString() - + mockActivities[2].id.toString()))); - - expect(find.byKey(const Key('IconComplete')), findsOneWidget); - }); + (WidgetTester tester) async { + await tester.runAsync(() async { + final Completer checkCompleted = Completer(); + + mockActivities[2].state = ActivityState.Normal; + mockActivities[2].timer.paused = true; + mockActivities[2].timer.fullLength = 100; + mockWeek.days[0].activities.add(mockActivities[2]); + authBloc.setMode(WeekplanMode.citizen); + final WeekplanScreen weekplanScreen = WeekplanScreen(mockWeek, user); + await tester.pumpWidget(MaterialApp(home: weekplanScreen)); + + await tester.pumpAndSettle(); + await tester.tap(find.byKey(Key(mockWeek.days[0].day.index.toString() + + mockActivities[2].id.toString()))); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('TimerInitKey')), findsNothing); + await tester.tap(find.byKey(Key(mockWeek.days[0].day.index.toString() + + mockActivities[2].id.toString()))); + + expect(find.byKey(const Key('TimerInitKey')), findsNothing); + // ignore: always_specify_types + Future.delayed(const Duration(seconds: 2), () async { + checkCompleted.complete(); + await checkCompleted.future; + + expect(find.byKey(const Key('IconComplete')), findsOneWidget); + await tester.tap(find.byKey(Key(mockWeek.days[0].day.index.toString() + + mockActivities[2].id.toString()))); + + expect(find.byKey(const Key('IconComplete')), findsOneWidget); }); }); + }); + + testWidgets( + 'Choice board displays properly in citizen mode when an activity has not been chosen', + (WidgetTester tester) async { + authBloc.setMode(WeekplanMode.citizen); + + // Add the activity to mockWeek + mockWeek.days[0].activities.add(mockActivities[3]); + + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + // Check if no choice board exists. + expect(find.byKey(const Key('WeekPlanScreenChoiceBoard')), findsOneWidget); + }); + + testWidgets( + 'Choice board displays properly in citizen mode when an activity has been chosen', + (WidgetTester tester) async { + authBloc.setMode(WeekplanMode.citizen); + + mockActivities[3].chosenActivity = 0; + + // Add the activity to mockWeek + mockWeek.days[0].activities.add(mockActivities[3]); + + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + // Check if no choice board exists. + expect(find.byKey(const Key('WeekPlanScreenChoiceBoard')), findsNothing); + }); + + testWidgets( + 'Choice board displays properly in guardian mode when an activity has not been chosen', + (WidgetTester tester) async { + authBloc.setMode(WeekplanMode.guardian); + + // Add the activity to mockWeek + mockWeek.days[0].activities.add(mockActivities[3]); + + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + // Check if no choice board exists. + expect(find.byKey(const Key('WeekPlanScreenChoiceBoard')), findsOneWidget); + }); + + testWidgets( + 'Choice board displays properly in guardian mode when an activity has been chosen', + (WidgetTester tester) async { + authBloc.setMode(WeekplanMode.guardian); + + mockActivities[3].chosenActivity = 0; + + // Add the activity to mockWeek + mockWeek.days[0].activities.add(mockActivities[3]); + + await tester.pumpWidget(MaterialApp(home: WeekplanScreen(mockWeek, user))); + await tester.pumpAndSettle(); + + // Check if no choice board exists. + expect(find.byKey(const Key('WeekPlanScreenChoiceBoard')), findsOneWidget); + }); } Color getColorFromWeekdayColorModel(WeekdayColorModel weekdayColorModel) { @@ -1279,9 +1301,9 @@ void expectColorDayMatch(Weekday day, String color) { } final Finder findColor = find.byWidgetPredicate((Widget widget) => - widget is Card && widget.color == Color(int.parse(color))); + widget is Card && widget.color == Color(int.parse(color))); final Finder findTitle = find.byWidgetPredicate( - (Widget widget) => widget is Card && widget.key == Key(dayString)); + (Widget widget) => widget is Card && widget.key == Key(dayString)); expect(find.descendant(of: findColor, matching: findTitle), findsOneWidget); }