Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/keys everywhere #15

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 49 additions & 30 deletions lib/features/presentation/pages/home_page/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,47 +38,47 @@ class _HomePageState extends State<HomePage> {
_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'),
),
],
);
Expand All @@ -92,8 +92,8 @@ class _HomePageState extends State<HomePage> {
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();
Expand Down Expand Up @@ -135,24 +135,20 @@ class _HomePageState extends State<HomePage> {
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<DeskInteractionCard> 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');
Expand All @@ -172,22 +168,26 @@ class _HomePageState extends State<HomePage> {
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) {
_updateCurrentDesk(Desk.empty());
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),
Expand All @@ -200,12 +200,31 @@ class _HomePageState extends State<HomePage> {
);
}

void _updateCurrentDesk(Desk desks) {
List<DeskInteractionCard> _getAllPresetDeskInteractionCards(
List<Preset> presetList) {
List<DeskInteractionCard> 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<DeskBloc>(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,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// TODO: skipped for now
// TODO: skipped for now

void main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void main() {
},
child: const Text(
'test',
key: Key('child-key'),
key: Key('child'),
),
),
);
Expand All @@ -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);
});

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -168,7 +168,7 @@ void main() {
},
child: const Text(
'test',
key: Key('child-key'),
key: Key('child'),
),
),
);
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
);
Expand Down
Loading