ModernMemoires/test/question_slider_widget_test...

70 lines
2.2 KiB
Dart
Raw Permalink Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:moody/utils/widgets/question_slider_widget.dart';
void main() {
testWidgets('QuestionSliderWidget displays the initial value', (WidgetTester tester) async {
const testKey = Key('slider');
final DateTime date = DateTime.now();
const String questionText = "How are you feeling today?";
const double initialSliderValue = 50.0;
const bool isSliderEnabled = true;
const Color sliderColor = Colors.blue;
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: QuestionSliderWidget(
key: testKey,
date: date,
questionText: questionText,
initialSliderValue: initialSliderValue,
isSliderEnabled: isSliderEnabled,
onSliderChanged: (SliderChangeData data) {},
onSliderPositionChanged: (double position) {},
sliderColor: sliderColor,
),
),
));
// Verify that the initial slider value is set.
final Slider sliderWidget = tester.firstWidget(find.byType(Slider));
expect(sliderWidget.value, initialSliderValue);
});
testWidgets('QuestionSliderWidget updates value on slide', (WidgetTester tester) async {
const testKey = Key('slider');
final DateTime date = DateTime.now();
const String questionText = "How are you feeling today?";
const double initialSliderValue = 50.0;
bool sliderMoved = false;
const Color sliderColor = Colors.blue;
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: QuestionSliderWidget(
key: testKey,
date: date,
questionText: questionText,
initialSliderValue: initialSliderValue,
isSliderEnabled: true,
onSliderChanged: (SliderChangeData data) {
sliderMoved = true;
},
onSliderPositionChanged: (double position) {},
sliderColor: sliderColor,
),
),
));
// Move the slider.
await tester.drag(find.byType(Slider), const Offset(100, 0));
await tester.pumpAndSettle();
// Verify that the slider moved callback was triggered.
expect(sliderMoved, true);
});
}