Skip to content

Commit

Permalink
TW-2111: Add unit test for isDisplayableResult func
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Dec 16, 2024
1 parent 519c3d2 commit 644697d
Show file tree
Hide file tree
Showing 4 changed files with 279 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/domain/model/search/server_side_search_categories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class ServerSideSearchCategories with EquatableMixin {
return Categories(
roomEvents: RoomEventsCriteria(
searchTerm: searchTerm,
groupings: Groupings(
groupBy: [Group(key: GroupKey.roomId)],
),
orderBy: SearchOrder.recent,
filter: searchFilter,
),
Expand Down
10 changes: 10 additions & 0 deletions lib/pages/search/server_search_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import 'package:fluffychat/domain/usecase/search/server_search_interactor.dart';
import 'package:fluffychat/presentation/model/search/presentation_server_side_state.dart';
import 'package:fluffychat/presentation/model/search/presentation_server_side_empty_search.dart';
import 'package:fluffychat/presentation/model/search/presentation_server_side_search.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/result_extension.dart';
import 'package:fluffychat/utils/string_extension.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -102,6 +104,10 @@ class ServerSearchController with SearchDebouncerMixin {
.where(
(result) => result.isDisplayableResult(
context: currentContext,
event: result.getEvent(currentContext),
matrixLocalizations: currentContext == null
? const MatrixDefaultLocalizations()
: MatrixLocals(L10n.of(currentContext!)!),
searchWord: _searchCategories!.searchTerm,
),
)
Expand All @@ -122,6 +128,10 @@ class ServerSearchController with SearchDebouncerMixin {
.where(
(result) => result.isDisplayableResult(
context: currentContext,
event: result.getEvent(currentContext),
matrixLocalizations: currentContext == null
? const MatrixDefaultLocalizations()
: MatrixLocals(L10n.of(currentContext!)!),
searchWord: _searchCategories!.searchTerm,
),
)
Expand Down
12 changes: 7 additions & 5 deletions lib/utils/matrix_sdk_extensions/result_extension.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:matrix/matrix.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';

extension ResultExtension on Result {
Event? getEvent(BuildContext context) {
Event? getEvent(BuildContext? context) {
if (context == null) {
return null;
}
if (result?.roomId == null) {
return null;
}
Expand All @@ -18,17 +19,18 @@ extension ResultExtension on Result {

bool isDisplayableResult({
BuildContext? context,
Event? event,
required String searchWord,
required MatrixLocalizations matrixLocalizations,
}) {
if (context == null) {
return false;
}
final event = getEvent(context);
if (event == null) {
return false;
}
final bodyContent = event.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)!),
matrixLocalizations,
hideEdit: true,
hideReply: true,
plaintextBody: true,
Expand Down
Loading

0 comments on commit 644697d

Please sign in to comment.