Skip to content

Commit

Permalink
Fix golden tests failing
Browse files Browse the repository at this point in the history
  • Loading branch information
JvnSlv committed Sep 6, 2024
1 parent f9bd47f commit 166fe71
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class StatisticsPage extends StatelessWidget {
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text(context.l10n.todos),
actions: [
actions: const [
AppTodoListBulkEditPopupMenuButton(),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TodoListBlocType, TodosFilterModel>(
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<PopupMenuButtonState>();
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@ 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<
TodoListBulkEditBlocType, List<BulkActionModel>, bool>(
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<PopupMenuButtonState>();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<$TodoModel>>? todos,
TodosFilterModel? filter,
}) {
Expand All @@ -24,7 +24,7 @@ Widget todoFilterPopupMenuButtonFactory({
),
),
],
child: TodosFilterPopupMenuButton(),
child: const TodosFilterPopupMenuButton(),
),
);
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
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';

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'))
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ Widget appTodoListBulkEditPopupMenuButtonFactory({
value: todoListBulkEditMockFactory(),
),
],
child: AppTodoListBulkEditPopupMenuButton(),
child: const AppTodoListBulkEditPopupMenuButton(),
);
//AppTodoListBulkEditPopupMenuButton();
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
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';

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'))
]);
}

0 comments on commit 166fe71

Please sign in to comment.