This commit is contained in:
J. A. Messias 2024-12-10 15:22:35 -03:00
parent dbc284762d
commit 6af6b030c2
1 changed files with 99 additions and 1 deletions

View File

@ -1 +1,99 @@
void main() {}
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hub/features/history/index.dart';
import 'package:hub/initialization.dart';
import 'package:hub/shared/helpers/storage/base_storage.dart';
import 'package:hub/shared/helpers/storage/storage_helper.dart';
import 'package:mockito/annotations.dart';
import 'package:rxdart/rxdart.dart';
@GenerateMocks([ProvisionalHistoryPage])
void main() {
group('ProvisionalHistoryPage Tests', () {
late BehaviorSubject<Map<String, String>> selectedTypeSubject;
setUpAll(() async => await initializeApp().then((_) async => await StorageHelper().set(SecureStorageKey.isLogged.value, 'true')));
setUp(() {
selectedTypeSubject = BehaviorSubject.seeded({'AGP_STATUS': '.*'});
});
tearDown(() {
selectedTypeSubject.close();
});
testWidgets('should display the app bar with title', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: ProvisionalHistoryPage()));
expect(find.text('Provisional History'), findsOneWidget);
});
testWidgets('should display the filter button', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: ProvisionalHistoryPage(),
));
expect(find.byIcon(Icons.filter_list), findsOneWidget);
});
testWidgets('should display the back button', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: ProvisionalHistoryPage(),
));
expect(find.byIcon(Icons.keyboard_arrow_left), findsOneWidget);
});
testWidgets('should display no history found message when no data', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: ProvisionalHistoryPage(),
));
expect(find.text('No history found!'), findsOneWidget);
});
testWidgets('should display loading indicator when fetching data', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: ProvisionalHistoryPage(),
));
expect(find.byType(CircularProgressIndicator), findsOneWidget);
});
testWidgets('should display history items when data is available', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: ProvisionalHistoryPage(),
));
final historyItem = {
'AGP_NOME': 'John Doe',
'AGP_DT_VISITA': '2023-10-01',
'AGP_STATUS': 'AT',
};
final provisionalHistoryState = tester.state(find.byType(ProvisionalHistoryPage)) as ProvisionalHistoryState;
provisionalHistoryState.wrap.add(historyItem);
provisionalHistoryState.hasData = true;
await tester.pump();
expect(find.text('John Doe'), findsOneWidget);
expect(find.text('2023-10-01'), findsOneWidget);
});
testWidgets('should update history when filter is applied', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: ProvisionalHistoryPage(),
));
await tester.tap(find.byIcon(Icons.filter_list));
await tester.pumpAndSettle();
await tester.tap(find.text('Active'));
await tester.tap(find.text('Apply'));
await tester.pumpAndSettle();
final provisionalHistoryState = tester.state(find.byType(ProvisionalHistoryPage)) as ProvisionalHistoryState;
expect(provisionalHistoryState.status, 'AT');
});
});
}