diff options
| author | Akshay Nair <phenax5@gmail.com> | 2020-06-02 19:28:14 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2020-06-02 19:28:14 +0530 |
| commit | 8550d124017c04d8391990e8fd0818a8c6dbcef9 (patch) | |
| tree | 7ab5300e95e7da4bd89918eb13fa03fc28039c3e | |
| parent | 1a148e4edf3a27afbc0944429c1ebb6e2599b832 (diff) | |
| download | daft-launcher-8550d124017c04d8391990e8fd0818a8c6dbcef9.tar.gz daft-launcher-8550d124017c04d8391990e8fd0818a8c6dbcef9.zip | |
Fixes default date and test case
| -rw-r--r-- | lib/pages/Home.dart | 9 | ||||
| -rw-r--r-- | test/homeview_test.dart | 22 |
2 files changed, 22 insertions, 9 deletions
diff --git a/lib/pages/Home.dart b/lib/pages/Home.dart index 1f553e3..f2809db 100644 --- a/lib/pages/Home.dart +++ b/lib/pages/Home.dart @@ -4,11 +4,12 @@ import 'package:intl/intl.dart'; class HomeView extends StatelessWidget { Stream<DateTime> time$; + DateTime defaultTime; - final timeFormat = new DateFormat.jm(); - final dateFormat = DateFormat('d, MMM'); + final timeFormat = new DateFormat.jm(); // hm fr 24 hrs + final dateFormat = DateFormat('d MMMM'); - HomeView({ this.time$ }): super(); + HomeView({ this.time$, this.defaultTime }): super(); @override Widget build(BuildContext ctx) { @@ -18,7 +19,7 @@ class HomeView extends StatelessWidget { children: [ StreamBuilder<DateTime>( stream: time$, - initialData: DateTime.now(), + initialData: defaultTime, builder: (BuildContext context, AsyncSnapshot<DateTime> snapshot) { switch (snapshot.connectionState) { case ConnectionState.active: diff --git a/test/homeview_test.dart b/test/homeview_test.dart index 8d8bedc..819600d 100644 --- a/test/homeview_test.dart +++ b/test/homeview_test.dart @@ -7,17 +7,29 @@ import 'utils.dart'; void main() { - Stream<DateTime> time$ = Stream.value(DateTime.utc(2020, DateTime.may, 7, 10, 25, 30)).asBroadcastStream(); + DateTime time = DateTime.utc(2020, DateTime.march, 7, 10, 25, 30); + Stream<DateTime> time$ = Stream.value(time).asBroadcastStream(); testWidgets('Should render with no errors', (WidgetTester tester) async { await tester.pumpWidget(wrapper(HomeView(time$: time$))); }); - testWidgets('Should show formatted date correctly', (WidgetTester tester) async { - await tester.pumpWidget(wrapper(HomeView(time$: time$))); + testWidgets('Should show formatted default date correctly', (WidgetTester tester) async { + await tester.pumpWidget(wrapper(HomeView(time$: time$, defaultTime: time))); await tester.pump(); - expect(find.byKey(Key('time')), findsOneWidget); - expect(find.byKey(Key('date')), findsOneWidget); + var timeWidget = find.byKey(Key('time')); + var dateWidget = find.byKey(Key('date')); + + expect(timeWidget, findsOneWidget); + expect(dateWidget, findsOneWidget); + + for(var w in timeWidget.evaluate()) { + expect(w.widget.toString(), contains('10:25 AM')); + } + + for(var w in dateWidget.evaluate()) { + expect(w.widget.toString(), contains('7 March')); + } }); } |
