Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Add currency converter test
Browse files Browse the repository at this point in the history
  • Loading branch information
kirahsapong committed Jan 31, 2024
1 parent 74b0857 commit f01112a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 39 deletions.
22 changes: 3 additions & 19 deletions frontend/test/features/deposit/deposit_page_test.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
import 'package:flutter_starter/features/deposit/deposit_page.dart';
import 'package:flutter_starter/shared/currency_converter.dart';
import 'package:flutter_starter/shared/fee_details.dart';
import 'package:flutter_test/flutter_test.dart';

import '../../helpers/widget_helpers.dart';

void main() {
group('DepositPage', () {
testWidgets('should show deposit input and output amounts', (tester) async {
testWidgets('should show Currency Converter', (tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(child: const DepositPage()),
);
final depositAmountPattern = RegExp(r'\$[0-9]+\.[0-9]{2}$');

expect(find.textContaining(depositAmountPattern), findsExactly(2));
});

testWidgets('should show you deposit', (tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(child: const DepositPage()),
);

expect(find.text('You deposit'), findsOneWidget);
});

testWidgets('should show you get', (tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(child: const DepositPage()),
);

expect(find.text('You get'), findsOneWidget);
expect(find.byType(CurrencyConverter), findsOneWidget);
});

testWidgets('should show Fee Details', (tester) async {
Expand Down
23 changes: 3 additions & 20 deletions frontend/test/features/withdraw/withdraw_page_test.dart
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
import 'package:flutter_starter/features/withdraw/withdraw_page.dart';
import 'package:flutter_starter/shared/currency_converter.dart';
import 'package:flutter_starter/shared/fee_details.dart';
import 'package:flutter_test/flutter_test.dart';

import '../../helpers/widget_helpers.dart';

void main() {
group('WithdrawPage', () {
testWidgets('should show withdraw input and output amounts',
(tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(child: const WithdrawPage()),
);
final depositAmountPattern = RegExp(r'\$[0-9]+\.[0-9]{2}$');

expect(find.textContaining(depositAmountPattern), findsExactly(2));
});

testWidgets('should show you withdraw', (tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(child: const WithdrawPage()),
);

expect(find.text('You withdraw'), findsOneWidget);
});

testWidgets('should show you get', (tester) async {
testWidgets('should show Currency Converter', (tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(child: const WithdrawPage()),
);

expect(find.text('You get'), findsOneWidget);
expect(find.byType(CurrencyConverter), findsOneWidget);
});

testWidgets('should show Fee Details', (tester) async {
Expand Down
74 changes: 74 additions & 0 deletions frontend/test/shared/currency_converter_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import 'package:flutter_starter/shared/currency_converter.dart';
import 'package:flutter_test/flutter_test.dart';

import '../helpers/widget_helpers.dart';

void main() {
group('CurrencyConverter', () {
testWidgets('should show transaction input and output amounts',
(tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(
child: const CurrencyConverter(
originAmount: '1.00',
originCurrency: 'USD',
originLabel: 'You withdraw',
destinationCurrency: 'MXN',
exchangeRate: '17',
)),
);
final depositAmountPattern = RegExp(r'\$[0-9]+\.[0-9]{2}$');

expect(find.textContaining(depositAmountPattern), findsExactly(2));
expect(find.textContaining('1.00'), findsOneWidget);
expect(find.textContaining('17.00'), findsOneWidget);
});

testWidgets('should show you origin and desination currencies',
(tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(
child: const CurrencyConverter(
originAmount: '1.00',
originCurrency: 'USD',
originLabel: 'You withdraw',
destinationCurrency: 'MXN',
exchangeRate: '17',
)),
);

expect(find.textContaining('USD'), findsOneWidget);
expect(find.textContaining('MXN'), findsOneWidget);
});

testWidgets('should show you origin label', (tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(
child: const CurrencyConverter(
originAmount: '1.00',
originCurrency: 'USD',
originLabel: 'You withdraw',
destinationCurrency: 'MXN',
exchangeRate: '17',
)),
);

expect(find.text('You withdraw'), findsOneWidget);
});

testWidgets('should show you get', (tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(
child: const CurrencyConverter(
originAmount: '1.00',
originCurrency: 'USD',
originLabel: 'You withdraw',
destinationCurrency: 'MXN',
exchangeRate: '17',
)),
);

expect(find.text('You get'), findsOneWidget);
});
});
}

0 comments on commit f01112a

Please sign in to comment.