stack_wallet/test/widget_tests/stack_dialog_test.dart

101 lines
2.9 KiB
Dart
Raw Normal View History

2022-10-18 17:15:14 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
2023-05-12 20:02:04 +00:00
import 'package:stackwallet/models/isar/stack_theme.dart';
import 'package:stackwallet/themes/stack_colors.dart';
2022-10-18 17:15:14 +00:00
import 'package:stackwallet/widgets/stack_dialog.dart';
2023-05-12 20:02:04 +00:00
import '../sample_data/theme_json.dart';
2022-10-18 17:15:14 +00:00
void main() {
testWidgets("test StackDialogBase", (widgetTester) async {
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
2023-05-08 17:59:00 +00:00
StackColors.fromStackColorTheme(
StackTheme.fromJson(
2023-05-12 20:02:04 +00:00
json: lightThemeJsonMap,
2023-05-08 17:59:00 +00:00
),
),
2022-10-18 17:15:14 +00:00
],
),
home: const Material(
child: StackDialogBase(),
),
),
);
expect(find.byType(StackDialogBase), findsOneWidget);
});
testWidgets("test StackDialog", (widgetTester) async {
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
2023-05-08 17:59:00 +00:00
StackColors.fromStackColorTheme(
StackTheme.fromJson(
2023-05-12 20:02:04 +00:00
json: lightThemeJsonMap,
2023-05-08 17:59:00 +00:00
),
),
2022-10-18 17:15:14 +00:00
],
),
home: const Material(
child: StackDialog(
title: "Some Dialog title",
message: "Some Message",
leftButton: TextButton(onPressed: null, child: Text("Left Button")),
rightButton:
TextButton(onPressed: null, child: Text("Right Button")),
),
),
),
);
expect(find.byType(StackDialogBase), findsOneWidget);
expect(find.byType(StackDialog), findsOneWidget);
expect(find.text("Some Dialog title"), findsOneWidget);
expect(find.text("Some Message"), findsOneWidget);
expect(find.text("Left Button"), findsOneWidget);
expect(find.text("Right Button"), findsOneWidget);
});
testWidgets("Test StackDialogOk", (widgetTester) async {
2024-01-26 23:42:07 +00:00
final navigatorKey = GlobalKey<NavigatorState>();
2022-10-18 17:15:14 +00:00
2024-01-26 23:42:07 +00:00
await widgetTester.pumpWidget(
ProviderScope(
2022-10-18 17:15:14 +00:00
overrides: [],
child: MaterialApp(
2024-01-26 23:42:07 +00:00
navigatorKey: navigatorKey,
2022-10-18 17:15:14 +00:00
theme: ThemeData(
extensions: [
2023-05-08 17:59:00 +00:00
StackColors.fromStackColorTheme(
StackTheme.fromJson(
2023-05-12 20:02:04 +00:00
json: lightThemeJsonMap,
2023-05-08 17:59:00 +00:00
),
),
2022-10-18 17:15:14 +00:00
],
),
2024-01-26 23:42:07 +00:00
home: StackOkDialog(
title: "Some random title",
message: "Some message",
leftButton: TextButton(
onPressed: () {},
child: const Text("I am left"),
2022-10-18 17:15:14 +00:00
),
),
2024-01-26 23:42:07 +00:00
),
),
);
2022-10-18 17:15:14 +00:00
2024-01-26 23:42:07 +00:00
final button = find.text('I am left');
await widgetTester.tap(button);
2022-10-18 17:15:14 +00:00
await widgetTester.pumpAndSettle();
2024-01-26 23:42:07 +00:00
final navigatorState = navigatorKey.currentState;
expect(navigatorState?.overlay, isNotNull);
2022-10-18 17:15:14 +00:00
});
}