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

Feat/929 tests improve notification showcase #993

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PushTokenWidget extends StatelessWidget {
@override
Widget build(BuildContext context) => InkWell(
onTap: () {
if (value != null) {
if (value != null && error == null) {
Clipboard.setData(ClipboardData(text: value!));
}
},
Expand Down Expand Up @@ -50,6 +50,8 @@ class PushTokenWidget extends StatelessWidget {
SizedBox(height: context.textFieldDialogTheme.spacingXSS),
ShimmerText(
error ?? value,
type:
ShimmerType.fixed(placeholderLength: label.length),
style: context.textFieldDialogTheme
.editFieldTextNotEditedTextStyle
.copyWith(
Expand All @@ -62,7 +64,7 @@ class PushTokenWidget extends StatelessWidget {
),
),
Visibility(
visible: value != null,
visible: value != null && error == null,
replacement: SizedBox(),
child: Padding(
padding: EdgeInsets.only(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,19 @@ class NotificationsPage extends StatelessWidget {
label: context
.l10n.featureNotifications.notificationTokenLabel,
value: pushToken,
key: const Key('pushTokenSuccessWidget'),
),
buildError: (context, error, bloc) => PushTokenWidget(
label: context
.l10n.featureNotifications.notificationTokenLabel,
error: context.l10n.error.notImplemented,
key: const Key('pushTokenErrorWidget'),
),
buildLoading: (context, bloc) => PushTokenWidget(
label: context
.l10n.featureNotifications.notificationTokenLabel,
value: null,
key: const Key('pushTokenLoadingWidget'),
),
),
),
Expand Down
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;
}
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';
}
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(),
);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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(),
),
],
),
);
}