Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: text filter not working #26

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
});
}
Loading