The template counter test could never compile (no flutter_test dev dependency, no MyApp). Replace it with unit tests for formatMoney (INR byte-identical to the old formatter, AED, BHD) and currency parsing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.6 KiB
Dart
43 lines
1.6 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:scalar_attendance/api_service.dart';
|
|
import 'package:scalar_attendance/money.dart';
|
|
|
|
void main() {
|
|
// The formatter the payslips screen used before org currencies.
|
|
String legacyInr(num v) => '₹${NumberFormat('#,##,###').format(v)}';
|
|
|
|
group('formatMoney', () {
|
|
test('missing / INR currency is byte-identical to the old rupee output', () {
|
|
for (final v in [0, 7, 999, 1000, 54321, 123456.7, 1234567, 98765432.49]) {
|
|
expect(formatMoney(v), legacyInr(v));
|
|
expect(formatMoney(v, null), legacyInr(v));
|
|
expect(formatMoney(v, ''), legacyInr(v));
|
|
expect(formatMoney(v, 'INR'), legacyInr(v));
|
|
expect(formatMoney(v, 'inr'), legacyInr(v));
|
|
}
|
|
expect(formatMoney(1234567), '₹12,34,567');
|
|
});
|
|
|
|
test('AED uses the ISO code, western grouping and 2 decimals', () {
|
|
expect(formatMoney(12345.5, 'AED'), 'AED 12,345.50');
|
|
expect(formatMoney(0, 'AED'), 'AED 0.00');
|
|
});
|
|
|
|
test('BHD uses 3 decimals', () {
|
|
expect(formatMoney(1234.5, 'BHD'), 'BHD 1,234.500');
|
|
});
|
|
});
|
|
|
|
group('payslip / profile currency', () {
|
|
test('parsed when present, null on older servers', () {
|
|
final withCur = Payslip.fromJson({'gid': 'p1', 'netPay': 10, 'currency': 'AED'});
|
|
final without = Payslip.fromJson({'gid': 'p1', 'netPay': 10});
|
|
expect(withCur.currency, 'AED');
|
|
expect(without.currency, isNull);
|
|
expect(Profile.fromJson({'currency': 'SAR'}).currency, 'SAR');
|
|
expect(Profile.fromJson({}).currency, isNull);
|
|
});
|
|
});
|
|
}
|