style(app): остальные экраны под новый визуальный язык и форматирование

Доходы, ребалансировка, налоги, импорт, цели, здоровье данных, правила, транзакции, категории, cashflow, pending: новые виджеты и токены темы, dart format. Тесты подстроены под новые модели.
This commit is contained in:
Dmitry
2026-09-19 22:14:27 +03:00
parent 62d36aa3e8
commit 322c60a359
55 changed files with 2158 additions and 1080 deletions
+147 -104
View File
@@ -33,7 +33,11 @@ void main() {
'tax_withheld': null,
},
],
'by_basis': {'schedule': '8100.00', 'announced': '4130.50', 'history': '2000.00'},
'by_basis': {
'schedule': '8100.00',
'announced': '4130.50',
'history': '2000.00',
},
};
test('parses the calendar, keeping every amount as a string', () {
@@ -44,13 +48,20 @@ void main() {
expect(c.entries.single.basis, 'announced');
expect(c.entries.single.ticker, 'SBER');
expect(c.entries.single.taxWithheld, isNull);
expect(c.entries.single.perUnit, '34.84', reason: 'never parsed through double');
expect(
c.entries.single.perUnit,
'34.84',
reason: 'never parsed through double',
);
});
test('a null amount_rub stays null — no FX rate is not zero', () {
final json = Map<String, dynamic>.from(calendarJson);
json['entries'] = [
{...(calendarJson['entries'] as List).first as Map<String, dynamic>, 'amount_rub': null},
{
...(calendarJson['entries'] as List).first as Map<String, dynamic>,
'amount_rub': null,
},
];
expect(IncomeCalendar.fromJson(json).entries.single.amountRub, isNull);
});
@@ -82,18 +93,28 @@ void main() {
{
'month': '2026-10-01',
'amount_rub': '1830.20',
'by_basis': {'schedule': '1133.40', 'announced': '696.80', 'history': '0'},
'by_basis': {
'schedule': '1133.40',
'announced': '696.80',
'history': '0',
},
},
],
'total_rub': '21960.00',
'annual_yield_on_value': '0.081',
'warnings': ['у 3 инструментов нет истории выплат — в прогноз не вошли'],
'warnings': [
'у 3 инструментов нет истории выплат — в прогноз не вошли',
],
});
expect(f.months.single.byBasis['schedule'], '1133.40');
expect(f.totalRub, '21960.00');
expect(f.annualYieldOnValue, '0.081');
expect(f.warnings, hasLength(1));
expect(f.bases, ['schedule', 'announced', 'history'], reason: 'contract order');
expect(f.bases, [
'schedule',
'announced',
'history',
], reason: 'contract order');
final noYield = IncomeForecast.fromJson(const {
'months': <dynamic>[],
@@ -110,7 +131,12 @@ void main() {
'dimension': 'asset_class',
'weights_sum': '1.00',
'targets': [
{'bucket': 'share', 'target_weight': '0.60', 'band': '0.05', 'note': null},
{
'bucket': 'share',
'target_weight': '0.60',
'band': '0.05',
'note': null,
},
{'bucket': 'bond', 'target_weight': '0.30', 'band': '0.05'},
{'bucket': 'cash', 'target_weight': '0.10', 'band': '0.02'},
],
@@ -121,22 +147,29 @@ void main() {
expect(set.targets.first.band, '0.05');
// 0.1 + 0.2 + 0.7 is exactly 1 in Decimal and would not be in double
final tenths = TargetSet(dimension: 'asset_class', targets: const [
TargetWeight(bucket: 'a', targetWeight: '0.1'),
TargetWeight(bucket: 'b', targetWeight: '0.2'),
TargetWeight(bucket: 'c', targetWeight: '0.7'),
]);
final tenths = TargetSet(
dimension: 'asset_class',
targets: const [
TargetWeight(bucket: 'a', targetWeight: '0.1'),
TargetWeight(bucket: 'b', targetWeight: '0.2'),
TargetWeight(bucket: 'c', targetWeight: '0.7'),
],
);
expect(tenths.sumIsValid, isTrue);
final short = TargetSet(dimension: 'asset_class', targets: const [
TargetWeight(bucket: 'a', targetWeight: '0.9'),
]);
final short = TargetSet(
dimension: 'asset_class',
targets: const [TargetWeight(bucket: 'a', targetWeight: '0.9')],
);
expect(short.sumIsValid, isFalse);
});
test('the PUT body omits empty optionals and keeps shares as strings', () {
final body = const TargetWeight(bucket: 'bond', targetWeight: '0.30', band: '0.05')
.toJson();
final body = const TargetWeight(
bucket: 'bond',
targetWeight: '0.30',
band: '0.05',
).toJson();
expect(body['target_weight'], '0.30');
expect(body.containsKey('note'), isFalse);
});
@@ -151,51 +184,54 @@ void main() {
expect(formatShareAsPercent(null), '');
});
test('parses the rebalance plan, including within_band and blocked_by_cash', () {
final plan = RebalancePlan.fromJson(const {
'portfolio_id': 1,
'dimension': 'asset_class',
'as_of': '2026-09-18',
'total_value_rub': '1284300.00',
'cash_available_rub': '48120.87',
'buckets': [
{
'bucket': 'share',
'current_value_rub': '812000.00',
'current_weight': '0.632',
'target_weight': '0.60',
'drift': '0.032',
'within_band': true,
'delta_value_rub': '-41420.00',
'trades': [
{
'instrument_id': 88,
'ticker': 'SBER',
'name': 'Сбербанк России',
'action': 'sell',
'suggested_qty': '150',
'lot': 10,
'price': '275.89',
'price_currency': 'RUB',
'amount_rub': '41383.50',
'blocked_by_cash': false,
},
],
},
],
'warnings': ['у 2 инструментов нет цены — в рекомендации не вошли'],
});
test(
'parses the rebalance plan, including within_band and blocked_by_cash',
() {
final plan = RebalancePlan.fromJson(const {
'portfolio_id': 1,
'dimension': 'asset_class',
'as_of': '2026-09-18',
'total_value_rub': '1284300.00',
'cash_available_rub': '48120.87',
'buckets': [
{
'bucket': 'share',
'current_value_rub': '812000.00',
'current_weight': '0.632',
'target_weight': '0.60',
'drift': '0.032',
'within_band': true,
'delta_value_rub': '-41420.00',
'trades': [
{
'instrument_id': 88,
'ticker': 'SBER',
'name': 'Сбербанк России',
'action': 'sell',
'suggested_qty': '150',
'lot': 10,
'price': '275.89',
'price_currency': 'RUB',
'amount_rub': '41383.50',
'blocked_by_cash': false,
},
],
},
],
'warnings': ['у 2 инструментов нет цены — в рекомендации не вошли'],
});
expect(plan.portfolioId, 1);
expect(plan.buckets.single.withinBand, isTrue);
expect(plan.everythingWithinBand, isTrue);
final trade = plan.buckets.single.trades.single;
expect(trade.action, 'sell');
expect(trade.suggestedQty, '150');
expect(trade.lot, 10);
expect(trade.blockedByCash, isFalse);
expect(plan.warnings, hasLength(1));
});
expect(plan.portfolioId, 1);
expect(plan.buckets.single.withinBand, isTrue);
expect(plan.everythingWithinBand, isTrue);
final trade = plan.buckets.single.trades.single;
expect(trade.action, 'sell');
expect(trade.suggestedQty, '150');
expect(trade.lot, 10);
expect(trade.blockedByCash, isFalse);
expect(plan.warnings, hasLength(1));
},
);
test('suggested_qty stays null when there is no price', () {
final trade = RebalanceTrade.fromJson(const {
@@ -214,49 +250,55 @@ void main() {
});
group('benchmarks', () {
test('parses a period row with excess, kind and days_skipped on both sides', () {
final rows = [
for (final r in const [
{
'period': '1y',
'date_from': '2025-09-18',
'date_to': '2026-09-18',
'portfolio_twr': '0.184',
'portfolio_twr_annualized': '0.184',
'portfolio_days_skipped': 3,
'benchmarks': [
{
'benchmark_id': 1,
'code': 'MCFTR',
'kind': 'total_return',
'twr': '0.121',
'twr_annualized': '0.121',
'days_skipped': 0,
'excess': '0.063',
},
{
'benchmark_id': 2,
'code': 'IMOEX',
'kind': 'price',
'twr': '0.084',
'days_skipped': 2,
'excess': '0.100',
},
],
},
])
BenchmarkRow.fromJson(r),
];
test(
'parses a period row with excess, kind and days_skipped on both sides',
() {
final rows = [
for (final r in const [
{
'period': '1y',
'date_from': '2025-09-18',
'date_to': '2026-09-18',
'portfolio_twr': '0.184',
'portfolio_twr_annualized': '0.184',
'portfolio_days_skipped': 3,
'benchmarks': [
{
'benchmark_id': 1,
'code': 'MCFTR',
'kind': 'total_return',
'twr': '0.121',
'twr_annualized': '0.121',
'days_skipped': 0,
'excess': '0.063',
},
{
'benchmark_id': 2,
'code': 'IMOEX',
'kind': 'price',
'twr': '0.084',
'days_skipped': 2,
'excess': '0.100',
},
],
},
])
BenchmarkRow.fromJson(r),
];
final row = rows.single;
expect(row.period, '1y');
expect(row.portfolioDaysSkipped, 3);
expect(row.hasSkippedDays, isTrue);
expect(row.benchmarks.first.isPriceIndex, isFalse);
expect(row.benchmarks.last.isPriceIndex, isTrue,
reason: 'a price index must be markable');
expect(row.benchmarks.first.excess, '0.063');
});
final row = rows.single;
expect(row.period, '1y');
expect(row.portfolioDaysSkipped, 3);
expect(row.hasSkippedDays, isTrue);
expect(row.benchmarks.first.isPriceIndex, isFalse);
expect(
row.benchmarks.last.isPriceIndex,
isTrue,
reason: 'a price index must be markable',
);
expect(row.benchmarks.first.excess, '0.063');
},
);
});
group('goals', () {
@@ -346,7 +388,8 @@ void main() {
'dividends_gross_rub': '12400.00',
'estimated_tax_rub': '1963.00',
},
'disclaimer': 'Оценка. Налоговый агент — брокер; сверяйтесь с его справкой.',
'disclaimer':
'Оценка. Налоговый агент — брокер; сверяйтесь с его справкой.',
});
expect(s.year, 2026);