fix test
This commit is contained in:
parent
528b3ad0f5
commit
3ee5aceb01
|
@ -0,0 +1,45 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart';
|
||||||
|
import 'package:hub/initialization.dart';
|
||||||
|
import 'package:hub/main.dart' as app;
|
||||||
|
import 'package:hub/shared/helpers/storage/base_storage.dart';
|
||||||
|
import 'package:hub/shared/helpers/storage/storage_helper.dart';
|
||||||
|
import 'package:integration_test/integration_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
group('ProvisionalHistoryPage Integration Test', () {
|
||||||
|
setUpAll(() async => await initializeApp().then((_) async {
|
||||||
|
await StorageHelper().set(SecureStorageKey.isLogged.value, 'true');
|
||||||
|
await StorageHelper().set(SecureStorageKey.haveLocal.value, 'true');
|
||||||
|
await StorageHelper().set(KeychainStorageKey.devUUID.value, 'b5c3818753e76d85');
|
||||||
|
await StorageHelper().set(KeychainStorageKey.userUUID.value, '649c45d7514a28.85876308');
|
||||||
|
await StorageHelper().set(KeychainStorageKey.clientUUID.value, '7');
|
||||||
|
}));
|
||||||
|
|
||||||
|
testWidgets('Filter Provisional History', (WidgetTester tester) async {
|
||||||
|
app.main();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final Finder menuButton = find.byIcon(Icons.person_search_outlined);
|
||||||
|
await tester.tap(menuButton);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final Finder filterButton = find.byIcon(Icons.filter_list);
|
||||||
|
await tester.tap(filterButton);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final Finder activeFilterOption = find.text('Active');
|
||||||
|
await tester.tap(activeFilterOption);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final Finder applyFilterButton = find.text('Apply');
|
||||||
|
await tester.tap(applyFilterButton);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(CardItemTemplateComponentWidget), findsWidgets);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -1,99 +0,0 @@
|
||||||
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');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in New Issue