stack_wallet/test/widget_tests/desktop/desktop_scaffold_test.dart

133 lines
3.7 KiB
Dart
Raw Normal View History

2022-10-20 10:49:45 +00:00
import 'package:flutter/material.dart';
2023-05-12 20:02:04 +00:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
2022-10-20 10:49:45 +00:00
import 'package:flutter_test/flutter_test.dart';
2023-05-12 20:02:04 +00:00
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:stackwallet/models/isar/stack_theme.dart';
import 'package:stackwallet/themes/stack_colors.dart';
2023-05-12 20:02:04 +00:00
import 'package:stackwallet/themes/theme_service.dart';
2022-10-20 10:49:45 +00:00
import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart';
2023-05-12 20:02:04 +00:00
import '../../sample_data/theme_json.dart';
import 'desktop_scaffold_test.mocks.dart';
@GenerateMocks([
ThemeService,
])
2022-10-20 10:49:45 +00:00
void main() {
testWidgets("test DesktopScaffold", (widgetTester) async {
final key = UniqueKey();
2023-05-12 20:02:04 +00:00
final mockThemeService = MockThemeService();
when(mockThemeService.getTheme(themeId: "light")).thenAnswer(
(_) => StackTheme.fromJson(
json: lightThemeJsonMap,
applicationThemesDirectoryPath: "test",
),
);
2022-10-20 10:49:45 +00:00
await widgetTester.pumpWidget(
2023-05-12 20:02:04 +00:00
ProviderScope(
overrides: [
pThemeService.overrideWithValue(mockThemeService),
],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
StackTheme.fromJson(
json: lightThemeJsonMap,
applicationThemesDirectoryPath: "test",
),
2023-05-08 17:59:00 +00:00
),
2023-05-12 20:02:04 +00:00
],
),
home: Material(
child: DesktopScaffold(
key: key,
body: const SizedBox(),
2023-05-08 17:59:00 +00:00
),
2022-10-20 10:49:45 +00:00
),
),
),
);
});
testWidgets("Test MasterScaffold for non desktop", (widgetTester) async {
final key = UniqueKey();
2023-05-12 20:02:04 +00:00
final mockThemeService = MockThemeService();
when(mockThemeService.getTheme(themeId: "light")).thenAnswer(
(_) => StackTheme.fromJson(
json: lightThemeJsonMap,
applicationThemesDirectoryPath: "test",
),
);
2022-10-20 10:49:45 +00:00
await widgetTester.pumpWidget(
2023-05-12 20:02:04 +00:00
ProviderScope(
overrides: [
pThemeService.overrideWithValue(mockThemeService),
],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
StackTheme.fromJson(
json: lightThemeJsonMap,
applicationThemesDirectoryPath: "test",
),
2023-05-08 17:59:00 +00:00
),
2023-05-12 20:02:04 +00:00
],
),
home: Material(
child: MasterScaffold(
key: key,
body: const SizedBox(),
appBar: AppBar(),
isDesktop: false,
2023-05-08 17:59:00 +00:00
),
2022-10-20 10:49:45 +00:00
),
),
),
);
});
testWidgets("Test MasterScaffold for desktop", (widgetTester) async {
final key = UniqueKey();
2023-05-12 20:02:04 +00:00
final mockThemeService = MockThemeService();
when(mockThemeService.getTheme(themeId: "light")).thenAnswer(
(_) => StackTheme.fromJson(
json: lightThemeJsonMap,
applicationThemesDirectoryPath: "test",
),
);
2022-10-20 10:49:45 +00:00
await widgetTester.pumpWidget(
2023-05-12 20:02:04 +00:00
ProviderScope(
overrides: [
pThemeService.overrideWithValue(mockThemeService),
],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
StackTheme.fromJson(
json: lightThemeJsonMap,
applicationThemesDirectoryPath: "test",
),
2023-05-08 17:59:00 +00:00
),
2023-05-12 20:02:04 +00:00
],
),
home: Material(
child: MasterScaffold(
key: key,
body: const SizedBox(),
appBar: AppBar(),
isDesktop: true,
2023-05-08 17:59:00 +00:00
),
2022-10-20 10:49:45 +00:00
),
),
),
);
});
}