-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RSDK-4265] Sensor widget tests (#81)
- Loading branch information
Showing
8 changed files
with
202 additions
and
31 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
int generateTestingPortFromName(String name) => 50000 + (name.hashCode % 10000); | ||
|
||
class TestableWidget extends StatelessWidget { | ||
const TestableWidget({ | ||
super.key, | ||
required this.child, | ||
}); | ||
|
||
final Widget child; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'Flutter Demo', | ||
home: Scaffold( | ||
body: child, | ||
), | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:viam_sdk/widgets.dart'; | ||
|
||
import '../test_utils.dart'; | ||
import '../unit_test/components/sensor_test.dart'; | ||
|
||
void main() { | ||
group('ViamSensorWidget', () { | ||
testWidgets('displays data', (tester) async { | ||
final widget = TestableWidget(child: ViamSensorWidget(sensor: FakeSensor('sensor'))); | ||
await tester.pumpWidget(widget); | ||
|
||
final dataTable = find.byType(DataTable); | ||
|
||
expect(dataTable, findsOneWidget); | ||
}); | ||
|
||
testWidgets('shows last refresh time', (tester) async { | ||
final widget = TestableWidget(child: ViamSensorWidget(sensor: FakeSensor('sensor'), showLastRefreshed: true)); | ||
await tester.pumpWidget(widget); | ||
|
||
final refreshButton = find.widgetWithIcon(ViamButton, Icons.refresh); | ||
await tester.press(refreshButton); | ||
await tester.pump(); | ||
|
||
final refreshTime = find.textContaining(RegExp(r'Updated at:.*')); | ||
|
||
expect(refreshTime, findsOneWidget); | ||
}); | ||
|
||
testWidgets('hides last refresh time', (tester) async { | ||
final widget = TestableWidget(child: ViamSensorWidget(sensor: FakeSensor('sensor'), showLastRefreshed: false)); | ||
await tester.pumpWidget(widget); | ||
|
||
final refreshButton = find.widgetWithIcon(ViamButton, Icons.refresh); | ||
await tester.press(refreshButton); | ||
await tester.pump(); | ||
|
||
final refreshTime = find.textContaining(RegExp(r'Updated at:.*')); | ||
|
||
expect(refreshTime, findsNothing); | ||
}); | ||
|
||
testWidgets('shows refresh controls', (tester) async { | ||
final widget = TestableWidget(child: ViamSensorWidget(sensor: FakeSensor('sensor'), showRefreshControls: true)); | ||
await tester.pumpWidget(widget); | ||
|
||
final playButton = find.widgetWithIcon(ViamButton, Icons.play_arrow); | ||
final pauseButton = find.widgetWithIcon(ViamButton, Icons.pause); | ||
final refreshButton = find.widgetWithIcon(ViamButton, Icons.refresh); | ||
|
||
expect(playButton, findsNothing); | ||
expect(pauseButton, findsOneWidget); | ||
expect(refreshButton, findsOneWidget); | ||
|
||
await tester.press(pauseButton); | ||
await tester.pump(); | ||
|
||
expect(playButton, findsNothing); | ||
expect(pauseButton, findsOneWidget); | ||
}); | ||
|
||
testWidgets('hides refresh controls', (tester) async { | ||
final widget = TestableWidget(child: ViamSensorWidget(sensor: FakeSensor('sensor'), showRefreshControls: false)); | ||
await tester.pumpWidget(widget); | ||
|
||
final playButton = find.widgetWithIcon(ViamButton, Icons.play_arrow); | ||
final pauseButton = find.widgetWithIcon(ViamButton, Icons.pause); | ||
final refreshButton = find.widgetWithIcon(ViamButton, Icons.refresh); | ||
|
||
expect(playButton, findsNothing); | ||
expect(pauseButton, findsNothing); | ||
expect(refreshButton, findsNothing); | ||
}); | ||
|
||
testWidgets('hides play/pause when refresh interval is null', (tester) async { | ||
final widget = TestableWidget(child: ViamSensorWidget(sensor: FakeSensor('sensor'), refreshInterval: null)); | ||
await tester.pumpWidget(widget); | ||
|
||
final playButton = find.widgetWithIcon(ViamButton, Icons.play_arrow); | ||
final pauseButton = find.widgetWithIcon(ViamButton, Icons.pause); | ||
final refreshButton = find.widgetWithIcon(ViamButton, Icons.refresh); | ||
|
||
expect(playButton, findsNothing); | ||
expect(pauseButton, findsNothing); | ||
expect(refreshButton, findsOneWidget); | ||
}); | ||
}); | ||
} |