-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
189 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,118 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:numberpicker/numberpicker.dart'; | ||
import 'test_utils.dart'; | ||
|
||
void main() { | ||
testWidgets('Integer small scroll up works', (WidgetTester tester) async { | ||
await _testNumberPicker( | ||
tester: tester, | ||
minValue: 1, | ||
maxValue: 10, | ||
initialValue: 5, | ||
scrollBy: 2, | ||
expectedValue: 7); | ||
await testNumberPicker( | ||
tester: tester, | ||
minValue: 1, | ||
maxValue: 10, | ||
initialValue: 5, | ||
scrollBy: 2, | ||
expectedValue: 7, | ||
infiniteLoop: true, | ||
); | ||
}); | ||
|
||
testWidgets('Integer small scroll down works', (WidgetTester tester) async { | ||
await _testNumberPicker( | ||
tester: tester, | ||
minValue: 1, | ||
maxValue: 10, | ||
initialValue: 5, | ||
scrollBy: -2, | ||
expectedValue: 3); | ||
await testNumberPicker( | ||
tester: tester, | ||
minValue: 1, | ||
maxValue: 10, | ||
initialValue: 5, | ||
scrollBy: -2, | ||
expectedValue: 3, | ||
infiniteLoop: true, | ||
); | ||
}); | ||
|
||
testWidgets('Integer overscroll over max value', (WidgetTester tester) async { | ||
await _testNumberPicker( | ||
tester: tester, | ||
minValue: 1, | ||
maxValue: 5, | ||
initialValue: 5, | ||
scrollBy: 1, | ||
expectedValue: 1); | ||
await testNumberPicker( | ||
tester: tester, | ||
minValue: 1, | ||
maxValue: 5, | ||
initialValue: 5, | ||
scrollBy: 1, | ||
expectedValue: 1, | ||
infiniteLoop: true, | ||
); | ||
}); | ||
|
||
testWidgets('Integer overscroll under min value', (WidgetTester tester) async { | ||
await _testNumberPicker( | ||
tester: tester, | ||
minValue: 1, | ||
maxValue: 5, | ||
initialValue: 1, | ||
scrollBy: -1, | ||
expectedValue: 5); | ||
testWidgets('Integer overscroll under min value', | ||
(WidgetTester tester) async { | ||
await testNumberPicker( | ||
tester: tester, | ||
minValue: 1, | ||
maxValue: 5, | ||
initialValue: 1, | ||
scrollBy: -1, | ||
expectedValue: 5, | ||
infiniteLoop: true, | ||
); | ||
}); | ||
|
||
testWidgets('Step works', (WidgetTester tester) async { | ||
await _testNumberPicker( | ||
tester: tester, | ||
minValue: 0, | ||
maxValue: 6, | ||
step: 3, | ||
initialValue: 0, | ||
scrollBy: 2, | ||
expectedValue: 6); | ||
await testNumberPicker( | ||
tester: tester, | ||
minValue: 0, | ||
maxValue: 6, | ||
step: 3, | ||
initialValue: 0, | ||
scrollBy: 2, | ||
expectedValue: 6, | ||
infiniteLoop: true, | ||
); | ||
}); | ||
|
||
testWidgets('Step cuts max value', (WidgetTester tester) async { | ||
await _testNumberPicker( | ||
tester: tester, | ||
minValue: 0, | ||
maxValue: 5, | ||
step: 3, | ||
initialValue: 0, | ||
scrollBy: 2, | ||
expectedValue: 0); | ||
await testNumberPicker( | ||
tester: tester, | ||
minValue: 0, | ||
maxValue: 5, | ||
step: 3, | ||
initialValue: 0, | ||
scrollBy: 2, | ||
expectedValue: 0, | ||
infiniteLoop: true, | ||
); | ||
}); | ||
|
||
testWidgets('Min value==step, force animate', (WidgetTester tester) async { | ||
await _testNumberPicker( | ||
tester: tester, | ||
minValue: 10, | ||
maxValue: 50, | ||
step: 10, | ||
initialValue: 10, | ||
scrollBy: 2, | ||
expectedValue: 30, | ||
animateToItself: true); | ||
await testNumberPicker( | ||
tester: tester, | ||
minValue: 10, | ||
maxValue: 50, | ||
step: 10, | ||
initialValue: 10, | ||
scrollBy: 2, | ||
expectedValue: 30, | ||
animateToItself: true, | ||
infiniteLoop: true, | ||
); | ||
}); | ||
|
||
testWidgets('Force animate works', (WidgetTester tester) async { | ||
await _testNumberPicker( | ||
tester: tester, | ||
minValue: 10, | ||
maxValue: 50, | ||
initialValue: 10, | ||
scrollBy: 13, | ||
expectedValue: 23, | ||
animateToItself: true); | ||
await testNumberPicker( | ||
tester: tester, | ||
minValue: 10, | ||
maxValue: 50, | ||
initialValue: 10, | ||
scrollBy: 13, | ||
expectedValue: 23, | ||
animateToItself: true, | ||
infiniteLoop: true, | ||
); | ||
}); | ||
} | ||
|
||
Future<NumberPicker> _testNumberPicker( | ||
{WidgetTester tester, | ||
int minValue, | ||
int maxValue, | ||
int initialValue, | ||
int scrollBy, | ||
int step = 1, | ||
int expectedValue, | ||
bool animateToItself = false}) async { | ||
int value = initialValue; | ||
NumberPicker picker; | ||
|
||
await tester.pumpWidget( | ||
StatefulBuilder(builder: (BuildContext context, StateSetter setState) { | ||
picker = NumberPicker.integer( | ||
initialValue: value, | ||
minValue: minValue, | ||
maxValue: maxValue, | ||
step: step, | ||
testWidgets('Zero pad works', (WidgetTester tester) async { | ||
await testMultipleValuesInPicker( | ||
tester: tester, | ||
minValue: 0, | ||
maxValue: 10, | ||
initialValue: 9, | ||
zeroPad: true, | ||
scrollBy: 1, | ||
infiniteLoop: true, | ||
onChanged: (newValue) => setState(() => value = newValue), | ||
); | ||
return MaterialApp( | ||
home: Scaffold( | ||
body: picker, | ||
), | ||
); | ||
}), | ||
); | ||
expect(value, equals(initialValue)); | ||
|
||
await _scrollNumberPicker(Offset(0.0, 0.0), tester, scrollBy); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(value, equals(expectedValue)); | ||
|
||
if (animateToItself) { | ||
expect(picker.selectedIntValue, equals(expectedValue)); | ||
await picker.animateInt(picker.selectedIntValue); | ||
await tester.pumpAndSettle(); | ||
expect(picker.selectedIntValue, equals(expectedValue)); | ||
} | ||
return picker; | ||
} | ||
|
||
_scrollNumberPicker( | ||
Offset pickerPosition, WidgetTester tester, int scrollBy) async { | ||
Offset pickerCenter = Offset( | ||
pickerPosition.dx + NumberPicker.kDefaultListViewCrossAxisSize / 2, | ||
pickerPosition.dy + 1.5 * NumberPicker.kDefaultItemExtent, | ||
); | ||
final TestGesture testGesture = await tester.startGesture(pickerCenter); | ||
await testGesture.moveBy(Offset( | ||
0.0, | ||
-scrollBy * NumberPicker.kDefaultItemExtent, | ||
)); | ||
} | ||
expectedDisplayValues: ['09', '10', '00']); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.