stack_wallet/test/widget_tests/address_book_card_test.dart

67 lines
2.1 KiB
Dart
Raw Normal View History

2022-10-07 08:34:30 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:stackwallet/models/contact.dart';
import 'package:stackwallet/models/contact_address_entry.dart';
2022-10-13 18:40:19 +00:00
import 'package:stackwallet/pages/address_book_views/subviews/contact_popup.dart';
2022-10-07 08:34:30 +00:00
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
import 'package:stackwallet/services/address_book_service.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/theme/light_colors.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/address_book_card.dart';
import 'address_book_card_test.mocks.dart';
class MockedFunctions extends Mock {
void showDialog();
}
2022-10-07 08:34:30 +00:00
@GenerateMocks([AddressBookService])
void main() {
2022-10-20 10:49:45 +00:00
testWidgets('test returns Contact Address Entry', (widgetTester) async {
final service = MockAddressBookService();
2022-10-13 18:40:19 +00:00
2022-10-20 10:49:45 +00:00
when(service.getContactById("default"))
.thenAnswer((realInvocation) => Contact(
name: "John Doe",
addresses: [
const ContactAddressEntry(
coin: Coin.bitcoincash,
address: "some bch address",
label: "Bills")
],
isFavorite: true));
2022-10-20 10:49:45 +00:00
await widgetTester.pumpWidget(
ProviderScope(
overrides: [
addressBookServiceProvider.overrideWithValue(
service,
),
],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
LightColors(),
),
],
),
home: const AddressBookCard(
contactId: "default",
),
),
2022-10-20 10:49:45 +00:00
),
);
2022-10-20 10:49:45 +00:00
expect(find.text("John Doe"), findsOneWidget);
expect(find.text("BCH"), findsOneWidget);
expect(find.text(Coin.bitcoincash.ticker), findsOneWidget);
2022-10-17 10:15:32 +00:00
2022-10-20 10:49:45 +00:00
await widgetTester.tap(find.byType(RawMaterialButton));
2022-10-13 18:40:19 +00:00
});
2022-10-07 08:34:30 +00:00
}