import 'package:fintracker_api/fintracker_api.dart'; import 'package:fintracker_app/core/cache/cached.dart'; import 'package:fintracker_app/features/accounts/providers.dart'; import 'package:fintracker_app/features/events/manual_event_dialog.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; AccountOut _account( int id, String name, AccountKind kind, { bool disabled = false, }) => AccountOut( id: id, kind: kind, source_: 'test', sourceId: 'acc-$id', broker: null, name: name, currency: 'RUB', role: AccountRole.investment, includeInNetWorth: true, mirrorOfAccountId: null, primaryEventSource: null, archived: false, disabled: disabled, openedAt: null, balance: null, balanceAsOf: null, startBalance: null, creditLimit: null, ); Future _open(WidgetTester tester, List accounts) async { await tester.pumpWidget( ProviderScope( overrides: [ accountsProvider.overrideWith((ref) async => Cached(accounts)), ], child: MaterialApp( home: Builder( builder: (context) => Scaffold( body: TextButton( onPressed: () => showManualEventDialog(context), child: const Text('open'), ), ), ), ), ), ); await tester.tap(find.text('open')); await tester.pumpAndSettle(); } void main() { testWidgets('a purchase asks for account, instrument, quantity and price', ( tester, ) async { await _open(tester, [_account(1, 'Брокер', AccountKind.broker)]); expect(find.text('Новое событие'), findsOneWidget); expect(find.text('Инструмент'), findsOneWidget); expect(find.text('Количество, шт.'), findsOneWidget); expect(find.text('Цена за штуку'), findsOneWidget); await tester.tap(find.text('Добавить')); await tester.pumpAndSettle(); expect(find.text('Выберите счёт'), findsOneWidget); expect(find.text('Выберите инструмент из списка'), findsOneWidget); expect(find.text('Обязательное поле'), findsWidgets); }); testWidgets('only active broker accounts can be picked', (tester) async { await _open(tester, [ _account(1, 'Брокер', AccountKind.broker), _account(2, 'Отключённый', AccountKind.broker, disabled: true), _account(3, 'Карта', AccountKind.zmCard), ]); await tester.tap(find.text('Брокерский счёт')); await tester.pumpAndSettle(); expect(find.text('Брокер'), findsOneWidget); expect(find.text('Отключённый'), findsNothing); expect(find.text('Карта'), findsNothing); }); testWidgets( 'a deposit needs only an amount: no instrument, quantity or price', (tester) async { await _open(tester, [_account(1, 'Брокер', AccountKind.broker)]); await tester.tap(find.text('Покупка')); await tester.pumpAndSettle(); await tester.tap(find.text('Пополнение').last); await tester.pumpAndSettle(); expect(find.text('Инструмент'), findsNothing); expect(find.text('Количество, шт.'), findsNothing); expect(find.text('Цена за штуку'), findsNothing); expect(find.text('Сумма'), findsOneWidget); }, ); }