Skip to content

Commit

Permalink
Added more widgets to testing layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Oct 16, 2023
1 parent 1d1adb8 commit b703b12
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
71 changes: 67 additions & 4 deletions test/widgets/dashboard_grid_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,30 @@ import 'package:elastic_dashboard/widgets/dialog_widgets/dialog_dropdown_chooser
import 'package:elastic_dashboard/widgets/dialog_widgets/dialog_text_input.dart';
import 'package:elastic_dashboard/widgets/draggable_containers/draggable_nt4_widget_container.dart';
import 'package:elastic_dashboard/widgets/draggable_containers/draggable_widget_container.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/camera_stream.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/combo_box_chooser.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/command_scheduler.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/command_widget.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/field_widget.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/fms_info.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/gyro.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/pid_controller.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/power_distribution.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/robot_preferences.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/split_button_chooser.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/subsystem_widget.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/nt4_widget.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/boolean_box.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/graph.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/match_time.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/multi_color_view.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/number_bar.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/number_slider.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/single_color_view.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/text_display.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/toggle_button.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/toggle_switch.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/voltage_view.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Expand All @@ -38,11 +55,10 @@ void main() async {
jsonData = jsonDecode(jsonString);
});

testWidgets('Dashboard grid loading', (widgetTester) async {
testWidgets('Dashboard grid loading (Tab 1)', (widgetTester) async {
FlutterError.onError = ignoreOverflowErrors;
widgetTester.view.physicalSize = const Size(1920, 1080);
widgetTester.view.devicePixelRatio = 1.0;
// WidgetController.hitTestWarningShouldBeFatal = true;

expect(jsonData.containsKey('tabs'), true);

Expand All @@ -66,19 +82,66 @@ void main() async {

await widgetTester.pump(Duration.zero);

// await widgetTester.pumpAndSettle();

expect(find.bySubtype<DraggableNT4WidgetContainer>(), findsNWidgets(9));
expect(find.bySubtype<NT4Widget>(), findsNWidgets(9));

expect(find.bySubtype<TextDisplay>(), findsOneWidget);
expect(find.bySubtype<BooleanBox>(), findsOneWidget);
expect(find.bySubtype<FieldWidget>(), findsOneWidget);
expect(find.bySubtype<PowerDistribution>(), findsOneWidget);
expect(find.bySubtype<FMSInfo>(), findsOneWidget);
expect(find.bySubtype<Gyro>(), findsOneWidget);
expect(find.bySubtype<CameraStreamWidget>(), findsOneWidget);
expect(find.bySubtype<MatchTimeWidget>(), findsOneWidget);
expect(find.bySubtype<PIDControllerWidget>(), findsOneWidget);
});

testWidgets('Dashboard grid loading (2nd Tab)', (widgetTester) async {
FlutterError.onError = ignoreOverflowErrors;
widgetTester.view.physicalSize = const Size(1920, 1080);
widgetTester.view.devicePixelRatio = 1.0;

expect(jsonData.containsKey('tabs'), true);

expect(jsonData['tabs'][0].containsValue('Teleoperated'), true);
expect(jsonData['tabs'][0].containsKey('grid_layout'), true);

expect(jsonData['tabs'][1].containsValue('Autonomous'), true);
expect(jsonData['tabs'][1].containsKey('grid_layout'), true);

await widgetTester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ChangeNotifierProvider(
create: (context) => DashboardGridModel(),
child: DashboardGrid.fromJson(
jsonData: jsonData['tabs'][1]['grid_layout']),
),
),
),
);

await widgetTester.pump(Duration.zero);

expect(find.bySubtype<DraggableNT4WidgetContainer>(), findsNWidgets(14));
expect(find.bySubtype<NT4Widget>(), findsNWidgets(14));

expect(find.bySubtype<ToggleButton>(), findsOneWidget);
expect(find.bySubtype<ToggleSwitch>(), findsOneWidget);
expect(find.bySubtype<ComboBoxChooser>(), findsOneWidget);
expect(find.bySubtype<SplitButtonChooser>(), findsOneWidget);
expect(find.bySubtype<SingleColorView>(), findsOneWidget);
expect(find.bySubtype<MultiColorView>(), findsOneWidget);
expect(find.bySubtype<VoltageView>(), findsOneWidget);
expect(find.bySubtype<NumberBar>(), findsOneWidget);
expect(find.bySubtype<NumberSlider>(), findsOneWidget);
expect(find.bySubtype<GraphWidget>(), findsOneWidget);
expect(find.bySubtype<CommandSchedulerWidget>(), findsOneWidget);
expect(find.bySubtype<CommandWidget>(), findsOneWidget);
expect(find.bySubtype<SubsystemWidget>(), findsOneWidget);
expect(find.bySubtype<RobotPreferences>(), findsOneWidget);
});

