Skip to content

Commit

Permalink
fix(battery_widget.dart,battery_widget_test.dart): Correctly display …
Browse files Browse the repository at this point in the history
…name and battery level on the actual widget of a battery trait primary object
  • Loading branch information
rlperez committed Dec 21, 2021
1 parent f24c319 commit 5fd31f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/traits/battery_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ class BatteryWidget extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Row(children: <Widget>[
Text(
(_batteryLevelTraitProvider.deviceDetail?.displayName ??
'BATTERY'),
style: Theme.of(context).textTheme.headline6,
textAlign: TextAlign.left,
),
Text(
'${_batteryLevelTraitProvider.getBatteryLevel}% Battery',
style: Theme.of(context)
.textTheme
.headline6
?.copyWith(color: _getBatteryLevelColor(_batteryLevelTraitProvider.getBatteryLevel)),
style: TextStyle(
fontSize: 16,
fontStyle: FontStyle.normal,
color: _getBatteryLevelColor(
_batteryLevelTraitProvider.getBatteryLevel)),
)
]),
SizedBox(
Expand Down
9 changes: 9 additions & 0 deletions test/traits/battery_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:yonomi_device_widgets/assets/traits/battery_level_icon.dart';
import 'package:yonomi_device_widgets/providers/battery_level_trait_provider.dart';
import 'package:yonomi_device_widgets/traits/battery_widget.dart';
import 'package:yonomi_device_widgets/ui/widget_style_constants.dart';
import 'package:yonomi_platform_sdk/third_party/yonomi_graphql_schema/schema.docs.schema.gql.dart';
import 'package:yonomi_platform_sdk/yonomi-sdk.dart';

import 'battery_widget_test.mocks.dart';

Expand All @@ -17,13 +19,17 @@ MaterialApp createMaterialApp(
);
}

final device = Device('id', 'name', 'description', 'manufacturerName', 'model',
null, GDateTime('value'), GDateTime('value'), [LockTrait(IsLocked(true))]);

@GenerateMocks([BatteryLevelTraitProvider])
void main() {
testWidgets('When loading, should show CircularProgressIndicator ',
(WidgetTester tester) async {
final mockBatteryLevelProvider = MockBatteryLevelTraitProvider();
when(mockBatteryLevelProvider.isLoading).thenReturn(true);
when(mockBatteryLevelProvider.isInErrorState).thenReturn(false);
when(mockBatteryLevelProvider.deviceDetail).thenReturn(device);

await tester.pumpWidget(createMaterialApp(mockBatteryLevelProvider));

Expand All @@ -37,6 +43,7 @@ void main() {
when(mockBatteryLevelProvider.isInErrorState).thenReturn(false);
when(mockBatteryLevelProvider.getBatteryLevel)
.thenReturn(WidgetStyleConstants.batteryLowMax);
when(mockBatteryLevelProvider.deviceDetail).thenReturn(device);

await tester.pumpWidget(createMaterialApp(mockBatteryLevelProvider));

Expand All @@ -53,6 +60,7 @@ void main() {
when(mockBatteryLevelProvider.isLoading).thenReturn(false);
when(mockBatteryLevelProvider.isInErrorState).thenReturn(false);
when(mockBatteryLevelProvider.getBatteryLevel).thenReturn(50);
when(mockBatteryLevelProvider.deviceDetail).thenReturn(device);

await tester.pumpWidget(createMaterialApp(mockBatteryLevelProvider));

Expand All @@ -69,6 +77,7 @@ void main() {
when(mockBatteryLevelProvider.isInErrorState).thenReturn(false);
when(mockBatteryLevelProvider.getBatteryLevel)
.thenReturn(WidgetStyleConstants.batteryFullMin);
when(mockBatteryLevelProvider.deviceDetail).thenReturn(device);

await tester.pumpWidget(createMaterialApp(mockBatteryLevelProvider));

Expand Down

0 comments on commit 5fd31f1

Please sign in to comment.