2022-11-02 14:49:19 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
2022-10-07 08:34:30 +00:00
|
|
|
import 'package:mockito/annotations.dart';
|
|
|
|
import 'package:mockito/mockito.dart';
|
2022-11-02 14:49:19 +00:00
|
|
|
import 'package:stackwallet/models/contact.dart';
|
|
|
|
import 'package:stackwallet/models/contact_address_entry.dart';
|
2023-05-08 17:59:00 +00:00
|
|
|
import 'package:stackwallet/models/isar/sw_theme.dart';
|
2022-11-02 14:49:19 +00:00
|
|
|
import 'package:stackwallet/pages/address_book_views/subviews/contact_popup.dart';
|
|
|
|
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
|
2022-10-07 08:34:30 +00:00
|
|
|
import 'package:stackwallet/services/address_book_service.dart';
|
2023-05-08 17:59:00 +00:00
|
|
|
import 'package:stackwallet/themes/defaults/dark.dart';
|
2022-11-02 14:49:19 +00:00
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
|
|
|
import 'package:stackwallet/widgets/address_book_card.dart';
|
|
|
|
|
|
|
|
import 'address_book_card_test.mocks.dart';
|
2022-10-07 08:34:30 +00:00
|
|
|
|
2022-10-16 06:50:10 +00:00
|
|
|
class MockedFunctions extends Mock {
|
|
|
|
void showDialog();
|
|
|
|
}
|
|
|
|
|
2022-10-07 08:34:30 +00:00
|
|
|
@GenerateMocks([AddressBookService])
|
|
|
|
void main() {
|
2022-11-02 14:49:19 +00:00
|
|
|
testWidgets('test returns Contact Address Entry', (widgetTester) async {
|
|
|
|
final service = MockAddressBookService();
|
2023-05-08 17:59:00 +00:00
|
|
|
final applicationThemesDirectoryPath = "";
|
2022-11-02 14:49:19 +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,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
await widgetTester.pumpWidget(
|
|
|
|
ProviderScope(
|
|
|
|
overrides: [
|
|
|
|
addressBookServiceProvider.overrideWithValue(
|
|
|
|
service,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
child: MaterialApp(
|
|
|
|
theme: ThemeData(
|
|
|
|
extensions: [
|
|
|
|
StackColors.fromStackColorTheme(
|
2023-05-08 17:59:00 +00:00
|
|
|
StackTheme.fromJson(
|
|
|
|
json: darkJson,
|
|
|
|
applicationThemesDirectoryPath:
|
|
|
|
applicationThemesDirectoryPath,
|
|
|
|
),
|
2022-11-02 14:49:19 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
home: const AddressBookCard(
|
|
|
|
contactId: "default",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(find.text("John Doe"), findsOneWidget);
|
|
|
|
expect(find.text("BCH"), findsOneWidget);
|
|
|
|
expect(find.text(Coin.bitcoincash.ticker), findsOneWidget);
|
|
|
|
|
|
|
|
if (Platform.isIOS || Platform.isAndroid) {
|
|
|
|
await widgetTester.tap(find.byType(RawMaterialButton));
|
|
|
|
expect(find.byType(ContactPopUp), findsOneWidget);
|
|
|
|
} else if (Util.isDesktop) {
|
2022-11-22 21:53:16 +00:00
|
|
|
expect(find.byType(RawMaterialButton), findsNothing);
|
2022-11-02 14:49:19 +00:00
|
|
|
}
|
|
|
|
});
|
2022-10-07 08:34:30 +00:00
|
|
|
}
|