Skip to content

Commit

Permalink
fix: text filter not working
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgomesdev committed Apr 21, 2024
1 parent 701615d commit 065442a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/ui/widget/text_selection_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class SearchFilter {
SearchReadFilter readFilter;

SearchFilter(this.readFilter) : textFilter = '';

@override
String toString() {
return "textFilter=$textFilter;readFilter='${readFilter.label}'";
}
}

enum SearchReadFilter {
Expand Down Expand Up @@ -129,7 +134,7 @@ class _TextSelectionDrawerState extends State<TextSelectionDrawer> {
selectionSink: widget.selectionSink,
scrollController: listScrollController,
subcategories: subcategories,
texts: texts,
texts: filteredTexts,
selectedTextId: selectedTextId,
onReadChange: () {
setState(() {});
Expand Down
12 changes: 12 additions & 0 deletions test/boot_screen_test.dart
Original file line number Diff line number Diff line change
@@ -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);
});
}
28 changes: 27 additions & 1 deletion test/boot_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -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");
});
}

0 comments on commit 065442a

Please sign in to comment.