-
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1141 from nrallakis/main
Add widget tests for FormBuilderRangeSlider #1090
- Loading branch information
Showing
2 changed files
with
66 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_form_builder/flutter_form_builder.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import 'form_builder_tester.dart'; | ||
|
||
void main() { | ||
group('FormBuilderRangeSlider --', () { | ||
testWidgets('basic', (WidgetTester tester) async { | ||
const widgetName = 'formBuilderRangeSlider'; | ||
final testWidget = FormBuilderRangeSlider( | ||
name: widgetName, | ||
min: 10.0, | ||
max: 20.0, | ||
); | ||
await tester.pumpWidget(buildTestableFieldWidget(testWidget)); | ||
|
||
expect(formSave(), isTrue); | ||
expect(formValue<RangeValues?>(widgetName), | ||
equals(const RangeValues(10.0, 10.0))); | ||
|
||
// Inspired by https://github.com/flutter/flutter/blob/master/packages/flutter/test/material/range_slider_test.dart | ||
// Tap at the center of the slider. | ||
final Offset topLeft = | ||
tester.getTopLeft(find.byType(RangeSlider)).translate(24, 0); | ||
final Offset bottomRight = | ||
tester.getBottomRight(find.byType(RangeSlider)).translate(-24, 0); | ||
final Offset rightTarget = topLeft + (bottomRight - topLeft) * 0.5; | ||
await tester.tapAt(rightTarget); | ||
|
||
expect(formSave(), isTrue); | ||
expect(formValue<RangeValues>(widgetName), const RangeValues(10.0, 15.0)); | ||
}); | ||
|
||
testWidgets('initial value', (WidgetTester tester) async { | ||
const widgetName = 'formBuilderRangeSlider'; | ||
final testWidget = FormBuilderRangeSlider( | ||
name: widgetName, | ||
min: 10.0, | ||
max: 20.0, | ||
initialValue: const RangeValues(14.0, 18.0), | ||
); | ||
await tester.pumpWidget(buildTestableFieldWidget(testWidget)); | ||
|
||
expect(formSave(), isTrue); | ||
expect(formValue<RangeValues?>(widgetName), | ||
equals(const RangeValues(14.0, 18.0))); | ||
|
||
// Inspired by https://github.com/flutter/flutter/blob/master/packages/flutter/test/material/range_slider_test.dart | ||
// Tap a small offset after the start of the slider. | ||
final Offset topLeft = | ||
tester.getTopLeft(find.byType(RangeSlider)).translate(24, 0); | ||
final Offset bottomRight = | ||
tester.getBottomRight(find.byType(RangeSlider)).translate(-24, 0); | ||
final Offset leftTarget = topLeft + (bottomRight - topLeft) * 0.1; | ||
await tester.tapAt(leftTarget); | ||
|
||
expect(formSave(), isTrue); | ||
expect(formValue<RangeValues>(widgetName), const RangeValues(11.0, 18.0)); | ||
}); | ||
}); | ||
} |