From 8c9f305ae3d65cc53d132b73c155e24692140291 Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:19:28 +0100 Subject: [PATCH 1/2] Replace `AlphaVersionBanner` with `DeploymentStageBanner`. --- app/lib/main/constants.dart | 3 + app/lib/main/sharezone.dart | 8 +- ...nner.dart => deployment_stage_banner.dart} | 32 ++++--- .../widgets/alpha_version_banner_test.dart | 76 ----------------- .../widgets/deployment_stage_banner_test.dart | 85 +++++++++++++++++++ 5 files changed, 109 insertions(+), 95 deletions(-) rename app/lib/widgets/{alpha_version_banner.dart => deployment_stage_banner.dart} (55%) delete mode 100644 app/test_goldens/widgets/alpha_version_banner_test.dart create mode 100644 app/test_goldens/widgets/deployment_stage_banner_test.dart diff --git a/app/lib/main/constants.dart b/app/lib/main/constants.dart index 132508a07..eac2e26b7 100644 --- a/app/lib/main/constants.dart +++ b/app/lib/main/constants.dart @@ -6,4 +6,7 @@ // // SPDX-License-Identifier: EUPL-1.2 +// Can be overridden for testing purposes. +String? kDevelopmentStageOrNull = + kDevelopmentStage == "" ? null : kDevelopmentStage; const kDevelopmentStage = String.fromEnvironment('DEVELOPMENT_STAGE'); diff --git a/app/lib/main/sharezone.dart b/app/lib/main/sharezone.dart index 8a6ec8cea..5f8fe1dd5 100644 --- a/app/lib/main/sharezone.dart +++ b/app/lib/main/sharezone.dart @@ -14,6 +14,7 @@ import 'package:bloc_provider/multi_bloc_provider.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; import 'package:overlay_support/overlay_support.dart'; +import 'package:platform_check/platform_check.dart'; import 'package:provider/provider.dart'; import 'package:sharezone/account/theme/theme_settings.dart'; import 'package:sharezone/dynamic_links/beitrittsversuch.dart'; @@ -21,7 +22,6 @@ import 'package:sharezone/dynamic_links/dynamic_link_bloc.dart'; import 'package:sharezone/dynamic_links/dynamic_links.dart'; import 'package:sharezone/main/auth_app.dart'; import 'package:sharezone/main/bloc_dependencies.dart'; -import 'package:sharezone/main/constants.dart'; import 'package:sharezone/main/sharezone_app.dart'; import 'package:sharezone/main/sharezone_bloc_providers.dart'; import 'package:sharezone/navigation/logic/navigation_bloc.dart'; @@ -29,10 +29,9 @@ import 'package:sharezone/notifications/notifications_permission.dart'; import 'package:sharezone/onboarding/group_onboarding/logic/signed_up_bloc.dart'; import 'package:sharezone/sharezone_plus/subscription_service/subscription_flag.dart'; import 'package:sharezone/util/flavor.dart'; -import 'package:sharezone/widgets/alpha_version_banner.dart'; import 'package:sharezone/widgets/animation/color_fade_in.dart'; +import 'package:sharezone/widgets/deployment_stage_banner.dart'; import 'package:sharezone_utils/device_information_manager.dart'; -import 'package:platform_check/platform_check.dart'; import 'package:sharezone_widgets/sharezone_widgets.dart'; /// Defines if the app is running in integration test mode. @@ -112,8 +111,7 @@ class _SharezoneState extends State with WidgetsBindingObserver { textDirection: TextDirection.ltr, child: _ThemeSettingsProvider( blocDependencies: widget.blocDependencies, - child: AlphaVersionBanner( - enabled: kDevelopmentStage == 'ALPHA', + child: DeploymentStageBanner( child: Stack( children: [ MultiProvider( diff --git a/app/lib/widgets/alpha_version_banner.dart b/app/lib/widgets/deployment_stage_banner.dart similarity index 55% rename from app/lib/widgets/alpha_version_banner.dart rename to app/lib/widgets/deployment_stage_banner.dart index 841ed47c5..efbddbe74 100644 --- a/app/lib/widgets/alpha_version_banner.dart +++ b/app/lib/widgets/deployment_stage_banner.dart @@ -8,49 +8,53 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:sharezone/main/constants.dart'; -/// Displays a [Banner] saying "ALPHA" when running an alpha version at top left -/// hand corner. +/// Displays the current deployment stage as a [Banner] if it is not stable. /// -/// Displays nothing when [enabled] is false. +/// Sharezone has different deployment stages e.g. "alpha", "beta", "preview". +/// This widget displays the current deployment stage as a [Banner] at the top +/// hand corner of the screen if we are not in the stable/production deployment +/// stage. +/// +/// This is intended so that users know that they are using a non-stable version +/// of the app and that they should expect bugs and other issues. /// /// This widget is similar and inspired by the [CheckedModeBanner] which displays /// "DEBUG" at the top right hand corner when running a Flutter app in debug /// mode. -class AlphaVersionBanner extends StatelessWidget { +class DeploymentStageBanner extends StatelessWidget { /// Creates a const alpha version banner. - const AlphaVersionBanner({ + const DeploymentStageBanner({ super.key, required this.child, - required this.enabled, }); /// The widget to show behind the banner. final Widget child; - /// Defines if the alpha banner should shown. - /// - /// If set to false, the banner will not be shown and is not visible. - final bool enabled; + bool get _isStable => + kDevelopmentStageOrNull == null || _uppercasedStage == 'STABLE'; + String? get _uppercasedStage => kDevelopmentStageOrNull?.toUpperCase(); @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); String message = 'disabled'; - if (enabled) { - message = 'ALPHA'; + if (!_isStable) { + message = _uppercasedStage!; } properties.add(DiagnosticsNode.message(message)); } @override Widget build(BuildContext context) { - if (!enabled) { + if (_isStable) { return child; } return Banner( - message: 'ALPHA', + message: _uppercasedStage!, textDirection: TextDirection.ltr, location: BannerLocation.topEnd, color: Colors.blue, diff --git a/app/test_goldens/widgets/alpha_version_banner_test.dart b/app/test_goldens/widgets/alpha_version_banner_test.dart deleted file mode 100644 index 6e942a3da..000000000 --- a/app/test_goldens/widgets/alpha_version_banner_test.dart +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2022 Sharezone UG (haftungsbeschränkt) -// Licensed under the EUPL-1.2-or-later. -// -// You may obtain a copy of the Licence at: -// https://joinup.ec.europa.eu/software/page/eupl -// -// SPDX-License-Identifier: EUPL-1.2 - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:golden_toolkit/golden_toolkit.dart'; -import 'package:sharezone/widgets/alpha_version_banner.dart'; - -void main() { - group('AlphaVersionBanner', () { - testGoldens( - 'displays the banner at the correct position', - (tester) async { - await tester.pumpWidgetBuilder( - const AlphaVersionBanner( - enabled: true, - child: MaterialApp( - debugShowCheckedModeBanner: false, - home: Scaffold( - body: Text("Text"), - ), - ), - ), - ); - - await screenMatchesGolden(tester, 'alpha_version_banner'); - }, - ); - - testWidgets("does display the banner if [enabled] is true", (tester) async { - await tester.pumpWidget( - const Directionality( - textDirection: TextDirection.ltr, - child: AlphaVersionBanner( - enabled: true, - child: MaterialApp( - debugShowCheckedModeBanner: false, - home: Scaffold( - body: Text("Text"), - ), - ), - ), - ), - ); - - expect(find.byType(Banner), findsOneWidget); - }); - - testWidgets( - "does not display the banner if [enabled] is false", - (tester) async { - await tester.pumpWidget( - const Directionality( - textDirection: TextDirection.ltr, - child: AlphaVersionBanner( - enabled: false, - child: MaterialApp( - debugShowCheckedModeBanner: false, - home: Scaffold( - body: Text("Text"), - ), - ), - ), - ), - ); - - expect(find.byType(Banner), findsNothing); - }, - ); - }); -} diff --git a/app/test_goldens/widgets/deployment_stage_banner_test.dart b/app/test_goldens/widgets/deployment_stage_banner_test.dart new file mode 100644 index 000000000..e257c0e26 --- /dev/null +++ b/app/test_goldens/widgets/deployment_stage_banner_test.dart @@ -0,0 +1,85 @@ +// Copyright (c) 2022 Sharezone UG (haftungsbeschränkt) +// Licensed under the EUPL-1.2-or-later. +// +// You may obtain a copy of the Licence at: +// https://joinup.ec.europa.eu/software/page/eupl +// +// SPDX-License-Identifier: EUPL-1.2 + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:golden_toolkit/golden_toolkit.dart'; +import 'package:sharezone/main/constants.dart'; +import 'package:sharezone/widgets/deployment_stage_banner.dart'; + +void main() { + group('$DeploymentStageBanner', () { + testGoldens( + 'displays the banner at the correct position', + (tester) async { + kDevelopmentStageOrNull = 'alpha'; + + await tester.pumpWidgetBuilder( + const DeploymentStageBanner( + child: MaterialApp( + debugShowCheckedModeBanner: false, + home: Scaffold( + body: Text("Text"), + ), + ), + ), + ); + + await screenMatchesGolden(tester, 'alpha_version_banner'); + }, + ); + + testWidgets("does display the banner if stage is alpha, beta or preview", + (tester) async { + for (var stage in ['alpha', 'beta', 'preview']) { + kDevelopmentStageOrNull = stage; + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: DeploymentStageBanner( + child: MaterialApp( + debugShowCheckedModeBanner: false, + home: Scaffold( + body: Text("Text"), + ), + ), + ), + ), + ); + + expect(find.byType(Banner), findsOneWidget, + reason: 'Stage "$stage" should display the banner'); + } + }); + + testWidgets("does not display the banner if stage is 'stable' or null", + (tester) async { + for (var stage in ['stable', null]) { + kDevelopmentStageOrNull = stage; + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: DeploymentStageBanner( + child: MaterialApp( + debugShowCheckedModeBanner: false, + home: Scaffold( + body: Text("Text"), + ), + ), + ), + ), + ); + + expect(find.byType(Banner), findsNothing, + reason: 'Stage "$stage" should not display the banner'); + } + }); + }); +} From 4c6e6b7b68e4e56804ee70d25df78108c0993928 Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:21:04 +0100 Subject: [PATCH 2/2] Rename to `DevelopmentStageBanner`. --- app/lib/main/sharezone.dart | 4 ++-- ...age_banner.dart => development_stage_banner.dart} | 12 ++++++------ ..._test.dart => development_stage_banner_test.dart} | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) rename app/lib/widgets/{deployment_stage_banner.dart => development_stage_banner.dart} (82%) rename app/test_goldens/widgets/{deployment_stage_banner_test.dart => development_stage_banner_test.dart} (90%) diff --git a/app/lib/main/sharezone.dart b/app/lib/main/sharezone.dart index 5f8fe1dd5..bfe286750 100644 --- a/app/lib/main/sharezone.dart +++ b/app/lib/main/sharezone.dart @@ -30,7 +30,7 @@ import 'package:sharezone/onboarding/group_onboarding/logic/signed_up_bloc.dart' import 'package:sharezone/sharezone_plus/subscription_service/subscription_flag.dart'; import 'package:sharezone/util/flavor.dart'; import 'package:sharezone/widgets/animation/color_fade_in.dart'; -import 'package:sharezone/widgets/deployment_stage_banner.dart'; +import 'package:sharezone/widgets/development_stage_banner.dart'; import 'package:sharezone_utils/device_information_manager.dart'; import 'package:sharezone_widgets/sharezone_widgets.dart'; @@ -111,7 +111,7 @@ class _SharezoneState extends State with WidgetsBindingObserver { textDirection: TextDirection.ltr, child: _ThemeSettingsProvider( blocDependencies: widget.blocDependencies, - child: DeploymentStageBanner( + child: DevelopmentStageBanner( child: Stack( children: [ MultiProvider( diff --git a/app/lib/widgets/deployment_stage_banner.dart b/app/lib/widgets/development_stage_banner.dart similarity index 82% rename from app/lib/widgets/deployment_stage_banner.dart rename to app/lib/widgets/development_stage_banner.dart index efbddbe74..8974c87d7 100644 --- a/app/lib/widgets/deployment_stage_banner.dart +++ b/app/lib/widgets/development_stage_banner.dart @@ -10,11 +10,11 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:sharezone/main/constants.dart'; -/// Displays the current deployment stage as a [Banner] if it is not stable. +/// Displays the current development stage as a [Banner] if it is not stable. /// -/// Sharezone has different deployment stages e.g. "alpha", "beta", "preview". -/// This widget displays the current deployment stage as a [Banner] at the top -/// hand corner of the screen if we are not in the stable/production deployment +/// Sharezone has different development stages e.g. "alpha", "beta", "preview". +/// This widget displays the current development stage as a [Banner] at the top +/// hand corner of the screen if we are not in the stable/production development /// stage. /// /// This is intended so that users know that they are using a non-stable version @@ -23,9 +23,9 @@ import 'package:sharezone/main/constants.dart'; /// This widget is similar and inspired by the [CheckedModeBanner] which displays /// "DEBUG" at the top right hand corner when running a Flutter app in debug /// mode. -class DeploymentStageBanner extends StatelessWidget { +class DevelopmentStageBanner extends StatelessWidget { /// Creates a const alpha version banner. - const DeploymentStageBanner({ + const DevelopmentStageBanner({ super.key, required this.child, }); diff --git a/app/test_goldens/widgets/deployment_stage_banner_test.dart b/app/test_goldens/widgets/development_stage_banner_test.dart similarity index 90% rename from app/test_goldens/widgets/deployment_stage_banner_test.dart rename to app/test_goldens/widgets/development_stage_banner_test.dart index e257c0e26..ba0400015 100644 --- a/app/test_goldens/widgets/deployment_stage_banner_test.dart +++ b/app/test_goldens/widgets/development_stage_banner_test.dart @@ -10,17 +10,17 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:sharezone/main/constants.dart'; -import 'package:sharezone/widgets/deployment_stage_banner.dart'; +import 'package:sharezone/widgets/development_stage_banner.dart'; void main() { - group('$DeploymentStageBanner', () { + group('$DevelopmentStageBanner', () { testGoldens( 'displays the banner at the correct position', (tester) async { kDevelopmentStageOrNull = 'alpha'; await tester.pumpWidgetBuilder( - const DeploymentStageBanner( + const DevelopmentStageBanner( child: MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( @@ -42,7 +42,7 @@ void main() { await tester.pumpWidget( const Directionality( textDirection: TextDirection.ltr, - child: DeploymentStageBanner( + child: DevelopmentStageBanner( child: MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( @@ -66,7 +66,7 @@ void main() { await tester.pumpWidget( const Directionality( textDirection: TextDirection.ltr, - child: DeploymentStageBanner( + child: DevelopmentStageBanner( child: MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold(