From 2d734db773b469e1844838c622d0297a74037c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20H=C3=BCnniger?= Date: Fri, 1 Sep 2023 15:16:59 +0200 Subject: [PATCH 1/2] feat: add some keys, renamed some keys --- .../pages/home_page/desk_interaction_card_test.dart | 10 +++++----- .../presentation/pages/home_page/home_page_test.dart | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/features/presentation/pages/home_page/desk_interaction_card_test.dart b/test/features/presentation/pages/home_page/desk_interaction_card_test.dart index bde3741..b422350 100644 --- a/test/features/presentation/pages/home_page/desk_interaction_card_test.dart +++ b/test/features/presentation/pages/home_page/desk_interaction_card_test.dart @@ -61,7 +61,7 @@ void main() { }, child: const Text( 'test', - key: Key('child-key'), + key: Key('child'), ), ), ); @@ -83,7 +83,7 @@ void main() { expect(find.byType(Text), findsNWidgets(2)); // idk why 4 -> 2 for the Text widgets and 2 for the SizedBox widgets (RenderConstraint Boxes for the texts) expect(find.byType(SizedBox), findsNWidgets(4)); - expect(find.byKey(const Key('child-key')), findsOneWidget); + expect(find.byKey(const Key('child')), findsOneWidget); // expect(find.byType(CustomIconButton), findsNothing); }); @@ -129,7 +129,7 @@ void main() { expect(find.byType(Icon), findsNWidgets(2)); expect(find.byType(Text), findsOneWidget); expect(find.byType(Spacer), findsOneWidget); - expect(find.byKey(const Key('child-key')), findsNothing); + expect(find.byKey(const Key('child')), findsNothing); }); testWidgets('onPressedCard is executed on tap', (widgetTester) async { @@ -168,7 +168,7 @@ void main() { }, child: const Text( 'test', - key: Key('child-key'), + key: Key('child'), ), ), ); @@ -189,7 +189,7 @@ void main() { expect(find.byType(Icon), findsNWidgets(2)); // only here there are 2 Text widgets -> in future work with keys or something else expect(find.byType(Text), findsNWidgets(2)); - expect(find.byKey(const Key('child-key')), findsOneWidget); + expect(find.byKey(const Key('child')), findsOneWidget); }); testWidgets('onPressedCard is executed on tap', (widgetTester) async { diff --git a/test/features/presentation/pages/home_page/home_page_test.dart b/test/features/presentation/pages/home_page/home_page_test.dart index 2b33aae..fc91f4a 100644 --- a/test/features/presentation/pages/home_page/home_page_test.dart +++ b/test/features/presentation/pages/home_page/home_page_test.dart @@ -82,8 +82,8 @@ void main() { await widgetTester.pumpWidget(createWidgetUnderTest()); await widgetTester.pump(const Duration(milliseconds: 500)); // assert - expect(find.byKey(const Key('all-articles-loading-indicator')), - findsOneWidget); + expect( + find.byKey(const Key('all-desks-loading-indicator')), findsOneWidget); await widgetTester.pumpAndSettle(); }, ); From c673f0c19f03afd2f2da07e6d4ff5d4f4f033396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20H=C3=BCnniger?= Date: Fri, 1 Sep 2023 15:17:16 +0200 Subject: [PATCH 2/2] chore: add some more keys and refactor the preset desk interaction card part --- .../pages/home_page/home_page.dart | 79 ++++++++++++------- .../pages/add_desk_page/preset_card_test.dart | 4 +- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/lib/features/presentation/pages/home_page/home_page.dart b/lib/features/presentation/pages/home_page/home_page.dart index fad6491..9342795 100644 --- a/lib/features/presentation/pages/home_page/home_page.dart +++ b/lib/features/presentation/pages/home_page/home_page.dart @@ -38,47 +38,47 @@ class _HomePageState extends State { _buildDeskCarouselSlider(), const SizedBox(height: ThemeSettings.mediumSpacing), const Heading( - title: 'Analytics', key: Key('analytics-heading'), + title: 'Analytics', ), const SizedBox(height: ThemeSettings.smallSpacing), DeskInteractionCard( + key: const Key('analytics-desk-card-standing'), title: 'Standing Time', iconAtStart: const Icon(Icons.info), onPressedCard: () {}, - key: const Key('analytics-desk-card-standing'), child: const LinearProgressIndicator( value: 0.7, ), ), const SizedBox(height: ThemeSettings.smallSpacing), DeskInteractionCard( + key: const Key('analytics-desk-card-sitting'), title: 'Sitting Time', iconAtStart: const Icon(Icons.info), onPressedCard: () {}, - key: const Key('analytics-desk-card-sitting'), child: const LinearProgressIndicator( value: 0.3, ), ), const SizedBox(height: ThemeSettings.mediumSpacing), const Heading( - title: 'Presets', key: Key('preset-heading'), + title: 'Presets', ), const SizedBox(height: ThemeSettings.smallSpacing), _buildCurrentDeskPresets(), const SizedBox(height: ThemeSettings.mediumSpacing), const Heading( - title: 'Others', key: Key('others-heading'), + title: 'Others', ), const SizedBox(height: ThemeSettings.smallSpacing), DeskInteractionCard( + key: const Key('others-desk-card-move'), title: 'Move desk', iconAtStart: const Icon(Icons.move_up), onPressedCard: () {}, - key: const Key('others-desk-card-move'), ), ], ); @@ -92,8 +92,8 @@ class _HomePageState extends State { return Container(); } else if (state is UpdateCurrentDeskSuccess) { return Heading( - title: state.currentDesk.name, key: const Key('current-desk-name'), + title: state.currentDesk.name, ); } else if (state is UpdateCurrentDeskFailure) { return Container(); @@ -135,24 +135,20 @@ class _HomePageState extends State { if (state is Empty) { return Container(); } else if (state is UpdateCurrentDeskSuccess) { - return Column( - children: [ - for (final Preset preset in state.currentDesk.presets) - Column( - children: [ - DeskInteractionCard( - title: preset.name, - iconAtStart: const Icon(Icons.height), - onPressedCard: () {}, - iconAtEnd: const Icon(Icons.settings), - onPressedIconAtEnd: () {}, - key: Key('preset-desk-card-${preset.id}'), - child: Text('${preset.targetHeight.toString()} cm'), - ), - const SizedBox(height: ThemeSettings.smallSpacing), - ], - ), - ], + final List cards = + _getAllPresetDeskInteractionCards(state.currentDesk.presets); + + return ListView.separated( + key: const Key('preset-desk-card-list'), + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + separatorBuilder: (context, index) { + return const SizedBox(height: ThemeSettings.smallSpacing); + }, + itemCount: cards.length, + itemBuilder: (_, index) { + return cards[index]; + }, ); } else { return const Text('Unknown state'); @@ -172,7 +168,7 @@ class _HomePageState extends State { return Container(); } else if (state is GetAllDesksFetching) { return const LoadingIndicator( - key: Key('all-articles-loading-indicator'), + key: Key('all-desks-loading-indicator'), ); } else if (state is GetAllDesksSuccess) { if (state.desks.isEmpty) { @@ -180,14 +176,18 @@ class _HomePageState extends State { return const Center(child: Text('No desks found :/')); } + // TODO: hier wird gerade wie beim CarouselSlider einfach erstmal das 0.te Element verwendet + // -> später mal schauen, wie ich das in der DB abbilden kann _updateCurrentDesk(state.desks.first); return DeskCarouselSlider( + key: const Key('desk-carousel-slider'), allDesks: state.desks, onDeskSelected: (Desk desk) => _updateCurrentDesk(desk), ); } else if (state is GetAllDesksFailure) { return Column( + key: const Key('all-desks-failure-column'), children: [ const Icon(Icons.error), Text(state.message), @@ -200,12 +200,31 @@ class _HomePageState extends State { ); } - void _updateCurrentDesk(Desk desks) { + List _getAllPresetDeskInteractionCards( + List presetList) { + List presetCards = []; + + for (final Preset preset in presetList) { + final DeskInteractionCard card = DeskInteractionCard( + key: Key('preset-desk-card-${preset.id}'), + title: preset.name, + iconAtStart: const Icon(Icons.height), + onPressedCard: () {}, + iconAtEnd: const Icon(Icons.settings), + onPressedIconAtEnd: () {}, + child: Text('${preset.targetHeight.toString()} cm'), + ); + + presetCards.add(card); + } + + return presetCards; + } + + void _updateCurrentDesk(Desk desk) { BlocProvider.of(context).add( UpdatedCurrentDesk( - // TODO: hier wird gerade wie beim CarouselSlider einfach erstmal das 0.te Element verwendet - // -> später mal schauen, wie ich das in der DB abbilden kann - currentDesk: desks, + currentDesk: desk, ), ); } diff --git a/test/features/presentation/pages/add_desk_page/preset_card_test.dart b/test/features/presentation/pages/add_desk_page/preset_card_test.dart index 39f1678..3e124ca 100644 --- a/test/features/presentation/pages/add_desk_page/preset_card_test.dart +++ b/test/features/presentation/pages/add_desk_page/preset_card_test.dart @@ -1 +1,3 @@ -// TODO: skipped for now \ No newline at end of file +// TODO: skipped for now + +void main() {}