Skip to content

Commit

Permalink
Test ensuring our space search works find
Browse files Browse the repository at this point in the history
  • Loading branch information
gnunicorn committed Nov 13, 2024
1 parent ef8470a commit d35a147
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
56 changes: 56 additions & 0 deletions app/test/features/spaces/search_provider_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:acter/common/providers/room_providers.dart';
import 'package:acter/common/providers/space_providers.dart';
import 'package:acter/features/search/providers/quick_search_providers.dart';
import 'package:acter/features/spaces/providers/space_list_provider.dart';
import 'package:acter_avatar/acter_avatar.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../helpers/mock_space_providers.dart';

void main() {
group('Spaces Search Provider Test', () {
test(
'Display Name update triggers proper update of search values on quick search',
() async {
final spaces = [
MockSpace(id: 'a'),
MockSpace(id: 'b'),
MockSpace(id: 'c'),
];
final Map<String, AvatarInfo> spaceInfos = {
'a': const AvatarInfo(uniqueId: 'a', displayName: 'abc'),
'b': const AvatarInfo(
uniqueId: 'b',
displayName: null,
), // not yet loaded
'c': const AvatarInfo(uniqueId: 'c', displayName: null),
};
final container = ProviderContainer(
overrides: [
spacesProvider.overrideWith((a) => MockSpaceListNotifiers(spaces)),
roomAvatarInfoProvider.overrideWith(
() => MockRoomAvatarInfoNotifier(items: spaceInfos),
),
bookmarkedSpacesProvider.overrideWith((a) => []),
],
);

final all = container.read(spaceListQuickSearchedProvider);
expect(all.length, 3);

// add a search term
container.read(quickSearchValueProvider.notifier).state = 'a';

final onlyOne = container.read(spaceListQuickSearchedProvider);
expect(onlyOne.length, 1);

// update a space info
spaceInfos['b'] = const AvatarInfo(uniqueId: 'b', displayName: 'abc');
// we only refresh the inner provider
container.refresh(roomAvatarInfoProvider('b'));

final itsTwo = container.read(spaceListQuickSearchedProvider);
expect(itsTwo.length, 2);
});
});
}
22 changes: 20 additions & 2 deletions app/test/helpers/mock_space_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import 'package:mocktail/mocktail.dart';
class MockRoomAvatarInfoNotifier extends FamilyNotifier<AvatarInfo, String>
with Mock
implements RoomAvatarInfoNotifier {
final Map<String, AvatarInfo> items;

MockRoomAvatarInfoNotifier({this.items = const {}});

@override
AvatarInfo build(arg) => AvatarInfo(uniqueId: arg);
AvatarInfo build(arg) => items[arg] ?? AvatarInfo(uniqueId: arg);
}

class RetryMockAsyncSpaceNotifier extends FamilyAsyncNotifier<Space?, String>
Expand All @@ -28,7 +32,21 @@ class RetryMockAsyncSpaceNotifier extends FamilyAsyncNotifier<Space?, String>
}
}

class MockSpace extends Fake implements Space {}
class MockSpace extends Fake implements Space {
final String id;
final bool bookmarked;

MockSpace({
this.id = 'id',
this.bookmarked = false,
});

@override
String getRoomIdStr() => id;

@override
bool isBookmarked() => bookmarked;
}

class MockSpaceHierarchyRoomInfo extends Fake
implements SpaceHierarchyRoomInfo {
Expand Down

0 comments on commit d35a147

Please sign in to comment.