WIP: Widget tests

This commit is contained in:
Likho 2022-10-20 12:49:45 +02:00
parent 1c2cd82292
commit bb40d4b165
3 changed files with 109 additions and 196 deletions

View file

@ -21,207 +21,46 @@ class MockedFunctions extends Mock {
@GenerateMocks([AddressBookService])
void main() {
group('Navigation tests', () {
late AddressBookService service;
setUp(() {
service = MockAddressBookService();
testWidgets('test returns Contact Address Entry', (widgetTester) async {
final service = MockAddressBookService();
when(service.getContactById("some id"))
.thenAnswer((realInvocation) => Contact(
name: "John Doe",
addresses: [
const ContactAddressEntry(
coin: Coin.bitcoincash,
address: "some bch address",
label: "Bills")
],
isFavorite: true));
});
when(service.getContactById("default"))
.thenAnswer((realInvocation) => Contact(
name: "John Doe",
addresses: [
const ContactAddressEntry(
coin: Coin.bitcoincash,
address: "some bch address",
label: "Bills")
],
isFavorite: true));
testWidgets('test returns Contact Address Entry', (widgetTester) async {
await widgetTester.pumpWidget(
ProviderScope(
overrides: [
addressBookServiceProvider.overrideWithValue(
service,
),
],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
LightColors(),
),
],
),
home: const AddressBookCard(
contactId: "some id",
),
await widgetTester.pumpWidget(
ProviderScope(
overrides: [
addressBookServiceProvider.overrideWithValue(
service,
),
],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
LightColors(),
),
],
),
home: const AddressBookCard(
contactId: "default",
),
),
);
),
);
expect(find.text("John Doe"), findsOneWidget);
expect(find.text(Coin.bitcoincash.ticker), findsOneWidget);
});
expect(find.text("John Doe"), findsOneWidget);
expect(find.text("BCH"), findsOneWidget);
expect(find.text(Coin.bitcoincash.ticker), findsOneWidget);
// testWidgets("Test button press opens dialog", (widgetTester) async {
// // final service = MockAddressBookService();
//
// when(service.getContactById("some id"))
// .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(
// LightColors(),
// ),
// ],
// ),
// home: const AddressBookCard(
// contactId: "some id",
// ),
// ),
// ),
// );
// //
// // when(service.getContactById("03177ce0-4af4-11ed-9617-af8aa7a3796f"))
// // .thenAnswer((realInvocation) => Contact(
// // name: "John Doe",
// // addresses: [
// // const ContactAddressEntry(
// // coin: Coin.bitcoincash,
// // address: "some bch address",
// // label: "Bills")
// // ],
// // isFavorite: true));
// await widgetTester.tap(find.byType(RawMaterialButton));
// // verify(MockedFunctions().showDialog()).called(1);
// await widgetTester.pump();
// when(service.getContactById("03177ce0-4af4-11ed-9617-af8aa7a3796f"))
// .thenAnswer((realInvocation) => Contact(
// name: "John Doe",
// addresses: [
// const ContactAddressEntry(
// coin: Coin.bitcoincash,
// address: "some bch address",
// label: "Bills")
// ],
// isFavorite: true));
//
// expect(
// find.byWidget(const ContactPopUp(
// contactId: "03177ce0-4af4-11ed-9617-af8aa7a3796f")),
// findsOneWidget);
// // await widgetTester.pump();
// // // when(contact)
// // await widgetTester.pump();
// });
await widgetTester.tap(find.byType(RawMaterialButton));
});
// testWidgets('test returns Contact Address Entry', (widgetTester) async {
// // final service = MockAddressBookService();
// // when(service.getContactById("some id"))
// // .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(
// serv,
// ),
// ],
// child: MaterialApp(
// theme: ThemeData(
// extensions: [
// StackColors.fromStackColorTheme(
// LightColors(),
// ),
// ],
// ),
// home: const AddressBookCard(
// contactId: "some id",
// ),
// ),
// ),
// );
//
// expect(find.text("John Doe"), findsOneWidget);
// expect(find.text(Coin.bitcoincash.ticker), findsOneWidget);
// });
// testWidgets("Test button press opens dialog", (widgetTester) async {
// final service = MockAddressBookService();
//
// // when(service.getContactById("some id"))
// // .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(
// LightColors(),
// ),
// ],
// ),
// home: const AddressBookCard(
// contactId: "03177ce0-4af4-11ed-9617-af8aa7a3796f",
// ),
// ),
// ),
// );
// //
// // when(service.getContactById("03177ce0-4af4-11ed-9617-af8aa7a3796f"))
// // .thenAnswer((realInvocation) => Contact(
// // name: "John Doe",
// // addresses: [
// // const ContactAddressEntry(
// // coin: Coin.bitcoincash,
// // address: "some bch address",
// // label: "Bills")
// // ],
// // isFavorite: true));
// // await widgetTester.tap(find.byType(RawMaterialButton));
// // // when(contact)
// // await widgetTester.pump();
// });
}

View file

@ -0,0 +1,70 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:stackwallet/utilities/theme/light_colors.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart';
void main() {
testWidgets("test DesktopScaffold", (widgetTester) async {
final key = UniqueKey();
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: Material(
child: DesktopScaffold(
key: key,
body: const SizedBox(),
),
),
),
);
});
testWidgets("Test MasterScaffold for non desktop", (widgetTester) async {
final key = UniqueKey();
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: Material(
child: MasterScaffold(
key: key,
body: const SizedBox(),
appBar: AppBar(),
isDesktop: false,
),
),
),
);
});
testWidgets("Test MasterScaffold for desktop", (widgetTester) async {
final key = UniqueKey();
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: Material(
child: MasterScaffold(
key: key,
body: const SizedBox(),
appBar: AppBar(),
isDesktop: true,
),
),
),
);
});
}

View file

@ -0,0 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:stackwallet/utilities/theme/light_colors.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';