-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Replace AlphaVersionBanner
with DevelopmentStageBanner
.
#1291
Conversation
WalkthroughThe recent update introduces a new variable for testing development stages, enhances the visibility of the app's development stage through a banner, and refines widget functionality and testing. It shifts focus towards a more dynamic presentation of the app's current stage, improving both developer experience and end-user awareness regarding the app's maturity level. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 5
Configuration used: CodeRabbit UI
Files selected for processing (4)
- app/lib/main/constants.dart (1 hunks)
- app/lib/main/sharezone.dart (2 hunks)
- app/lib/widgets/development_stage_banner.dart (1 hunks)
- app/test_goldens/widgets/development_stage_banner_test.dart (1 hunks)
Additional comments: 2
app/lib/main/sharezone.dart (2)
- 17-17: Ensure
platform_check
is used elsewhere in the file; otherwise, its import is unnecessary.- 33-33: The replacement of
AlphaVersionBanner
withDevelopmentStageBanner
is consistent with the PR objectives.
// Can be overridden for testing purposes. | ||
String? kDevelopmentStageOrNull = | ||
kDevelopmentStage == "" ? null : kDevelopmentStage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure kDevelopmentStage
is defined before kDevelopmentStageOrNull
to avoid referencing an undefined variable.
- String? kDevelopmentStageOrNull =
- kDevelopmentStage == "" ? null : kDevelopmentStage;
- const kDevelopmentStage = String.fromEnvironment('DEVELOPMENT_STAGE');
+ const kDevelopmentStage = String.fromEnvironment('DEVELOPMENT_STAGE');
+ String? kDevelopmentStageOrNull =
+ kDevelopmentStage == "" ? null : kDevelopmentStage;
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
// Can be overridden for testing purposes. | |
String? kDevelopmentStageOrNull = | |
kDevelopmentStage == "" ? null : kDevelopmentStage; | |
const kDevelopmentStage = String.fromEnvironment('DEVELOPMENT_STAGE'); | |
String? kDevelopmentStageOrNull = | |
kDevelopmentStage == "" ? null : kDevelopmentStage; |
bool get _isStable => | ||
kDevelopmentStageOrNull == null || _uppercasedStage == 'STABLE'; | ||
String? get _uppercasedStage => kDevelopmentStageOrNull?.toUpperCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider caching _uppercasedStage
to avoid calling toUpperCase()
multiple times.
+ late final String? _cachedUppercasedStage = kDevelopmentStageOrNull?.toUpperCase();
+ String? get _uppercasedStage => _cachedUppercasedStage;
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
bool get _isStable => | |
kDevelopmentStageOrNull == null || _uppercasedStage == 'STABLE'; | |
String? get _uppercasedStage => kDevelopmentStageOrNull?.toUpperCase(); | |
bool get _isStable => | |
kDevelopmentStageOrNull == null || _uppercasedStage == 'STABLE'; | |
late final String? _cachedUppercasedStage = kDevelopmentStageOrNull?.toUpperCase(); | |
String? get _uppercasedStage => _cachedUppercasedStage; |
|
||
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 development stage as a [Banner] if it is not stable. | ||
/// | ||
/// Displays nothing when [enabled] is false. | ||
/// 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 | ||
/// 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 DevelopmentStageBanner extends StatelessWidget { | ||
/// Creates a const alpha version banner. | ||
const AlphaVersionBanner({ | ||
const DevelopmentStageBanner({ | ||
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [57-61]
Use BannerLocation.topStart
instead of BannerLocation.topEnd
for consistency with the description of displaying the banner at the top left corner.
- location: BannerLocation.topEnd,
+ location: BannerLocation.topStart,
kDevelopmentStageOrNull = 'alpha'; | ||
|
||
await tester.pumpWidgetBuilder( | ||
const DevelopmentStageBanner( | ||
child: MaterialApp( | ||
debugShowCheckedModeBanner: false, | ||
home: Scaffold( | ||
body: Text("Text"), | ||
), | ||
), | ||
), | ||
); | ||
|
||
await screenMatchesGolden(tester, 'alpha_version_banner'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure kDevelopmentStageOrNull
is reset to its original value after each test to avoid side effects between tests.
+ tearDown(() {
+ kDevelopmentStageOrNull = null;
+ });
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
kDevelopmentStageOrNull = 'alpha'; | |
await tester.pumpWidgetBuilder( | |
const DevelopmentStageBanner( | |
child: MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Text("Text"), | |
), | |
), | |
), | |
); | |
await screenMatchesGolden(tester, 'alpha_version_banner'); | |
kDevelopmentStageOrNull = 'alpha'; | |
await tester.pumpWidgetBuilder( | |
const DevelopmentStageBanner( | |
child: MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Text("Text"), | |
), | |
), | |
), | |
); | |
await screenMatchesGolden(tester, 'alpha_version_banner'); | |
tearDown(() { | |
kDevelopmentStageOrNull = null; | |
}); |
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: DevelopmentStageBanner( | ||
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: DevelopmentStageBanner( | ||
child: MaterialApp( | ||
debugShowCheckedModeBanner: false, | ||
home: Scaffold( | ||
body: Text("Text"), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
|
||
expect(find.byType(Banner), findsNothing, | ||
reason: 'Stage "$stage" should not display the banner'); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider parameterizing tests for different stages to reduce code duplication.
- testWidgets("does display the banner if stage is alpha, beta or preview",
- (tester) async {
- for (var stage in ['alpha', 'beta', 'preview']) {
- kDevelopmentStageOrNull = stage;
- ...
- }
- });
- testWidgets("does not display the banner if stage is 'stable' or null",
- (tester) async {
- for (var stage in ['stable', null]) {
- kDevelopmentStageOrNull = stage;
- ...
- }
- });
+ final stagesWithBanner = ['alpha', 'beta', 'preview'];
+ final stagesWithoutBanner = ['stable', null];
+ for (var stage in [...stagesWithBanner, ...stagesWithoutBanner]) {
+ testWidgets("displays banner correctly for stage $stage", (tester) async {
+ kDevelopmentStageOrNull = stage;
+ ...
+ final expectedFindings = stagesWithBanner.contains(stage) ? findsOneWidget : findsNothing;
+ expect(find.byType(Banner), expectedFindings, reason: 'Stage "$stage" should ${expectedFindings == findsOneWidget ? '' : 'not '}display the banner');
+ });
+ }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
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: DevelopmentStageBanner( | |
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: DevelopmentStageBanner( | |
child: MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Text("Text"), | |
), | |
), | |
), | |
), | |
); | |
expect(find.byType(Banner), findsNothing, | |
reason: 'Stage "$stage" should not display the banner'); | |
} | |
}); | |
final stagesWithBanner = ['alpha', 'beta', 'preview']; | |
final stagesWithoutBanner = ['stable', null]; | |
for (var stage in [...stagesWithBanner, ...stagesWithoutBanner]) { | |
testWidgets("displays banner correctly for stage $stage", (tester) async { | |
kDevelopmentStageOrNull = stage; | |
await tester.pumpWidget( | |
const Directionality( | |
textDirection: TextDirection.ltr, | |
child: DevelopmentStageBanner( | |
child: MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Text("Text"), | |
), | |
), | |
), | |
), | |
); | |
final expectedFindings = stagesWithBanner.contains(stage) ? findsOneWidget : findsNothing; | |
expect(find.byType(Banner), expectedFindings, | |
reason: 'Stage "$stage" should ${expectedFindings == findsOneWidget ? '' : 'not '}display the banner'); | |
}); | |
} |
Visit the preview URL for this PR (updated for commit 4c6e6b7): https://sharezone-test--pr1291-add-deployment-stage-x9bsmr71.web.app (expires Sat, 10 Feb 2024 14:29:38 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 4cb3ae61e1e018abfd9841fd3239f5b49ccc034b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…it. (#1290) Use `sz build web` in web-app preview job and add `preview` stage to it. Together with #1291 this will display a "PREVIEW" banner for all previews. Since this uses `pull_request_target` one can't see it in the preview here. I checked manually though (by overriding `pull_request_target` with `pull_request`)
This replaces the
AlphaVersionBanner
withDevelopmentStageBanner
so that a banner is always shown if the user uses a non-stable version of Sharezone.This is useful for #1290 (new "preview" stage for preview builds in PRs).
Currently the banner is only shown in alpha, not in beta. This will show a banner in alpha and beta.
Summary by CodeRabbit