Skip to content

Commit

Permalink
Merge pull request #667 from cypherstack/ui-fixes
Browse files Browse the repository at this point in the history
fix tests
  • Loading branch information
julian-CStack authored Sep 12, 2023
2 parents 610c267 + 4d537d8 commit 88462c1
Show file tree
Hide file tree
Showing 10 changed files with 344 additions and 5 deletions.
7 changes: 7 additions & 0 deletions test/notifications/notification_card_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
Expand All @@ -7,6 +9,7 @@ import 'package:mockito/mockito.dart';
import 'package:stackwallet/models/isar/stack_theme.dart';
import 'package:stackwallet/models/notification_model.dart';
import 'package:stackwallet/notifications/notification_card.dart';
import 'package:stackwallet/themes/coin_icon_provider.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/themes/theme_service.dart';
import 'package:stackwallet/utilities/assets.dart';
Expand Down Expand Up @@ -47,6 +50,10 @@ void main() {
ProviderScope(
overrides: [
pThemeService.overrideWithValue(mockThemeService),
coinIconProvider.overrideWithProvider(
(argument) => Provider<String>((_) =>
"${Directory.current.path}/test/sample_data/light/assets/dummy.svg"),
),
],
child: MaterialApp(
theme: ThemeData(
Expand Down
13 changes: 12 additions & 1 deletion test/pages/send_view/send_view_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
Expand All @@ -14,6 +16,7 @@ import 'package:stackwallet/services/locale_service.dart';
import 'package:stackwallet/services/node_service.dart';
import 'package:stackwallet/services/wallets.dart';
import 'package:stackwallet/services/wallets_service.dart';
import 'package:stackwallet/themes/coin_icon_provider.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/themes/theme_service.dart';
import 'package:stackwallet/utilities/amount/amount_unit.dart';
Expand Down Expand Up @@ -80,6 +83,10 @@ void main() {
.overrideWithValue(mockLocaleService),
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
pThemeService.overrideWithValue(mockThemeService),
coinIconProvider.overrideWithProvider(
(argument) => Provider<String>((_) =>
"${Directory.current.path}/test/sample_data/light/assets/dummy.svg"),
),
// previewTxButtonStateProvider
],
child: MaterialApp(
Expand Down Expand Up @@ -157,7 +164,11 @@ void main() {
localeServiceChangeNotifierProvider
.overrideWithValue(mockLocaleService),
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
pThemeService.overrideWithValue(mockThemeService)
pThemeService.overrideWithValue(mockThemeService),
coinIconProvider.overrideWithProvider(
(argument) => Provider<String>((_) =>
"${Directory.current.path}/test/sample_data/light/assets/dummy.svg"),
),
// previewTxButtonStateProvider
],
child: MaterialApp(
Expand Down
17 changes: 16 additions & 1 deletion test/widget_tests/managed_favorite_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand All @@ -14,6 +16,7 @@ import 'package:stackwallet/services/locale_service.dart';
import 'package:stackwallet/services/node_service.dart';
import 'package:stackwallet/services/wallets.dart';
import 'package:stackwallet/services/wallets_service.dart';
import 'package:stackwallet/themes/coin_icon_provider.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/themes/theme_service.dart';
import 'package:stackwallet/utilities/amount/amount.dart';
Expand Down Expand Up @@ -89,6 +92,10 @@ void main() {
walletsChangeNotifierProvider.overrideWithValue(wallets),
pThemeService.overrideWithValue(mockThemeService),
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
coinIconProvider.overrideWithProvider(
(argument) => Provider<String>((_) =>
"${Directory.current.path}/test/sample_data/light/assets/dummy.svg"),
),
],
child: MaterialApp(
theme: ThemeData(
Expand Down Expand Up @@ -176,6 +183,10 @@ void main() {
walletsServiceChangeNotifierProvider
.overrideWithValue(mockWalletsService),
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
coinIconProvider.overrideWithProvider(
(argument) => Provider<String>((_) =>
"${Directory.current.path}/test/sample_data/light/assets/dummy.svg"),
),
],
child: MaterialApp(
theme: ThemeData(
Expand Down Expand Up @@ -261,7 +272,11 @@ void main() {
pThemeService.overrideWithValue(mockThemeService),
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
walletsServiceChangeNotifierProvider
.overrideWithValue(mockWalletsService)
.overrideWithValue(mockWalletsService),
coinIconProvider.overrideWithProvider(
(argument) => Provider<String>((_) =>
"${Directory.current.path}/test/sample_data/light/assets/dummy.svg"),
),
],
child: MaterialApp(
theme: ThemeData(
Expand Down
7 changes: 7 additions & 0 deletions test/widget_tests/table_view/table_view_row_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
Expand All @@ -12,6 +14,7 @@ import 'package:stackwallet/services/coins/coin_service.dart';
import 'package:stackwallet/services/coins/manager.dart';
import 'package:stackwallet/services/wallets.dart';
import 'package:stackwallet/services/wallets_service.dart';
import 'package:stackwallet/themes/coin_icon_provider.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/themes/theme_service.dart';
import 'package:stackwallet/utilities/amount/amount.dart';
Expand Down Expand Up @@ -72,6 +75,10 @@ void main() {
overrides: [
walletsChangeNotifierProvider.overrideWithValue(mockWallet),
pThemeService.overrideWithValue(mockThemeService),
coinIconProvider.overrideWithProvider(
(argument) => Provider<String>((_) =>
"${Directory.current.path}/test/sample_data/light/assets/dummy.svg"),
),
],
child: MaterialApp(
theme: ThemeData(
Expand Down
20 changes: 20 additions & 0 deletions test/widget_tests/trade_card_test.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/models/isar/stack_theme.dart';
import 'package:stackwallet/themes/coin_icon_provider.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/themes/theme_providers.dart';
import 'package:stackwallet/themes/theme_service.dart';
import 'package:stackwallet/widgets/trade_card.dart';

Expand All @@ -14,10 +18,17 @@ import 'trade_card_test.mocks.dart';

@GenerateMocks([
ThemeService,
IThemeAssets,
])
void main() {
testWidgets("Test Trade card builds", (widgetTester) async {
final mockThemeService = MockThemeService();
final mockIThemeAssets = MockIThemeAssets();

when(mockIThemeAssets.txExchangeFailed).thenAnswer(
(_) =>
"${Directory.current.path}/test/sample_data/light/assets/dummy.svg",
);
when(mockThemeService.getTheme(themeId: "light")).thenAnswer(
(_) => StackTheme.fromJson(
json: lightThemeJsonMap,
Expand Down Expand Up @@ -51,6 +62,15 @@ void main() {
ProviderScope(
overrides: [
pThemeService.overrideWithValue(mockThemeService),
themeAssetsProvider.overrideWithProvider(
StateProvider(
(ref) => mockIThemeAssets,
),
),
coinIconProvider.overrideWithProvider(
(argument) => Provider<String>((_) =>
"${Directory.current.path}/test/sample_data/light/assets/dummy.svg"),
),
],
child: MaterialApp(
theme: ThemeData(
Expand Down
100 changes: 100 additions & 0 deletions test/widget_tests/trade_card_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,103 @@ class MockThemeService extends _i1.Mock implements _i3.ThemeService {
{#themeId: themeId},
)) as _i4.StackTheme?);
}

/// A class which mocks [IThemeAssets].
///
/// See the documentation for Mockito's code generation for more information.
class MockIThemeAssets extends _i1.Mock implements _i4.IThemeAssets {
MockIThemeAssets() {
_i1.throwOnMissingStub(this);
}

@override
String get bellNew => (super.noSuchMethod(
Invocation.getter(#bellNew),
returnValue: '',
) as String);
@override
String get buy => (super.noSuchMethod(
Invocation.getter(#buy),
returnValue: '',
) as String);
@override
String get exchange => (super.noSuchMethod(
Invocation.getter(#exchange),
returnValue: '',
) as String);
@override
String get personaIncognito => (super.noSuchMethod(
Invocation.getter(#personaIncognito),
returnValue: '',
) as String);
@override
String get personaEasy => (super.noSuchMethod(
Invocation.getter(#personaEasy),
returnValue: '',
) as String);
@override
String get stack => (super.noSuchMethod(
Invocation.getter(#stack),
returnValue: '',
) as String);
@override
String get stackIcon => (super.noSuchMethod(
Invocation.getter(#stackIcon),
returnValue: '',
) as String);
@override
String get receive => (super.noSuchMethod(
Invocation.getter(#receive),
returnValue: '',
) as String);
@override
String get receivePending => (super.noSuchMethod(
Invocation.getter(#receivePending),
returnValue: '',
) as String);
@override
String get receiveCancelled => (super.noSuchMethod(
Invocation.getter(#receiveCancelled),
returnValue: '',
) as String);
@override
String get send => (super.noSuchMethod(
Invocation.getter(#send),
returnValue: '',
) as String);
@override
String get sendPending => (super.noSuchMethod(
Invocation.getter(#sendPending),
returnValue: '',
) as String);
@override
String get sendCancelled => (super.noSuchMethod(
Invocation.getter(#sendCancelled),
returnValue: '',
) as String);
@override
String get themeSelector => (super.noSuchMethod(
Invocation.getter(#themeSelector),
returnValue: '',
) as String);
@override
String get themePreview => (super.noSuchMethod(
Invocation.getter(#themePreview),
returnValue: '',
) as String);
@override
String get txExchange => (super.noSuchMethod(
Invocation.getter(#txExchange),
returnValue: '',
) as String);
@override
String get txExchangePending => (super.noSuchMethod(
Invocation.getter(#txExchangePending),
returnValue: '',
) as String);
@override
String get txExchangeFailed => (super.noSuchMethod(
Invocation.getter(#txExchangeFailed),
returnValue: '',
) as String);
}
Loading

0 comments on commit 88462c1

Please sign in to comment.