testWidgets('Editing properties', (widgetTester) async {
FlutterError.onError = ignoreOverflowErrors;
widgetTester.view.physicalSize = const Size(1920, 1080);
Expand Down
2 changes: 1 addition & 1 deletion test_resources/test-layout.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"tabs":[{"name":"Teleoperated","grid_layout":{"containers":[{"title":"Test Number","x":0.0,"y":0.0,"width":128.0,"height":128.0,"type":"Text Display","properties":{"topic":"/SmartDashboard/Testing","period":0.033}},{"title":"Test Boolean","x":128.0,"y":0.0,"width":128.0,"height":128.0,"type":"Boolean Box","properties":{"topic":"/SmartDashboard/Test Boolean","period":0.033,"true_color":4283215696,"false_color":4294198070}},{"title":"Field","x":256.0,"y":384.0,"width":384.0,"height":256.0,"type":"Field","properties":{"topic":"/SmartDashboard/Field","period":0.033,"field_game":"Charged Up","robot_width":0.82,"robot_length":1.0,"show_other_objects":true,"show_trajectories":true}},{"title":"Test Gyro","x":0.0,"y":128.0,"width":256.0,"height":256.0,"type":"Gyro","properties":{"topic":"/SmartDashboard/Test Gyro","period":0.033,"counter_clockwise_positive":false}},{"title":"Test Distribution","x":640.0,"y":0.0,"width":384.0,"height":512.0,"type":"PowerDistribution","properties":{"topic":"/SmartDashboard/Test Distribution","period":0.033}},{"title":"Test PID Controller","x":1024.0,"y":0.0,"width":256.0,"height":384.0,"type":"PIDController","properties":{"topic":"/SmartDashboard/Test PID Controller","period":0.033,"kp_topic":"/SmartDashboard/Test PID Controller/p","ki_topic":"/SmartDashboard/Test PID Controller/i","kd_topic":"/SmartDashboard/Test PID Controller/d","setpoint_topic":"/SmartDashboard/Test PID Controller/setpoint"}},{"title":"USB Camera 0","x":0.0,"y":384.0,"width":128.0,"height":128.0,"type":"Camera Stream","properties":{"topic":"/CameraPublisher/USB Camera 0","period":0.033}},{"title":"FMSInfo","x":256.0,"y":256.0,"width":384.0,"height":128.0,"type":"FMSInfo","properties":{"topic":"/FMSInfo","period":0.033}},{"title":"Match Time","x":128.0,"y":384.0,"width":128.0,"height":128.0,"type":"Match Time","properties":{"topic":"/SmartDashboard/Match Time","period":0.033}}]}},{"name":"Autonomous","grid_layout":{"containers":[{"title":"Test Chooser","x":0.0,"y":0.0,"width":256.0,"height":128.0,"type":"ComboBox Chooser","properties":{"topic":"/SmartDashboard/Test Chooser","period":0.033}}]}}]}
{"tabs":[{"name":"Teleoperated","grid_layout":{"containers":[{"title":"Test Number","x":0.0,"y":0.0,"width":128.0,"height":128.0,"type":"Text Display","properties":{"topic":"/SmartDashboard/Testing","period":0.033}},{"title":"Test Boolean","x":128.0,"y":0.0,"width":128.0,"height":128.0,"type":"Boolean Box","properties":{"topic":"/SmartDashboard/Test Boolean","period":0.033,"true_color":4283215696,"false_color":4294198070}},{"title":"Field","x":256.0,"y":384.0,"width":384.0,"height":256.0,"type":"Field","properties":{"topic":"/SmartDashboard/Field","period":0.033,"field_game":"Charged Up","robot_width":0.82,"robot_length":1.0,"show_other_objects":true,"show_trajectories":true}},{"title":"Test Gyro","x":0.0,"y":128.0,"width":256.0,"height":256.0,"type":"Gyro","properties":{"topic":"/SmartDashboard/Test Gyro","period":0.033,"counter_clockwise_positive":false}},{"title":"Test Distribution","x":640.0,"y":0.0,"width":384.0,"height":512.0,"type":"PowerDistribution","properties":{"topic":"/SmartDashboard/Test Distribution","period":0.033}},{"title":"Test PID Controller","x":1024.0,"y":0.0,"width":256.0,"height":384.0,"type":"PIDController","properties":{"topic":"/SmartDashboard/Test PID Controller","period":0.033,"kp_topic":"/SmartDashboard/Test PID Controller/p","ki_topic":"/SmartDashboard/Test PID Controller/i","kd_topic":"/SmartDashboard/Test PID Controller/d","setpoint_topic":"/SmartDashboard/Test PID Controller/setpoint"}},{"title":"USB Camera 0","x":0.0,"y":384.0,"width":128.0,"height":128.0,"type":"Camera Stream","properties":{"topic":"/CameraPublisher/USB Camera 0","period":0.033}},{"title":"FMSInfo","x":256.0,"y":256.0,"width":384.0,"height":128.0,"type":"FMSInfo","properties":{"topic":"/FMSInfo","period":0.033}},{"title":"Match Time","x":128.0,"y":384.0,"width":128.0,"height":128.0,"type":"Match Time","properties":{"topic":"/SmartDashboard/Match Time","period":0.033}}]}},{"name":"Autonomous","grid_layout":{"containers":[{"title":"Test Chooser","x":0.0,"y":0.0,"width":256.0,"height":128.0,"type":"ComboBox Chooser","properties":{"topic":"/SmartDashboard/Test Chooser","period":0.033}},{"title":"Command Scheduler","x":256.0,"y":0.0,"width":256.0,"height":384.0,"type":"Scheduler","properties":{"topic":"/SmartDashboard/Command Scheduler","period":0.033}},{"title":"Drive System","x":512.0,"y":128.0,"width":256.0,"height":128.0,"type":"Subsystem","properties":{"topic":"/SmartDashboard/Drive System","period":0.033}},{"title":"Rainbow Color Array","x":0.0,"y":256.0,"width":256.0,"height":128.0,"type":"Multi Color View","properties":{"topic":"/SmartDashboard/Rainbow Color Array","period":0.033}},{"title":"Voltage","x":0.0,"y":384.0,"width":256.0,"height":128.0,"type":"Voltage View","properties":{"topic":"/SmartDashboard/Voltage","period":0.033,"min_value":4.0,"max_value":13.0,"divisions":5,"inverted":false,"orientation":"horizontal"}},{"title":"Auto Path","x":512.0,"y":0.0,"width":256.0,"height":128.0,"type":"Command","properties":{"topic":"/SmartDashboard/Auto Path","period":0.033}},{"title":"Test Boolean","x":512.0,"y":256.0,"width":128.0,"height":128.0,"type":"Toggle Switch","properties":{"topic":"/SmartDashboard/Test Boolean","period":0.033}},{"title":"Test Boolean","x":640.0,"y":256.0,"width":128.0,"height":128.0,"type":"Toggle Button","properties":{"topic":"/SmartDashboard/Test Boolean","period":0.033}},{"title":"Preferences","x":768.0,"y":0.0,"width":256.0,"height":384.0,"type":"RobotPreferences","properties":{"topic":"/Preferences","period":0.033}},{"title":"Auto Chooser","x":0.0,"y":128.0,"width":256.0,"height":128.0,"type":"Split Button Chooser","properties":{"topic":"/SmartDashboard/Auto Chooser","period":0.033}},{"title":"Rainbow Color","x":256.0,"y":384.0,"width":128.0,"height":128.0,"type":"Single Color View","properties":{"topic":"/SmartDashboard/Rainbow Color","period":0.033}},{"title":"Test Number","x":384.0,"y":384.0,"width":128.0,"height":128.0,"type":"Number Bar","properties":{"topic":"/SmartDashboard/Test Number","period":0.033,"min_value":-1.0,"max_value":1.0,"divisions":5,"inverted":false,"orientation":"horizontal"}},{"title":"Test Number","x":512.0,"y":384.0,"width":256.0,"height":128.0,"type":"Number Slider","properties":{"topic":"/SmartDashboard/Test Number","period":0.033,"min_value":-1.0,"max_value":1.0,"divisions":5}},{"title":"Voltage","x":768.0,"y":384.0,"width":256.0,"height":128.0,"type":"Graph","properties":{"topic":"/SmartDashboard/Voltage","period":0.033,"time_displayed":5.0,"min_value":null,"max_value":null,"color":4278238420}}]}}]}

0 comments on commit b703b12

Please sign in to comment.