historylist test
parent
a9480cc508
commit
6c0708ca77
|
@ -0,0 +1,102 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:smoke_cess_app/widgets/entry_detail_widget.dart';
|
||||
import 'package:smoke_cess_app/widgets/history_list_widget.dart';
|
||||
|
||||
void main() {
|
||||
group('HistoryList', () {
|
||||
initializeDateFormatting('de');
|
||||
final List<String> history = ['1', '2', '3'];
|
||||
dateSelector(String p0) => DateTime.now();
|
||||
entryDataSelector(String p0) => p0;
|
||||
|
||||
testWidgets('should produce #(history.length) EntryDetail Widgets',
|
||||
(widgetTester) async {
|
||||
await widgetTester.pumpWidget(WrappedHistoryList(
|
||||
history: history,
|
||||
dateSelector: dateSelector,
|
||||
entryDataSelector: entryDataSelector));
|
||||
final widgetFinder = find.byType(EntryDetail);
|
||||
final dateFinder =
|
||||
find.text(DateFormat.MMMd('de').format(DateTime.now()));
|
||||
//HistoryList uses Icons.circle as default if there is no IconData provided
|
||||
final iconFinder = find.byIcon(Icons.circle);
|
||||
expect(widgetFinder, findsNWidgets(history.length));
|
||||
expect(dateFinder, findsNWidgets(history.length));
|
||||
expect(iconFinder, findsNWidgets(history.length));
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'should render correct icon if specified with icon selection function',
|
||||
(widgetTester) async {
|
||||
IconData iconDataSelector(String p0) => Icons.email;
|
||||
|
||||
await widgetTester.pumpWidget(WrappedHistoryList(
|
||||
history: history,
|
||||
dateSelector: dateSelector,
|
||||
entryDataSelector: entryDataSelector,
|
||||
iconDataSelector: iconDataSelector,
|
||||
));
|
||||
final circleIconFinder = find.byIcon(Icons.circle);
|
||||
final correctIconFinder = find.byIcon(Icons.email);
|
||||
|
||||
expect(circleIconFinder, findsNothing);
|
||||
expect(correctIconFinder, findsNWidgets(history.length));
|
||||
});
|
||||
|
||||
testWidgets('icon field should overwrite iconSelector',
|
||||
(widgetTester) async {
|
||||
const IconData icon = Icons.abc;
|
||||
IconData iconDataSelector(String p0) => Icons.email;
|
||||
await widgetTester.pumpWidget(WrappedHistoryList(
|
||||
history: history,
|
||||
dateSelector: dateSelector,
|
||||
entryDataSelector: entryDataSelector,
|
||||
iconDataSelector: iconDataSelector,
|
||||
icon: Icons.abc,
|
||||
));
|
||||
final circleIconFinder = find.byIcon(Icons.circle);
|
||||
final emailIconFinder = find.byIcon(Icons.email);
|
||||
final correctIconFinder = find.byIcon(icon);
|
||||
|
||||
expect(circleIconFinder, findsNothing);
|
||||
expect(emailIconFinder, findsNothing);
|
||||
expect(correctIconFinder, findsNWidgets(history.length));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class WrappedHistoryList<T> extends StatelessWidget {
|
||||
final List<T> history;
|
||||
final DateTime Function(T) dateSelector;
|
||||
final String Function(T) entryDataSelector;
|
||||
final IconData Function(T)? iconDataSelector;
|
||||
final String Function(T)? entryCommentSelector;
|
||||
final IconData? icon;
|
||||
const WrappedHistoryList(
|
||||
{super.key,
|
||||
required this.history,
|
||||
required this.dateSelector,
|
||||
required this.entryDataSelector,
|
||||
this.iconDataSelector,
|
||||
this.icon,
|
||||
this.entryCommentSelector});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Column(children: [
|
||||
HistoryList<T>(
|
||||
history: history,
|
||||
dateSelector: dateSelector,
|
||||
entryDataSelector: entryDataSelector,
|
||||
icon: icon,
|
||||
iconDataSelector: iconDataSelector,
|
||||
entryCommentSelector: entryCommentSelector,
|
||||
)
|
||||
])));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue