Files
eatvio_app/test/features/feed/presentation/widgets/chip_group_test.dart

88 lines
2.5 KiB
Dart

import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/feed/presentation/widgets/chip_group.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('ChipGroup', () {
testWidgets('displays chip group widget', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChipGroup(
selectedChipIndex: 0,
chipsLabelList: const ['All', 'Recipes', 'Diets'],
setSelectedChipIndex: (index) {},
),
),
),
);
expect(find.byType(ChipGroup), findsOneWidget);
});
testWidgets('displays all chips from list', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChipGroup(
selectedChipIndex: 0,
chipsLabelList: const ['All', 'Recipes', 'Diets', 'Plans'],
setSelectedChipIndex: (index) {},
),
),
),
);
expect(find.byType(ChipGroup), findsOneWidget);
expect(find.text('All'), findsOneWidget);
expect(find.text('Recipes'), findsOneWidget);
expect(find.text('Diets'), findsOneWidget);
expect(find.text('Plans'), findsOneWidget);
});
testWidgets('calls setSelectedChipIndex when chip is tapped', (tester) async {
int? selectedIndex;
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChipGroup(
selectedChipIndex: 0,
chipsLabelList: const ['All', 'Recipes', 'Diets'],
setSelectedChipIndex: (index) {
selectedIndex = index;
},
),
),
),
);
await tester.tap(find.text('Recipes'));
await tester.pump();
expect(selectedIndex, 1);
});
testWidgets('displays empty chip group when list is empty', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: ChipGroup(
selectedChipIndex: 0,
chipsLabelList: const [],
setSelectedChipIndex: (index) {},
),
),
),
);
expect(find.byType(ChipGroup), findsOneWidget);
});
});
}