From 166fe71105fae354a033512e214dc45f260bd079 Mon Sep 17 00:00:00 2001 From: JvnSlv Date: Fri, 6 Sep 2024 17:07:19 +0200 Subject: [PATCH] Fix golden tests failing --- .../views/statistics_page.dart | 2 +- .../todos_filter_popup_menu_button.dart | 27 ++++++++++--------- .../views/todo_list_page.dart | 2 +- ...todo_list_bulk_edit_popup_menu_button.dart | 27 ++++++++++--------- ...odos_filter_popup_menu_button_factory.dart | 4 +-- ..._filter_popup_menu_button_golden_test.dart | 19 +++++++------ ...t_bulk_edit_popup_menu_button_factory.dart | 3 +-- ...lk_edit_popup_menu_button_golden_test.dart | 23 +++++++--------- 8 files changed, 52 insertions(+), 55 deletions(-) diff --git a/examples/todoapp/lib/feature_statistics/views/statistics_page.dart b/examples/todoapp/lib/feature_statistics/views/statistics_page.dart index b77464cfe..3a75b574a 100644 --- a/examples/todoapp/lib/feature_statistics/views/statistics_page.dart +++ b/examples/todoapp/lib/feature_statistics/views/statistics_page.dart @@ -19,7 +19,7 @@ class StatisticsPage extends StatelessWidget { Widget build(BuildContext context) => Scaffold( appBar: AppBar( title: Text(context.l10n.todos), - actions: [ + actions: const [ AppTodoListBulkEditPopupMenuButton(), ], ), diff --git a/examples/todoapp/lib/feature_todo_list/ui_components/todos_filter_popup_menu_button.dart b/examples/todoapp/lib/feature_todo_list/ui_components/todos_filter_popup_menu_button.dart index 6c204f705..a3506248f 100644 --- a/examples/todoapp/lib/feature_todo_list/ui_components/todos_filter_popup_menu_button.dart +++ b/examples/todoapp/lib/feature_todo_list/ui_components/todos_filter_popup_menu_button.dart @@ -7,26 +7,27 @@ import '../../base/models/todos_filter_model.dart'; import '../blocs/todo_list_bloc.dart'; class TodosFilterPopupMenuButton extends StatelessWidget { - TodosFilterPopupMenuButton({super.key}); - final GlobalKey _popupMenuKey = GlobalKey(); - + const TodosFilterPopupMenuButton({super.key}); @override Widget build(BuildContext context) => RxBlocBuilder( state: (bloc) => bloc.states.filter, builder: (context, snapshot, bloc) => PopupMenuButton( - key: _popupMenuKey, - child: SmallButton( - type: SmallButtonType.icon, - icon: context.designSystem.icons.filter.icon, - colorStyle: ButtonColorStyle.fromContext(context).copyWith( - activeButtonTextColor: context.designSystem.colors.textColor, + child: Builder( + builder: (context) => SmallButton( + type: SmallButtonType.icon, + icon: context.designSystem.icons.filter.icon, + colorStyle: ButtonColorStyle.fromContext(context).copyWith( + activeButtonTextColor: context.designSystem.colors.textColor, + ), + onPressed: () { + final popupMenuButton = + context.findAncestorStateOfType(); + popupMenuButton?.showButtonMenu(); + }, ), - onPressed: () { - final dynamic popupMenu = _popupMenuKey.currentState; - popupMenu.showButtonMenu(); - }, ), + onSelected: (filter) => bloc.events.applyFilter(filter), itemBuilder: (context) => TodosFilterModel.values .map((filter) => switch (filter) { (TodosFilterModel.all) => PopupMenuItem( diff --git a/examples/todoapp/lib/feature_todo_list/views/todo_list_page.dart b/examples/todoapp/lib/feature_todo_list/views/todo_list_page.dart index 26a95e10d..7d0b92a65 100644 --- a/examples/todoapp/lib/feature_todo_list/views/todo_list_page.dart +++ b/examples/todoapp/lib/feature_todo_list/views/todo_list_page.dart @@ -24,7 +24,7 @@ class TodoListPage extends StatelessWidget { Widget build(BuildContext context) => Scaffold( appBar: AppBar( title: Text(context.l10n.todos), - actions: [ + actions: const [ TodosFilterPopupMenuButton(), AppTodoListBulkEditPopupMenuButton(), ], diff --git a/examples/todoapp/lib/lib_todo_actions/ui_components/app_todo_list_bulk_edit_popup_menu_button.dart b/examples/todoapp/lib/lib_todo_actions/ui_components/app_todo_list_bulk_edit_popup_menu_button.dart index 656902af2..7f23f4d85 100644 --- a/examples/todoapp/lib/lib_todo_actions/ui_components/app_todo_list_bulk_edit_popup_menu_button.dart +++ b/examples/todoapp/lib/lib_todo_actions/ui_components/app_todo_list_bulk_edit_popup_menu_button.dart @@ -9,8 +9,7 @@ import '../blocs/todo_list_bulk_edit_bloc.dart'; import '../models/bulk_action.dart'; class AppTodoListBulkEditPopupMenuButton extends StatelessWidget { - AppTodoListBulkEditPopupMenuButton({super.key}); - final GlobalKey _popupMenuKey = GlobalKey(); + const AppTodoListBulkEditPopupMenuButton({super.key}); @override Widget build(BuildContext context) => RxBlocMultiBuilder2< @@ -18,18 +17,20 @@ class AppTodoListBulkEditPopupMenuButton extends StatelessWidget { state1: (bloc) => bloc.states.bulkActions, state2: (bloc) => bloc.states.isLoading, builder: (context, snapshot, isLoading, bloc) => PopupMenuButton( - key: _popupMenuKey, - child: SmallButton( - state: isLoading.buttonStateModel, - type: SmallButtonType.icon, - icon: context.designSystem.icons.menu.icon, - colorStyle: ButtonColorStyle.fromContext(context).copyWith( - activeButtonTextColor: context.designSystem.colors.textColor, + child: Builder( + builder: (context) => SmallButton( + onPressed: () { + final popupMenuButton = + context.findAncestorStateOfType(); + popupMenuButton?.showButtonMenu(); + }, + state: isLoading.buttonStateModel, + type: SmallButtonType.icon, + icon: context.designSystem.icons.menu.icon, + colorStyle: ButtonColorStyle.fromContext(context).copyWith( + activeButtonTextColor: context.designSystem.colors.textColor, + ), ), - onPressed: () { - final dynamic popupMenu = _popupMenuKey.currentState; - popupMenu.showButtonMenu(); - }, ), itemBuilder: (context) => snapshot.hasData ? snapshot.requireData diff --git a/examples/todoapp/test/feature_todo_details/factory/todos_filter_popup_menu_button_factory.dart b/examples/todoapp/test/feature_todo_details/factory/todos_filter_popup_menu_button_factory.dart index 067267426..ea31413b9 100644 --- a/examples/todoapp/test/feature_todo_details/factory/todos_filter_popup_menu_button_factory.dart +++ b/examples/todoapp/test/feature_todo_details/factory/todos_filter_popup_menu_button_factory.dart @@ -10,7 +10,7 @@ import 'package:todoapp/feature_todo_list/ui_components/todos_filter_popup_menu_ import '../blocs/todo_list_bloc_factory.dart'; /// Change the parameters according the the needs of the test -Widget todoFilterPopupMenuButtonFactory({ +Widget todosFilterPopupMenuButtonFactory({ Result>? todos, TodosFilterModel? filter, }) { @@ -24,7 +24,7 @@ Widget todoFilterPopupMenuButtonFactory({ ), ), ], - child: TodosFilterPopupMenuButton(), + child: const TodosFilterPopupMenuButton(), ), ); } diff --git a/examples/todoapp/test/feature_todo_details/view/todos_filter_popup_menu_button_golden_test.dart b/examples/todoapp/test/feature_todo_details/view/todos_filter_popup_menu_button_golden_test.dart index 2ed5c038c..b2bc2e94f 100644 --- a/examples/todoapp/test/feature_todo_details/view/todos_filter_popup_menu_button_golden_test.dart +++ b/examples/todoapp/test/feature_todo_details/view/todos_filter_popup_menu_button_golden_test.dart @@ -1,5 +1,3 @@ -import 'package:todoapp/base/models/todos_filter_model.dart'; - import '../../helpers/golden_helper.dart'; import '../../helpers/models/scenario.dart'; import '../factory/todos_filter_popup_menu_button_factory.dart'; @@ -7,15 +5,16 @@ import '../factory/todos_filter_popup_menu_button_factory.dart'; void main() { runGoldenTests([ generateDeviceBuilder( - widget: todoFilterPopupMenuButtonFactory(filter: TodosFilterModel.all), - scenario: Scenario(name: 'todos_filter_popup_menu_button_all')), + widget: todosFilterPopupMenuButtonFactory(), //example: Stubs.emptyList + scenario: Scenario(name: 'todos_filter_popup_menu_button_empty')), + generateDeviceBuilder( + widget: todosFilterPopupMenuButtonFactory(), //example: Stubs.success + scenario: Scenario(name: 'todos_filter_popup_menu_button_success')), generateDeviceBuilder( - widget: todoFilterPopupMenuButtonFactory( - filter: TodosFilterModel.incomplete), - scenario: Scenario(name: 'todos_filter_popup_menu_button_incomplete')), + widget: todosFilterPopupMenuButtonFactory(), //loading + scenario: Scenario(name: 'todos_filter_popup_menu_button_loading')), generateDeviceBuilder( - widget: todoFilterPopupMenuButtonFactory( - filter: TodosFilterModel.completed), - scenario: Scenario(name: 'todos_filter_popup_menu_button_completed')), + widget: todosFilterPopupMenuButtonFactory(), + scenario: Scenario(name: 'todos_filter_popup_menu_button_error')) ]); } diff --git a/examples/todoapp/test/lib_todo_actions/factory/app_todo_list_bulk_edit_popup_menu_button_factory.dart b/examples/todoapp/test/lib_todo_actions/factory/app_todo_list_bulk_edit_popup_menu_button_factory.dart index c2911fdea..d4f65d210 100644 --- a/examples/todoapp/test/lib_todo_actions/factory/app_todo_list_bulk_edit_popup_menu_button_factory.dart +++ b/examples/todoapp/test/lib_todo_actions/factory/app_todo_list_bulk_edit_popup_menu_button_factory.dart @@ -14,6 +14,5 @@ Widget appTodoListBulkEditPopupMenuButtonFactory({ value: todoListBulkEditMockFactory(), ), ], - child: AppTodoListBulkEditPopupMenuButton(), + child: const AppTodoListBulkEditPopupMenuButton(), ); -//AppTodoListBulkEditPopupMenuButton(); diff --git a/examples/todoapp/test/lib_todo_actions/view/app_todo_list_bulk_edit_popup_menu_button_golden_test.dart b/examples/todoapp/test/lib_todo_actions/view/app_todo_list_bulk_edit_popup_menu_button_golden_test.dart index 40dbad9c0..30dc8f60a 100644 --- a/examples/todoapp/test/lib_todo_actions/view/app_todo_list_bulk_edit_popup_menu_button_golden_test.dart +++ b/examples/todoapp/test/lib_todo_actions/view/app_todo_list_bulk_edit_popup_menu_button_golden_test.dart @@ -1,4 +1,3 @@ -import 'package:todoapp/lib_todo_actions/models/bulk_action.dart'; import '../../helpers/golden_helper.dart'; import '../../helpers/models/scenario.dart'; import '../factory/app_todo_list_bulk_edit_popup_menu_button_factory.dart'; @@ -6,22 +5,20 @@ import '../factory/app_todo_list_bulk_edit_popup_menu_button_factory.dart'; void main() { runGoldenTests([ generateDeviceBuilder( - widget: appTodoListBulkEditPopupMenuButtonFactory(bulkActions: [ - BulkActionModel.markAllComplete, - BulkActionModel.markAllIncomplete, - BulkActionModel.clearCompleted - ]), + widget: appTodoListBulkEditPopupMenuButtonFactory(), scenario: - Scenario(name: 'app_todo_list_bulk_edit_popup_menu_button_all')), + Scenario(name: 'app_todo_list_bulk_edit_popup_menu_button_empty')), generateDeviceBuilder( - widget: appTodoListBulkEditPopupMenuButtonFactory( - bulkActions: [BulkActionModel.markAllIncomplete]), + widget: appTodoListBulkEditPopupMenuButtonFactory(), scenario: Scenario( - name: 'app_todo_list_bulk_edit_popup_menu_button_incomplete')), + name: 'app_todo_list_bulk_edit_popup_menu_button_success')), generateDeviceBuilder( - widget: appTodoListBulkEditPopupMenuButtonFactory( - bulkActions: [BulkActionModel.markAllComplete]), + widget: appTodoListBulkEditPopupMenuButtonFactory(), scenario: Scenario( - name: 'app_todo_list_bulk_edit_popup_menu_button_completed')), + name: 'app_todo_list_bulk_edit_popup_menu_button_loading')), + generateDeviceBuilder( + widget: appTodoListBulkEditPopupMenuButtonFactory(), + scenario: + Scenario(name: 'app_todo_list_bulk_edit_popup_menu_button_error')) ]); }