ModernMemoires/test/text_switch_container_widge...

71 lines
2.0 KiB
Dart
Raw Normal View History

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:moody/views/settings_page/widgets/text_switch_container_widget.dart';
void main() {
group('TextSwitchContainer Tests', () {
testWidgets('displays left and right text correctly', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: TextSwitchContainer(
leftText: 'Left Text',
rightText: 'Right Text',
onTap: () {},
),
),
));
expect(find.text('Left Text'), findsOneWidget);
expect(find.text('Right Text'), findsOneWidget);
});
testWidgets('switch toggles correctly', (WidgetTester tester) async {
bool switchToggled = false;
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: TextSwitchContainer(
leftText: 'Left Text',
hasSwitch: true,
switchDefaultValue: false,
onTap: () {},
onSwitchToggle: (value) {
switchToggled = value;
},
),
),
));
expect(find.byType(CupertinoSwitch), findsOneWidget);
await tester.tap(find.byType(CupertinoSwitch));
await tester.pump();
expect(switchToggled, isTrue);
});
testWidgets('tap callback is executed', (WidgetTester tester) async {
bool tapCallbackExecuted = false;
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: SizedBox(
width: 300,
height: 50, // Provide adequate size
child: TextSwitchContainer(
leftText: 'Left Text',
onTap: () {
tapCallbackExecuted = true;
},
),
),
),
));
await tester.tap(find.text('Left Text'));
await tester.pump();
expect(tapCallbackExecuted, isTrue);
});
});
}