From 064a63e932a267039777edd9193b90aaecb9cee5 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 23 Feb 2017 10:53:40 -0800 Subject: [PATCH] Add haptic feedback tests for DatePicker (#8376) --- .../test/material/date_picker_test.dart | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/packages/flutter/test/material/date_picker_test.dart b/packages/flutter/test/material/date_picker_test.dart index dc3ecf4eab..8c11ceee19 100644 --- a/packages/flutter/test/material/date_picker_test.dart +++ b/packages/flutter/test/material/date_picker_test.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:intl/intl.dart'; @@ -268,4 +269,63 @@ void main() { expect(await date, equals(new DateTime(2017, DateTime.JANUARY, 10))); }); }); + + group('haptic feedback', () { + const Duration kHapticFeedbackInterval = const Duration(milliseconds: 10); + int hapticFeedbackCount; + + setUpAll(() { + PlatformMessages.setMockJSONMessageHandler('flutter/platform', (dynamic message) { + if (message['method'] == "HapticFeedback.vibrate") + hapticFeedbackCount++; + }); + }); + + setUp(() { + hapticFeedbackCount = 0; + initialDate = new DateTime(2017, DateTime.JANUARY, 16); + firstDate = new DateTime(2017, DateTime.JANUARY, 10); + lastDate = new DateTime(2018, DateTime.JANUARY, 20); + selectableDayPredicate = (DateTime date) => date.day.isEven; + }); + + testWidgets('tap-select date vibrates', (WidgetTester tester) async { + await preparePicker(tester, (Future date) async { + await tester.tap(find.text('10')); + await tester.pump(kHapticFeedbackInterval); + expect(hapticFeedbackCount, 1); + await tester.tap(find.text('12')); + await tester.pump(kHapticFeedbackInterval); + expect(hapticFeedbackCount, 2); + await tester.tap(find.text('14')); + await tester.pump(kHapticFeedbackInterval); + expect(hapticFeedbackCount, 3); + }); + }); + + testWidgets('tap-select unselectable date does not vibrate', (WidgetTester tester) async { + await preparePicker(tester, (Future date) async { + await tester.tap(find.text('11')); + await tester.pump(kHapticFeedbackInterval); + expect(hapticFeedbackCount, 0); + await tester.tap(find.text('13')); + await tester.pump(kHapticFeedbackInterval); + expect(hapticFeedbackCount, 0); + await tester.tap(find.text('15')); + await tester.pump(kHapticFeedbackInterval); + expect(hapticFeedbackCount, 0); + }); + }); + + testWidgets('mode, year change vibrates', (WidgetTester tester) async { + await preparePicker(tester, (Future date) async { + await tester.tap(find.text('2017')); + await tester.pump(kHapticFeedbackInterval); + expect(hapticFeedbackCount, 1); + await tester.tap(find.text('2018')); + await tester.pump(kHapticFeedbackInterval); + expect(hapticFeedbackCount, 2); + }); + }); + }); }