-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/929 tests improve notification showcase (#993)
* Notification improvement tests * Hide copy button on error * Add keys to pushTokenWidget * Fix the goldens loading state and remove pumps * Make shimmer type fixed otherwise goldens generated random one every time and fail
- Loading branch information
1 parent
68b564e
commit 5ff0364
Showing
12 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...icks/rx_bloc_base/__brick__/test/feature_notifications/mocks/notifications_bloc_mock.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:rx_bloc/rx_bloc.dart'; | ||
import 'package:rxdart/rxdart.dart'; | ||
import 'package:{{project_name}}/base/models/errors/error_model.dart'; | ||
import 'package:{{project_name}}/feature_notifications/blocs/notifications_bloc.dart'; | ||
|
||
import 'notifications_bloc_mock.mocks.dart'; | ||
|
||
@GenerateMocks([ | ||
NotificationsBlocEvents, | ||
NotificationsBlocStates, | ||
NotificationsBlocType, | ||
]) | ||
NotificationsBlocType notificationsBlocMockFactory({ | ||
String? pushToken, | ||
ErrorModel? error, | ||
}) { | ||
final notificationsBloc = MockNotificationsBlocType(); | ||
final eventsMock = MockNotificationsBlocEvents(); | ||
final statesMock = MockNotificationsBlocStates(); | ||
|
||
when(notificationsBloc.events).thenReturn(eventsMock); | ||
when(notificationsBloc.states).thenReturn(statesMock); | ||
|
||
final pushTokenState = (pushToken != null | ||
? Stream.value(Result.success(pushToken)) | ||
: error == null | ||
? Stream<Result<String>>.value(Result.loading()) | ||
: Stream<Result<String>>.value(Result<String>.error(error))) | ||
.publishReplay(maxSize: 1) | ||
..connect(); | ||
|
||
when(statesMock.pushToken).thenAnswer( | ||
(_) => pushTokenState, | ||
); | ||
|
||
when(statesMock.errors).thenAnswer( | ||
(_) => error != null ? Stream.value(error) : const Stream.empty(), | ||
); | ||
|
||
return notificationsBloc; | ||
} |
6 changes: 6 additions & 0 deletions
6
...c_cli/mason_templates/bricks/rx_bloc_base/__brick__/test/feature_notifications/stubs.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
|
||
class Stubs { | ||
static final pushToken = | ||
'euJaS9wGTQOuzDmVr8VSci:APA91bFHj6T67ns123mStP2PfberpS_srGCMBcFPSOza0lcLtx_231XFRx7kxcVEfYkYaf-YacRVj3ZRk9kFjh9ZC_1PjH6aFUNaWAns4DfcWHzkEO4wSW8'; | ||
} |
28 changes: 28 additions & 0 deletions
28
...base/__brick__/test/feature_notifications/views/factories/notifications_page_factory.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{{> licence.dart }} | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_rx_bloc/flutter_rx_bloc.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:{{project_name}}/base/models/errors/error_model.dart'; | ||
import 'package:{{project_name}}/feature_notifications/blocs/notifications_bloc.dart'; | ||
import 'package:{{project_name}}/feature_notifications/views/notifications_page.dart'; | ||
|
||
import '../../mocks/notifications_bloc_mock.dart'; | ||
|
||
/// wraps a [NotificationsPage] in a [Provider] of type [NotificationsBlocType], creating | ||
/// a mocked bloc depending on the values being tested | ||
Widget notificationsPageFactory({ | ||
ErrorModel? error, | ||
String? pushToken, | ||
}) => | ||
MultiProvider( | ||
providers: [ | ||
RxBlocProvider<NotificationsBlocType>.value( | ||
value: notificationsBlocMockFactory( | ||
pushToken: pushToken, | ||
error: error, | ||
), | ||
), | ||
], | ||
child: const NotificationsPage(), | ||
); |
Binary file added
BIN
+157 KB
...base/__brick__/test/feature_notifications/views/goldens/ci/dark_theme/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+145 KB
...se/__brick__/test/feature_notifications/views/goldens/ci/dark_theme/loading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+287 KB
...se/__brick__/test/feature_notifications/views/goldens/ci/dark_theme/success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+159 KB
...ase/__brick__/test/feature_notifications/views/goldens/ci/light_theme/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+147 KB
...e/__brick__/test/feature_notifications/views/goldens/ci/light_theme/loading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+291 KB
...e/__brick__/test/feature_notifications/views/goldens/ci/light_theme/success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions
34
...icks/rx_bloc_base/__brick__/test/feature_notifications/views/notifications_page_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{{> licence.dart }} | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:{{project_name}}/base/models/errors/error_model.dart'; | ||
|
||
import '../../helpers/golden_helper.dart'; | ||
import '../stubs.dart'; | ||
import 'factories/notifications_page_factory.dart'; | ||
|
||
void main() { | ||
group( | ||
'NotificationsPage golden tests', | ||
() => runGoldenTests( | ||
[ | ||
buildScenario( | ||
scenario: 'success', | ||
widget: notificationsPageFactory( | ||
pushToken: Stubs.pushToken, | ||
), | ||
), | ||
buildScenario( | ||
scenario: 'error', | ||
widget: notificationsPageFactory( | ||
error: NotFoundErrorModel(message: 'Error message'), | ||
), | ||
), | ||
buildScenario( | ||
scenario: 'loading', | ||
widget: notificationsPageFactory(), | ||
), | ||
], | ||
), | ||
); | ||
} |