forked from eatvio/eatvio_app
144 lines
4.8 KiB
Dart
144 lines
4.8 KiB
Dart
import 'package:eatvio_app/core/app_config.dart';
|
|
import 'package:eatvio_app/core/app_initializer.dart';
|
|
import 'package:eatvio_app/core/locator_service.dart';
|
|
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
|
import 'package:eatvio_app/features/profile/models/sub_model.dart';
|
|
import 'package:eatvio_app/features/profile/presentation/widgets/sub_widget.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:network_image_mock/network_image_mock.dart';
|
|
|
|
void main() {
|
|
group('SubWidget', () {
|
|
setUpAll(() async {
|
|
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
|
});
|
|
|
|
setUp(() async {
|
|
await sl.reset();
|
|
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
|
});
|
|
|
|
Widget createTestWidget(SubModel subModel) {
|
|
return MaterialApp.router(
|
|
theme: ThemeHelper().themeData(),
|
|
routerConfig: GoRouter(
|
|
routes: [
|
|
GoRoute(
|
|
path: '/',
|
|
builder: (context, state) => Scaffold(
|
|
body: SubWidget(subModel: subModel),
|
|
),
|
|
),
|
|
GoRoute(
|
|
path: '/profile',
|
|
name: 'profileScreen',
|
|
builder: (context, state) => Scaffold(
|
|
body: Text('Profile: ${state.extra}'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
testWidgets('displays sub model name correctly', (WidgetTester tester) async {
|
|
await mockNetworkImagesFor(() async {
|
|
final subModel = SubModel(
|
|
slug: 'user1',
|
|
name: 'John Doe',
|
|
city: 'Moscow',
|
|
birthdate: DateTime(1990, 1, 1),
|
|
isEntitySubscribedByMe: false,
|
|
profilePhotoUrl: '/photo.jpg',
|
|
roles: ['user'],
|
|
);
|
|
|
|
await tester.pumpWidget(createTestWidget(subModel));
|
|
await tester.pump(); // Initial frame
|
|
await tester.pump(); // Allow image loading to start
|
|
|
|
expect(find.text('John Doe'), findsOneWidget);
|
|
});
|
|
});
|
|
|
|
testWidgets('displays city correctly', (WidgetTester tester) async {
|
|
await mockNetworkImagesFor(() async {
|
|
final subModel = SubModel(
|
|
slug: 'user2',
|
|
name: 'Jane Smith',
|
|
city: 'London',
|
|
birthdate: DateTime(1995, 5, 15),
|
|
isEntitySubscribedByMe: true,
|
|
profilePhotoUrl: '/photo2.jpg',
|
|
roles: ['consultant'],
|
|
);
|
|
|
|
await tester.pumpWidget(createTestWidget(subModel));
|
|
await tester.pump(); // Initial frame
|
|
await tester.pump(); // Allow image loading to start
|
|
|
|
expect(find.textContaining('London'), findsOneWidget);
|
|
});
|
|
});
|
|
|
|
testWidgets('displays age and city', (WidgetTester tester) async {
|
|
await mockNetworkImagesFor(() async {
|
|
final birthdate = DateTime.now().subtract(const Duration(days: 365 * 25));
|
|
final subModel = SubModel(
|
|
slug: 'user3',
|
|
name: 'Test User',
|
|
city: 'Paris',
|
|
birthdate: birthdate,
|
|
isEntitySubscribedByMe: false,
|
|
profilePhotoUrl: '/photo3.jpg',
|
|
roles: [],
|
|
);
|
|
|
|
await tester.pumpWidget(createTestWidget(subModel));
|
|
await tester.pump(); // Initial frame
|
|
await tester.pump(); // Allow image loading to start
|
|
|
|
expect(find.text('Test User'), findsOneWidget);
|
|
expect(find.textContaining('Paris'), findsOneWidget);
|
|
});
|
|
});
|
|
|
|
testWidgets('displays with different subscription states', (WidgetTester tester) async {
|
|
await mockNetworkImagesFor(() async {
|
|
final subscribedModel = SubModel(
|
|
slug: 'user4',
|
|
name: 'Subscribed User',
|
|
city: 'Berlin',
|
|
birthdate: DateTime(1990, 1, 1),
|
|
isEntitySubscribedByMe: true,
|
|
profilePhotoUrl: '/photo4.jpg',
|
|
roles: ['user'],
|
|
);
|
|
|
|
final notSubscribedModel = SubModel(
|
|
slug: 'user5',
|
|
name: 'Not Subscribed User',
|
|
city: 'Rome',
|
|
birthdate: DateTime(1990, 1, 1),
|
|
isEntitySubscribedByMe: false,
|
|
profilePhotoUrl: '/photo5.jpg',
|
|
roles: ['user'],
|
|
);
|
|
|
|
await tester.pumpWidget(createTestWidget(subscribedModel));
|
|
await tester.pump(); // Initial frame
|
|
await tester.pump(); // Allow image loading to start
|
|
expect(find.text('Subscribed User'), findsOneWidget);
|
|
|
|
await tester.pumpWidget(createTestWidget(notSubscribedModel));
|
|
await tester.pump(); // Initial frame
|
|
await tester.pump(); // Allow image loading to start
|
|
expect(find.text('Not Subscribed User'), findsOneWidget);
|
|
});
|
|
});
|
|
});
|
|
}
|