mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-16 17:27:39 +00:00
initial ExchangeView screen tests
This commit is contained in:
parent
71826d4da3
commit
88af88740b
2 changed files with 439 additions and 0 deletions
122
test/screen_tests/exchange/exchange_view_test.dart
Normal file
122
test/screen_tests/exchange/exchange_view_test.dart
Normal file
|
@ -0,0 +1,122 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:stackwallet/models/exchange/change_now/exchange_transaction.dart';
|
||||
import 'package:stackwallet/pages/exchange_view/exchange_view.dart';
|
||||
import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.dart';
|
||||
import 'package:stackwallet/providers/global/prefs_provider.dart';
|
||||
import 'package:stackwallet/providers/global/trades_service_provider.dart';
|
||||
import 'package:stackwallet/services/change_now/change_now.dart';
|
||||
import 'package:stackwallet/services/trade_notes_service.dart';
|
||||
import 'package:stackwallet/services/trade_service.dart';
|
||||
import 'package:stackwallet/utilities/prefs.dart';
|
||||
import 'package:stackwallet/widgets/trade_card.dart';
|
||||
|
||||
import 'exchange_view_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([Prefs, TradesService, TradeNotesService, ChangeNow])
|
||||
void main() {
|
||||
testWidgets("ExchangeView builds correctly with no trade history",
|
||||
(widgetTester) async {
|
||||
final prefs = MockPrefs();
|
||||
final tradeService = MockTradesService();
|
||||
|
||||
when(prefs.exchangeRateType)
|
||||
.thenAnswer((realInvocation) => ExchangeRateType.estimated);
|
||||
|
||||
when(tradeService.trades).thenAnswer((realInvocation) => []);
|
||||
|
||||
await widgetTester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
prefsChangeNotifierProvider
|
||||
.overrideWithProvider(ChangeNotifierProvider((ref) => prefs)),
|
||||
tradesServiceProvider.overrideWithProvider(
|
||||
ChangeNotifierProvider((ref) => tradeService)),
|
||||
],
|
||||
child: const MaterialApp(
|
||||
home: Material(child: ExchangeView()),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await widgetTester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(TextFormField), findsNWidgets(2));
|
||||
expect(find.byType(SvgPicture), findsNWidgets(6));
|
||||
|
||||
expect(find.text("You will send"), findsOneWidget);
|
||||
expect(find.text("You will receive"), findsOneWidget);
|
||||
expect(find.text("Exchange"), findsOneWidget);
|
||||
expect(find.text("Estimated rate"), findsOneWidget);
|
||||
expect(find.text("Trades"), findsOneWidget);
|
||||
expect(find.text("-"), findsNWidgets(2));
|
||||
|
||||
expect(find.text("Trades will appear here"), findsOneWidget);
|
||||
|
||||
expect(find.byType(TextButton), findsNWidgets(2));
|
||||
expect(find.byType(TradeCard), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets("ExchangeView builds correctly with one trade history",
|
||||
(widgetTester) async {
|
||||
final prefs = MockPrefs();
|
||||
final tradeService = MockTradesService();
|
||||
|
||||
when(prefs.exchangeRateType)
|
||||
.thenAnswer((realInvocation) => ExchangeRateType.estimated);
|
||||
|
||||
when(tradeService.trades).thenAnswer((realInvocation) => [
|
||||
ExchangeTransaction(
|
||||
id: "some id",
|
||||
payinAddress: "adr",
|
||||
payoutAddress: "adr2",
|
||||
payinExtraId: "",
|
||||
payoutExtraId: "",
|
||||
fromCurrency: "btc",
|
||||
toCurrency: "xmr",
|
||||
amount: "42",
|
||||
refundAddress: "",
|
||||
refundExtraId: "refundExtraId",
|
||||
payoutExtraIdName: "",
|
||||
uuid: "dhjkfg872tr8yugsd",
|
||||
date: DateTime(1999),
|
||||
statusString: "Waiting",
|
||||
statusObject: null)
|
||||
]);
|
||||
|
||||
await widgetTester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
prefsChangeNotifierProvider
|
||||
.overrideWithProvider(ChangeNotifierProvider((ref) => prefs)),
|
||||
tradesServiceProvider.overrideWithProvider(
|
||||
ChangeNotifierProvider((ref) => tradeService)),
|
||||
],
|
||||
child: const MaterialApp(
|
||||
home: Material(child: ExchangeView()),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await widgetTester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(TextFormField), findsNWidgets(2));
|
||||
expect(find.byType(SvgPicture), findsNWidgets(7));
|
||||
|
||||
expect(find.text("You will send"), findsOneWidget);
|
||||
expect(find.text("You will receive"), findsOneWidget);
|
||||
expect(find.text("Exchange"), findsOneWidget);
|
||||
expect(find.text("Estimated rate"), findsOneWidget);
|
||||
expect(find.text("Trades"), findsOneWidget);
|
||||
expect(find.text("-"), findsNWidgets(2));
|
||||
|
||||
expect(find.text("Trades will appear here"), findsNothing);
|
||||
|
||||
expect(find.byType(TextButton), findsNWidgets(2));
|
||||
expect(find.byType(TradeCard), findsOneWidget);
|
||||
});
|
||||
}
|
317
test/screen_tests/exchange/exchange_view_test.mocks.dart
Normal file
317
test/screen_tests/exchange/exchange_view_test.mocks.dart
Normal file
|
@ -0,0 +1,317 @@
|
|||
// Mocks generated by Mockito 5.2.0 from annotations
|
||||
// in stackwallet/test/screen_tests/exchange/exchange_view_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
import 'dart:async' as _i6;
|
||||
import 'dart:ui' as _i7;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:stackwallet/models/exchange/change_now/exchange_transaction.dart'
|
||||
as _i9;
|
||||
import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.dart'
|
||||
as _i4;
|
||||
import 'package:stackwallet/services/change_now/change_now.dart' as _i11;
|
||||
import 'package:stackwallet/services/trade_notes_service.dart' as _i10;
|
||||
import 'package:stackwallet/services/trade_service.dart' as _i8;
|
||||
import 'package:stackwallet/utilities/enums/backup_frequency_type.dart' as _i5;
|
||||
import 'package:stackwallet/utilities/enums/sync_type_enum.dart' as _i3;
|
||||
import 'package:stackwallet/utilities/prefs.dart' as _i2;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
// ignore_for_file: avoid_setters_without_getters
|
||||
// ignore_for_file: comment_references
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: invalid_use_of_visible_for_testing_member
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
// ignore_for_file: unnecessary_parenthesis
|
||||
// ignore_for_file: camel_case_types
|
||||
|
||||
/// A class which mocks [Prefs].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockPrefs extends _i1.Mock implements _i2.Prefs {
|
||||
MockPrefs() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isInitialized =>
|
||||
(super.noSuchMethod(Invocation.getter(#isInitialized), returnValue: false)
|
||||
as bool);
|
||||
@override
|
||||
int get lastUnlockedTimeout => (super
|
||||
.noSuchMethod(Invocation.getter(#lastUnlockedTimeout), returnValue: 0)
|
||||
as int);
|
||||
@override
|
||||
set lastUnlockedTimeout(int? lastUnlockedTimeout) => super.noSuchMethod(
|
||||
Invocation.setter(#lastUnlockedTimeout, lastUnlockedTimeout),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
int get lastUnlocked =>
|
||||
(super.noSuchMethod(Invocation.getter(#lastUnlocked), returnValue: 0)
|
||||
as int);
|
||||
@override
|
||||
set lastUnlocked(int? lastUnlocked) =>
|
||||
super.noSuchMethod(Invocation.setter(#lastUnlocked, lastUnlocked),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
int get currentNotificationId =>
|
||||
(super.noSuchMethod(Invocation.getter(#currentNotificationId),
|
||||
returnValue: 0) as int);
|
||||
@override
|
||||
List<String> get walletIdsSyncOnStartup =>
|
||||
(super.noSuchMethod(Invocation.getter(#walletIdsSyncOnStartup),
|
||||
returnValue: <String>[]) as List<String>);
|
||||
@override
|
||||
set walletIdsSyncOnStartup(List<String>? walletIdsSyncOnStartup) =>
|
||||
super.noSuchMethod(
|
||||
Invocation.setter(#walletIdsSyncOnStartup, walletIdsSyncOnStartup),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
_i3.SyncingType get syncType =>
|
||||
(super.noSuchMethod(Invocation.getter(#syncType),
|
||||
returnValue: _i3.SyncingType.currentWalletOnly) as _i3.SyncingType);
|
||||
@override
|
||||
set syncType(_i3.SyncingType? syncType) =>
|
||||
super.noSuchMethod(Invocation.setter(#syncType, syncType),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
bool get wifiOnly =>
|
||||
(super.noSuchMethod(Invocation.getter(#wifiOnly), returnValue: false)
|
||||
as bool);
|
||||
@override
|
||||
set wifiOnly(bool? wifiOnly) =>
|
||||
super.noSuchMethod(Invocation.setter(#wifiOnly, wifiOnly),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
bool get showFavoriteWallets =>
|
||||
(super.noSuchMethod(Invocation.getter(#showFavoriteWallets),
|
||||
returnValue: false) as bool);
|
||||
@override
|
||||
set showFavoriteWallets(bool? showFavoriteWallets) => super.noSuchMethod(
|
||||
Invocation.setter(#showFavoriteWallets, showFavoriteWallets),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
String get language =>
|
||||
(super.noSuchMethod(Invocation.getter(#language), returnValue: '')
|
||||
as String);
|
||||
@override
|
||||
set language(String? newLanguage) =>
|
||||
super.noSuchMethod(Invocation.setter(#language, newLanguage),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
String get currency =>
|
||||
(super.noSuchMethod(Invocation.getter(#currency), returnValue: '')
|
||||
as String);
|
||||
@override
|
||||
set currency(String? newCurrency) =>
|
||||
super.noSuchMethod(Invocation.setter(#currency, newCurrency),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
_i4.ExchangeRateType get exchangeRateType =>
|
||||
(super.noSuchMethod(Invocation.getter(#exchangeRateType),
|
||||
returnValue: _i4.ExchangeRateType.estimated) as _i4.ExchangeRateType);
|
||||
@override
|
||||
set exchangeRateType(_i4.ExchangeRateType? exchangeRateType) =>
|
||||
super.noSuchMethod(Invocation.setter(#exchangeRateType, exchangeRateType),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
bool get useBiometrics =>
|
||||
(super.noSuchMethod(Invocation.getter(#useBiometrics), returnValue: false)
|
||||
as bool);
|
||||
@override
|
||||
set useBiometrics(bool? useBiometrics) =>
|
||||
super.noSuchMethod(Invocation.setter(#useBiometrics, useBiometrics),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
bool get hasPin =>
|
||||
(super.noSuchMethod(Invocation.getter(#hasPin), returnValue: false)
|
||||
as bool);
|
||||
@override
|
||||
set hasPin(bool? hasPin) =>
|
||||
super.noSuchMethod(Invocation.setter(#hasPin, hasPin),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
bool get showTestNetCoins =>
|
||||
(super.noSuchMethod(Invocation.getter(#showTestNetCoins),
|
||||
returnValue: false) as bool);
|
||||
@override
|
||||
set showTestNetCoins(bool? showTestNetCoins) =>
|
||||
super.noSuchMethod(Invocation.setter(#showTestNetCoins, showTestNetCoins),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
bool get isAutoBackupEnabled =>
|
||||
(super.noSuchMethod(Invocation.getter(#isAutoBackupEnabled),
|
||||
returnValue: false) as bool);
|
||||
@override
|
||||
set isAutoBackupEnabled(bool? isAutoBackupEnabled) => super.noSuchMethod(
|
||||
Invocation.setter(#isAutoBackupEnabled, isAutoBackupEnabled),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
set autoBackupLocation(String? autoBackupLocation) => super.noSuchMethod(
|
||||
Invocation.setter(#autoBackupLocation, autoBackupLocation),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
_i5.BackupFrequencyType get backupFrequencyType =>
|
||||
(super.noSuchMethod(Invocation.getter(#backupFrequencyType),
|
||||
returnValue: _i5.BackupFrequencyType.everyTenMinutes)
|
||||
as _i5.BackupFrequencyType);
|
||||
@override
|
||||
set backupFrequencyType(_i5.BackupFrequencyType? backupFrequencyType) =>
|
||||
super.noSuchMethod(
|
||||
Invocation.setter(#backupFrequencyType, backupFrequencyType),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
set lastAutoBackup(DateTime? lastAutoBackup) =>
|
||||
super.noSuchMethod(Invocation.setter(#lastAutoBackup, lastAutoBackup),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
bool get hasListeners =>
|
||||
(super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false)
|
||||
as bool);
|
||||
@override
|
||||
_i6.Future<void> init() => (super.noSuchMethod(Invocation.method(#init, []),
|
||||
returnValue: Future<void>.value(),
|
||||
returnValueForMissingStub: Future<void>.value()) as _i6.Future<void>);
|
||||
@override
|
||||
_i6.Future<void> incrementCurrentNotificationIndex() => (super.noSuchMethod(
|
||||
Invocation.method(#incrementCurrentNotificationIndex, []),
|
||||
returnValue: Future<void>.value(),
|
||||
returnValueForMissingStub: Future<void>.value()) as _i6.Future<void>);
|
||||
@override
|
||||
void addListener(_i7.VoidCallback? listener) =>
|
||||
super.noSuchMethod(Invocation.method(#addListener, [listener]),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
void removeListener(_i7.VoidCallback? listener) =>
|
||||
super.noSuchMethod(Invocation.method(#removeListener, [listener]),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
void dispose() => super.noSuchMethod(Invocation.method(#dispose, []),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
void notifyListeners() =>
|
||||
super.noSuchMethod(Invocation.method(#notifyListeners, []),
|
||||
returnValueForMissingStub: null);
|
||||
}
|
||||
|
||||
/// A class which mocks [TradesService].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockTradesService extends _i1.Mock implements _i8.TradesService {
|
||||
MockTradesService() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
List<_i9.ExchangeTransaction> get trades =>
|
||||
(super.noSuchMethod(Invocation.getter(#trades),
|
||||
returnValue: <_i9.ExchangeTransaction>[])
|
||||
as List<_i9.ExchangeTransaction>);
|
||||
@override
|
||||
bool get hasListeners =>
|
||||
(super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false)
|
||||
as bool);
|
||||
@override
|
||||
_i6.Future<void> add(
|
||||
{_i9.ExchangeTransaction? trade, bool? shouldNotifyListeners}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#add, [],
|
||||
{#trade: trade, #shouldNotifyListeners: shouldNotifyListeners}),
|
||||
returnValue: Future<void>.value(),
|
||||
returnValueForMissingStub: Future<void>.value()) as _i6.Future<void>);
|
||||
@override
|
||||
_i6.Future<void> edit(
|
||||
{_i9.ExchangeTransaction? trade, bool? shouldNotifyListeners}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#edit, [],
|
||||
{#trade: trade, #shouldNotifyListeners: shouldNotifyListeners}),
|
||||
returnValue: Future<void>.value(),
|
||||
returnValueForMissingStub: Future<void>.value()) as _i6.Future<void>);
|
||||
@override
|
||||
_i6.Future<void> delete(
|
||||
{_i9.ExchangeTransaction? trade, bool? shouldNotifyListeners}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#delete, [],
|
||||
{#trade: trade, #shouldNotifyListeners: shouldNotifyListeners}),
|
||||
returnValue: Future<void>.value(),
|
||||
returnValueForMissingStub: Future<void>.value()) as _i6.Future<void>);
|
||||
@override
|
||||
_i6.Future<void> deleteByUuid({String? uuid, bool? shouldNotifyListeners}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#deleteByUuid, [],
|
||||
{#uuid: uuid, #shouldNotifyListeners: shouldNotifyListeners}),
|
||||
returnValue: Future<void>.value(),
|
||||
returnValueForMissingStub: Future<void>.value()) as _i6.Future<void>);
|
||||
@override
|
||||
void addListener(_i7.VoidCallback? listener) =>
|
||||
super.noSuchMethod(Invocation.method(#addListener, [listener]),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
void removeListener(_i7.VoidCallback? listener) =>
|
||||
super.noSuchMethod(Invocation.method(#removeListener, [listener]),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
void dispose() => super.noSuchMethod(Invocation.method(#dispose, []),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
void notifyListeners() =>
|
||||
super.noSuchMethod(Invocation.method(#notifyListeners, []),
|
||||
returnValueForMissingStub: null);
|
||||
}
|
||||
|
||||
/// A class which mocks [TradeNotesService].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockTradeNotesService extends _i1.Mock implements _i10.TradeNotesService {
|
||||
MockTradeNotesService() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, String> get all => (super.noSuchMethod(Invocation.getter(#all),
|
||||
returnValue: <String, String>{}) as Map<String, String>);
|
||||
@override
|
||||
bool get hasListeners =>
|
||||
(super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false)
|
||||
as bool);
|
||||
@override
|
||||
String getNote({String? tradeId}) =>
|
||||
(super.noSuchMethod(Invocation.method(#getNote, [], {#tradeId: tradeId}),
|
||||
returnValue: '') as String);
|
||||
@override
|
||||
_i6.Future<void> set({String? tradeId, String? note}) => (super.noSuchMethod(
|
||||
Invocation.method(#set, [], {#tradeId: tradeId, #note: note}),
|
||||
returnValue: Future<void>.value(),
|
||||
returnValueForMissingStub: Future<void>.value()) as _i6.Future<void>);
|
||||
@override
|
||||
_i6.Future<void> delete({String? tradeId}) =>
|
||||
(super.noSuchMethod(Invocation.method(#delete, [], {#tradeId: tradeId}),
|
||||
returnValue: Future<void>.value(),
|
||||
returnValueForMissingStub: Future<void>.value()) as _i6.Future<void>);
|
||||
@override
|
||||
void addListener(_i7.VoidCallback? listener) =>
|
||||
super.noSuchMethod(Invocation.method(#addListener, [listener]),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
void removeListener(_i7.VoidCallback? listener) =>
|
||||
super.noSuchMethod(Invocation.method(#removeListener, [listener]),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
void dispose() => super.noSuchMethod(Invocation.method(#dispose, []),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
void notifyListeners() =>
|
||||
super.noSuchMethod(Invocation.method(#notifyListeners, []),
|
||||
returnValueForMissingStub: null);
|
||||
}
|
||||
|
||||
/// A class which mocks [ChangeNow].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockChangeNow extends _i1.Mock implements _i11.ChangeNow {
|
||||
MockChangeNow() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue