From eba0df52c8c5e53f1f60432734efc814ccaae424 Mon Sep 17 00:00:00 2001 From: David Gomes <10091092+davidgomesdev@users.noreply.github.com> Date: Sat, 20 Apr 2024 18:55:35 +0100 Subject: [PATCH] fix: text filter not working --- lib/ui/widget/text_selection_drawer.dart | 7 +++++- test/boot_screen_test.dart | 12 ++++++++++ test/boot_service_test.dart | 28 +++++++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 test/boot_screen_test.dart diff --git a/lib/ui/widget/text_selection_drawer.dart b/lib/ui/widget/text_selection_drawer.dart index 411be92..0b6ccb5 100644 --- a/lib/ui/widget/text_selection_drawer.dart +++ b/lib/ui/widget/text_selection_drawer.dart @@ -17,6 +17,11 @@ class SearchFilter { SearchReadFilter readFilter; SearchFilter(this.readFilter) : textFilter = ''; + + @override + String toString() { + return "textFilter=$textFilter;readFilter='${readFilter.label}'"; + } } enum SearchReadFilter { @@ -129,7 +134,7 @@ class _TextSelectionDrawerState extends State { selectionSink: widget.selectionSink, scrollController: listScrollController, subcategories: subcategories, - texts: texts, + texts: filteredTexts, selectedTextId: selectedTextId, onReadChange: () { setState(() {}); diff --git a/test/boot_screen_test.dart b/test/boot_screen_test.dart new file mode 100644 index 0000000..a0b7719 --- /dev/null +++ b/test/boot_screen_test.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pessoa_bonito/ui/screen/boot_screen.dart'; +import 'package:pessoa_bonito/ui/screen/splash_screen.dart'; + +void main() { + testWidgets('Boot screen should show splash', (tester) async { + await tester.pumpWidget(const MaterialApp(home: BootScreen())); + + expect(find.byType(SplashScreen), findsOneWidget); + }); +} \ No newline at end of file diff --git a/test/boot_service_test.dart b/test/boot_service_test.dart index 05c9938..d8ee3ee 100644 --- a/test/boot_service_test.dart +++ b/test/boot_service_test.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; +import 'package:get/get.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:pessoa_bonito/service/text_store.dart'; @@ -16,7 +17,7 @@ void main() { exampleJson = File('test/assets/example.json').readAsStringSync(); }); - test('TextStoreService reads texts json properly', () async { + test('TextStoreService reads sample texts json properly', () async { final assetBundleMock = MockAssetBundle(); when(assetBundleMock.loadString(any)).thenAnswer((_) async => exampleJson); @@ -55,4 +56,29 @@ void main() { expect(categoryWithSubcategoriesAndTexts.texts.first.id, equals(1234)); expect(categoryWithSubcategoriesAndTexts.texts[1].id, equals(9)); }); + + test('TextStoreService reads real texts json and functions properly', () async { + final realJson = File('assets/json_files/texts.json').readAsStringSync(); + + final assetBundleMock = MockAssetBundle(); + + when(assetBundleMock.loadString(any)).thenAnswer((_) async => realJson); + + final service = await TextStoreService.initialize(assetBundleMock); + + Get.put(service); + + final index = service.index; + + expect(index.subcategories, hasLength(9)); + expect(index.texts, isEmpty); + + final marPortuguesCategory = service.getCategory(34); + + expect(marPortuguesCategory.title, "Segunda parte: MAR PORTUGUÊS"); + + final infanteRootCategory = service.getTextRootCategory(2375); + + expect(infanteRootCategory.title, "Poesia Ortónima de Fernando Pessoa"); + }); }