From 7698fe7f3b2baf0d3ed1562499ba01029f4fb818 Mon Sep 17 00:00:00 2001 From: Amos Date: Thu, 3 Aug 2023 17:09:45 +0800 Subject: [PATCH] Test: LightConfig, LightConfig, Scroll, onPointerCancel --- test/tilt_widget/tilt_config_light_test.dart | 30 ++++++++++ test/tilt_widget/tilt_config_shadow_test.dart | 37 ++++++++++++ test/tilt_widget/tilt_gestures_drag_test.dart | 59 +++++++++++++++++++ .../tilt_widget/tilt_gestures_touch_test.dart | 14 ++++- 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 test/tilt_widget/tilt_config_light_test.dart create mode 100644 test/tilt_widget/tilt_config_shadow_test.dart create mode 100644 test/tilt_widget/tilt_gestures_drag_test.dart diff --git a/test/tilt_widget/tilt_config_light_test.dart b/test/tilt_widget/tilt_config_light_test.dart new file mode 100644 index 0000000..2f92b78 --- /dev/null +++ b/test/tilt_widget/tilt_config_light_test.dart @@ -0,0 +1,30 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_tilt/flutter_tilt.dart'; + +void main() { + group('tilt LightConfig', () { + test('assert', () { + expect( + () => LightConfig( + minIntensity: 1.0, + maxIntensity: 0.0, + ), + throwsAssertionError, + ); + expect( + () => LightConfig( + minIntensity: -0.1, + maxIntensity: 1.0, + ), + throwsAssertionError, + ); + expect( + () => LightConfig( + minIntensity: 0.1, + maxIntensity: 1.1, + ), + throwsAssertionError, + ); + }); + }); +} diff --git a/test/tilt_widget/tilt_config_shadow_test.dart b/test/tilt_widget/tilt_config_shadow_test.dart new file mode 100644 index 0000000..fab778b --- /dev/null +++ b/test/tilt_widget/tilt_config_shadow_test.dart @@ -0,0 +1,37 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_tilt/flutter_tilt.dart'; + +void main() { + group('tilt LightConfig', () { + test('assert', () { + expect( + () => ShadowConfig(minIntensity: 1.0, maxIntensity: 0.0), + throwsAssertionError, + ); + expect( + () => ShadowConfig(minIntensity: -0.1, maxIntensity: 1.0), + throwsAssertionError, + ); + expect( + () => ShadowConfig(minIntensity: 0.1, maxIntensity: 1.1), + throwsAssertionError, + ); + expect( + () => ShadowConfig(offsetFactor: -0.1), + throwsAssertionError, + ); + expect( + () => ShadowConfig(spreadFactor: -0.1), + throwsAssertionError, + ); + expect( + () => ShadowConfig(minBlurRadius: 0.2, maxBlurRadius: 0.1), + throwsAssertionError, + ); + expect( + () => ShadowConfig(minBlurRadius: -0.1, maxBlurRadius: 1.0), + throwsAssertionError, + ); + }); + }); +} diff --git a/test/tilt_widget/tilt_gestures_drag_test.dart b/test/tilt_widget/tilt_gestures_drag_test.dart new file mode 100644 index 0000000..134fea6 --- /dev/null +++ b/test/tilt_widget/tilt_gestures_drag_test.dart @@ -0,0 +1,59 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_tilt/flutter_tilt.dart'; + +void main() { + group('tilt gestures drag', () { + testWidgets('scroll', (WidgetTester tester) async { + final Finder childFinder = find.text('Tilt'); + final Finder scrollFinder = find.byKey(const Key('scroll')); + final ScrollController scrollController = ScrollController(); + + /// 回调赋值 + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: ListView( + controller: scrollController, + children: const [ + Tilt( + key: Key('tilt_widget'), + child: SizedBox(width: 100, height: 100, child: Text('Tilt')), + ), + SizedBox(key: Key('scroll'), height: 100, width: 100), + SizedBox(height: 1000), + ], + ), + ), + ), + ); + + /// onVerticalDragUpdate + await tester.timedDrag( + childFinder, + const Offset(0.0, -100.0), + const Duration(milliseconds: 1000), + ); + await tester.pump(const Duration(milliseconds: 1000)); + expect(childFinder, findsOneWidget); + + /// onHorizontalDragUpdate + await tester.timedDrag( + childFinder, + const Offset(-100.0, 0.0), + const Duration(milliseconds: 1000), + ); + await tester.pump(const Duration(milliseconds: 1000)); + expect(childFinder, findsOneWidget); + + /// scroll + await tester.timedDrag( + scrollFinder, + const Offset(0.0, -100.0), + const Duration(milliseconds: 1000), + ); + await tester.pump(const Duration(milliseconds: 1000)); + expect(childFinder, findsNothing); + }); + }); +} diff --git a/test/tilt_widget/tilt_gestures_touch_test.dart b/test/tilt_widget/tilt_gestures_touch_test.dart index 69a00a0..943dc83 100644 --- a/test/tilt_widget/tilt_gestures_touch_test.dart +++ b/test/tilt_widget/tilt_gestures_touch_test.dart @@ -4,11 +4,12 @@ import 'package:flutter_tilt/flutter_tilt.dart'; import 'tilt_widget.dart'; void main() { - group('tilt gestures touch ', () { + group('tilt gestures touch', () { const TiltConfig tiltConfig = TiltConfig(); final Finder tiltScaffoldFinder = find.byKey(const Key('tilt_scaffold')); final Finder tiltWidgetFinder = find.byKey(const Key('tilt_widget')); final Finder childFinder = find.text('Tilt'); + final TestPointer testPointer = TestPointer(); testWidgets('gestures move leave', (WidgetTester tester) async { TiltDataModel? _moveTiltData; @@ -65,6 +66,17 @@ void main() { expect(_leaveGesturesType, GesturesType.touch); expect(_leaveTiltData, _leaveTiltDataExpect); }); + testWidgets('onPointerCancel', (WidgetTester tester) async { + await tester.pumpWidget(const TiltWidget()); + + final Offset location = tester.getCenter(tiltWidgetFinder); + await tester.sendEventToBinding(testPointer.down(location)); + await tester.sendEventToBinding(testPointer.cancel()); + await tester.pumpAndSettle(); + expect(childFinder, findsOneWidget); + + await tester.sendEventToBinding(testPointer.removePointer()); + }); testWidgets('move top', (WidgetTester tester) async { TiltDataModel? _tiltData; GesturesType? _gesturesType;