-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Suraj Adhikari
committed
Nov 17, 2021
1 parent
2048701
commit e247044
Showing
3 changed files
with
138 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,61 @@ | ||
// import 'package:yonomi_platform_sdk/repository/devices/devices_repository.dart' | ||
// as Devices; | ||
import 'package:yonomi_platform_sdk/yonomi-sdk.dart' as Devices; | ||
import 'package:yonomi_device_widgets/assets/traits/device_item_icon.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
// Widget createIconWidget(List<Devices.Trait> traits) { | ||
// return MaterialApp( | ||
// home: Scaffold( | ||
// body: Container(child: DeviceItemIcon.getIcon(traits)), | ||
// ), | ||
// ); | ||
// } | ||
// | ||
// class UnknownTrait extends Devices.Trait { | ||
// UnknownTrait(String name, Devices.State state) : super(name, state); | ||
// } | ||
// | ||
// void main() { | ||
// testWidgets('should render correct thermostat trait icon', | ||
// (WidgetTester tester) async { | ||
// final thermostatDevice = [ | ||
// Devices.ThermostatTrait('thermostat', Devices.TargetTemperature(22)) | ||
// ]; | ||
// await tester.pumpWidget(createIconWidget(thermostatDevice)); | ||
// expect(find.widgetWithText(Center, '22'), findsOneWidget); | ||
// }); | ||
// | ||
// testWidgets('should render n/a if target temperature is null', | ||
// (WidgetTester tester) async { | ||
// final thermostatDevice = [ | ||
// Devices.ThermostatTrait('thermostat', Devices.TargetTemperature(null)) | ||
// ]; | ||
// await tester.pumpWidget(createIconWidget(thermostatDevice)); | ||
// expect(find.widgetWithText(Center, 'N/A'), findsOneWidget); | ||
// }); | ||
// | ||
// testWidgets('should render correct Lock trait icon when unlocked', | ||
// (WidgetTester tester) async { | ||
// final lockDevice = [ | ||
// Devices.LockUnlockTrait('lockunlock', Devices.IsLocked(false)) | ||
// ]; | ||
// await tester.pumpWidget(createIconWidget(lockDevice)); | ||
// expect(find.byIcon(Icons.lock_open), findsOneWidget); | ||
// }); | ||
// | ||
// testWidgets('should render correct Lock trait icon when locked', | ||
// (WidgetTester tester) async { | ||
// final lockDevice = [ | ||
// Devices.LockUnlockTrait('lockunlock', Devices.IsLocked(true)) | ||
// ]; | ||
// await tester.pumpWidget(createIconWidget(lockDevice)); | ||
// expect(find.byIcon(Icons.lock), findsOneWidget); | ||
// }); | ||
// | ||
// testWidgets('should render unknown icon if trait not found', | ||
// (WidgetTester tester) async { | ||
// final unknownDevice = [UnknownTrait('unknown', Devices.IsLocked(true))]; | ||
// await tester.pumpWidget(createIconWidget(unknownDevice)); | ||
// expect(find.byIcon(Icons.device_unknown), findsOneWidget); | ||
// }); | ||
// } | ||
Widget createIconWidget(List<Devices.Trait> traits) { | ||
return MaterialApp( | ||
home: Scaffold( | ||
body: Container(child: DeviceItemIcon.getIcon(traits)), | ||
), | ||
); | ||
} | ||
|
||
class UnknownTrait extends Devices.Trait { | ||
UnknownTrait(String name, Devices.State state) : super(name, state); | ||
} | ||
|
||
void main() { | ||
testWidgets('should render correct thermostat trait icon', | ||
(WidgetTester tester) async { | ||
final thermostatDevice = [ | ||
Devices.ThermostatTrait('thermostat', Devices.TargetTemperature(22)) | ||
]; | ||
await tester.pumpWidget(createIconWidget(thermostatDevice)); | ||
expect(find.widgetWithText(Center, '22'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('should render n/a if target temperature is null', | ||
(WidgetTester tester) async { | ||
final thermostatDevice = [ | ||
Devices.ThermostatTrait('thermostat', Devices.TargetTemperature(null)) | ||
]; | ||
await tester.pumpWidget(createIconWidget(thermostatDevice)); | ||
expect(find.widgetWithText(Center, 'N/A'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('should render correct Lock trait icon when unlocked', | ||
(WidgetTester tester) async { | ||
final lockDevice = [ | ||
Devices.LockTrait('lockunlock', Devices.IsLocked(false)) | ||
]; | ||
await tester.pumpWidget(createIconWidget(lockDevice)); | ||
expect(find.byIcon(Icons.lock_open), findsOneWidget); | ||
}); | ||
|
||
testWidgets('should render correct Lock trait icon when locked', | ||
(WidgetTester tester) async { | ||
final lockDevice = [ | ||
Devices.LockTrait('lockunlock', Devices.IsLocked(true)) | ||
]; | ||
await tester.pumpWidget(createIconWidget(lockDevice)); | ||
expect(find.byIcon(Icons.lock), findsOneWidget); | ||
}); | ||
|
||
testWidgets('should render unknown icon if trait not found', | ||
(WidgetTester tester) async { | ||
final unknownDevice = [UnknownTrait('unknown', Devices.IsLocked(true))]; | ||
await tester.pumpWidget(createIconWidget(unknownDevice)); | ||
expect(find.byIcon(Icons.device_unknown), findsOneWidget); | ||
}); | ||
} |
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