Skip to content

Commit

Permalink
Tests for EventList Error Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
gnunicorn committed Aug 25, 2024
1 parent 1530441 commit e4ecfe5
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 12 deletions.
30 changes: 20 additions & 10 deletions app/lib/features/events/pages/event_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:math';

import 'package:acter/common/providers/space_providers.dart';
import 'package:acter/common/toolkit/buttons/primary_action_button.dart';
import 'package:acter/common/toolkit/errors/error_page.dart';
import 'package:acter/common/utils/routes.dart';
import 'package:acter/common/widgets/acter_search_widget.dart';
import 'package:acter/common/widgets/add_button_with_can_permission.dart';
Expand Down Expand Up @@ -34,7 +35,7 @@ class _EventListPageState extends ConsumerState<EventListPage> {

String get searchValue => ref.watch(searchValueProvider);

EventFilters get eventFilterValue => ref.watch(eventFilerProvider);
EventFilters get eventFilterValue => ref.watch(eventFilterProvider);

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -85,10 +86,19 @@ class _EventListPageState extends ConsumerState<EventListPage> {
Expanded(
child: calEventsLoader.when(
data: (calEvents) => _buildEventList(calEvents),
error: (e, s) {
_log.severe('Failed to search events in space', e, s);
return Center(
child: Text(L10n.of(context).searchingFailed(e)),
error: (error, stack) {
_log.severe('Failed to search events in space', error, stack);
return ErrorPage(
background: const EventListSkeleton(),
error: error,
stack: stack,
onRetryTap: () {
ref.invalidate(
eventListSearchFilterProvider(
(spaceId: widget.spaceId, searchText: searchValue),
),
);
},
);
},
loading: () => const EventListSkeleton(),
Expand All @@ -109,39 +119,39 @@ class _EventListPageState extends ConsumerState<EventListPage> {
selected: eventFilterValue == EventFilters.all,
label: Text(L10n.of(context).all),
onSelected: (value) => ref
.read(eventFilerProvider.notifier)
.read(eventFilterProvider.notifier)
.state = EventFilters.all,
),
const SizedBox(width: 10),
FilterChip(
selected: eventFilterValue == EventFilters.bookmarked,
label: Text(L10n.of(context).bookmarked),
onSelected: (value) => ref
.read(eventFilerProvider.notifier)
.read(eventFilterProvider.notifier)
.state = EventFilters.bookmarked,
),
const SizedBox(width: 10),
FilterChip(
selected: eventFilterValue == EventFilters.ongoing,
label: Text(L10n.of(context).happeningNow),
onSelected: (value) => ref
.read(eventFilerProvider.notifier)
.read(eventFilterProvider.notifier)
.state = EventFilters.ongoing,
),
const SizedBox(width: 10),
FilterChip(
selected: eventFilterValue == EventFilters.upcoming,
label: Text(L10n.of(context).upcoming),
onSelected: (value) => ref
.read(eventFilerProvider.notifier)
.read(eventFilterProvider.notifier)
.state = EventFilters.upcoming,
),
const SizedBox(width: 10),
FilterChip(
selected: eventFilterValue == EventFilters.past,
label: Text(L10n.of(context).past),
onSelected: (value) => ref
.read(eventFilerProvider.notifier)
.read(eventFilterProvider.notifier)
.state = EventFilters.past,
),
],
Expand Down
4 changes: 2 additions & 2 deletions app/lib/features/events/providers/event_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ enum EventFilters {
past,
}

final eventFilerProvider =
final eventFilterProvider =
StateProvider.autoDispose<EventFilters>((ref) => EventFilters.all);

//SEARCH EVENTS
Expand All @@ -138,7 +138,7 @@ final eventListSearchFilterProvider = FutureProvider.autoDispose
List<ffi.CalendarEvent> filteredEventList = [];

//Filter events based on the selection
EventFilters eventFilter = ref.watch(eventFilerProvider);
EventFilters eventFilter = ref.watch(eventFilterProvider);
switch (eventFilter) {
case EventFilters.bookmarked:
{
Expand Down
100 changes: 100 additions & 0 deletions app/test/features/events/error_pages_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import 'package:acter/common/providers/room_providers.dart';
import 'package:acter/common/providers/space_providers.dart';
import 'package:acter/common/widgets/acter_search_widget.dart';
import 'package:acter/features/events/pages/event_list_page.dart';
import 'package:acter/features/events/providers/event_providers.dart';
import 'package:flutter_test/flutter_test.dart';

import '../../helpers/error_helpers.dart';
import '../../helpers/test_util.dart';

void main() {
group('Event List Error Pages', () {
testWidgets('full list', (tester) async {
bool shouldFail = true;
await tester.pumpProviderWidget(
overrides: [
eventListSearchFilterProvider.overrideWith((a, b) {
if (shouldFail) {
// toggle failure so the retry works
shouldFail = !shouldFail;
throw 'Expected fail: Space not loaded';
}
return [];
}),
hasSpaceWithPermissionProvider.overrideWith((_, ref) => false),
],
child: const EventListPage(),
);
await tester.ensureErrorPageWithRetryWorks();
});
testWidgets('full list with search', (tester) async {
bool shouldFail = true;

await tester.pumpProviderWidget(
overrides: [
searchValueProvider
.overrideWith((_) => 'some string'), // set a search string

eventListSearchFilterProvider.overrideWith((a, b) {
if (shouldFail) {
// toggle failure so the retry works
shouldFail = !shouldFail;
throw 'Expected fail: Space not loaded';
}
return [];
}),
hasSpaceWithPermissionProvider.overrideWith((_, ref) => false),
],
child: const EventListPage(),
);
await tester.ensureErrorPageWithRetryWorks();
});

testWidgets('space list', (tester) async {
bool shouldFail = true;
await tester.pumpProviderWidget(
overrides: [
roomDisplayNameProvider.overrideWith((a, b) => 'test'),
eventListSearchFilterProvider.overrideWith((a, b) {
if (shouldFail) {
// toggle failure so the retry works
shouldFail = !shouldFail;
throw 'Expected fail: Space not loaded';
}
return [];
}),
hasSpaceWithPermissionProvider.overrideWith((_, ref) => false),
],
child: const EventListPage(
spaceId: '!test',
),
);
await tester.ensureErrorPageWithRetryWorks();
});

testWidgets('space list with search', (tester) async {
bool shouldFail = true;
await tester.pumpProviderWidget(
overrides: [
roomDisplayNameProvider.overrideWith((a, b) => 'test'),
searchValueProvider
.overrideWith((_) => 'some search'), // set a search string
eventListSearchFilterProvider.overrideWith((a, b) {
if (shouldFail) {
// toggle failure so the retry works
shouldFail = !shouldFail;
throw 'Expected fail: Space not loaded';
}
return [];
}),
hasSpaceWithPermissionProvider.overrideWith((_, ref) => false),
],
child: const EventListPage(
spaceId: '!test',
),
);
await tester.ensureErrorPageWithRetryWorks();
});
});
}

0 comments on commit e4ecfe5

Please sign in to comment.