diff --git a/test/pages/dashboard_page_test.dart b/test/pages/dashboard_page_test.dart index 76114844..58bd11a3 100644 --- a/test/pages/dashboard_page_test.dart +++ b/test/pages/dashboard_page_test.dart @@ -8,12 +8,14 @@ import 'package:elastic_dashboard/services/nt4_connection.dart'; import 'package:elastic_dashboard/widgets/custom_appbar.dart'; import 'package:elastic_dashboard/widgets/dashboard_grid.dart'; import 'package:elastic_dashboard/widgets/dialog_widgets/dialog_text_input.dart'; +import 'package:elastic_dashboard/widgets/dialog_widgets/layout_drag_tile.dart'; import 'package:elastic_dashboard/widgets/draggable_containers/draggable_list_layout.dart'; import 'package:elastic_dashboard/widgets/draggable_dialog.dart'; import 'package:elastic_dashboard/widgets/draggable_containers/draggable_widget_container.dart'; import 'package:elastic_dashboard/widgets/editable_tab_bar.dart'; import 'package:elastic_dashboard/widgets/network_tree/network_table_tree.dart'; import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/combo_box_chooser.dart'; +import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/boolean_box.dart'; import 'package:elastic_dashboard/widgets/settings_dialog.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; @@ -132,7 +134,7 @@ void main() { expect(jsonString, preferences.getString(PrefKeys.layout)); }); - testWidgets('Add widget dialog', (widgetTester) async { + testWidgets('Add widget dialog (widgets)', (widgetTester) async { FlutterError.onError = ignoreOverflowErrors; setupMockOnlineNT4(); @@ -196,6 +198,147 @@ void main() { await widgetTester.pumpAndSettle(); }); + testWidgets('Add widget dialog (layouts)', (widgetTester) async { + FlutterError.onError = ignoreOverflowErrors; + setupMockOnlineNT4(); + + await widgetTester.pumpWidget( + MaterialApp( + home: DashboardPage( + connectionStream: Stream.value(true), + preferences: preferences, + version: '0.0.0.0', + ), + ), + ); + + await widgetTester.pumpAndSettle(); + + final addWidget = find.widgetWithText(MenuItemButton, 'Add Widget'); + + expect(addWidget, findsOneWidget); + expect(find.widgetWithText(DraggableDialog, 'Add Widget'), findsNothing); + + MenuItemButton addWidgetButton = + addWidget.evaluate().first.widget as MenuItemButton; + + addWidgetButton.onPressed?.call(); + + await widgetTester.pumpAndSettle(); + + expect(find.widgetWithText(DraggableDialog, 'Add Widget'), findsOneWidget); + + final layoutsTab = find.text('Layouts'); + expect(layoutsTab, findsOneWidget); + + await widgetTester.tap(layoutsTab); + await widgetTester.pumpAndSettle(); + + final listLayoutContainer = + find.widgetWithText(WidgetContainer, 'List Layout'); + expect(listLayoutContainer, findsNothing); + + final listLayoutTile = find.widgetWithText(LayoutDragTile, 'List Layout'); + expect(listLayoutTile, findsOneWidget); + + await widgetTester.drag(listLayoutTile, const Offset(100, 100), + kind: PointerDeviceKind.mouse); + await widgetTester.pumpAndSettle(); + + expect(listLayoutContainer, findsNothing); + + await widgetTester.drag(listLayoutTile, const Offset(300, -150), + kind: PointerDeviceKind.mouse); + await widgetTester.pumpAndSettle(); + + expect(listLayoutContainer, findsOneWidget); + }); + + testWidgets('List Layouts', (widgetTester) async { + FlutterError.onError = ignoreOverflowErrors; + setupMockOnlineNT4(); + + await widgetTester.pumpWidget( + MaterialApp( + home: DashboardPage( + connectionStream: Stream.value(true), + preferences: preferences, + version: '0.0.0.0', + ), + ), + ); + + await widgetTester.pumpAndSettle(); + + final addWidget = find.widgetWithText(MenuItemButton, 'Add Widget'); + + expect(addWidget, findsOneWidget); + expect(find.widgetWithText(DraggableDialog, 'Add Widget'), findsNothing); + + MenuItemButton addWidgetButton = + addWidget.evaluate().first.widget as MenuItemButton; + + addWidgetButton.onPressed?.call(); + + await widgetTester.pumpAndSettle(); + + expect(find.widgetWithText(DraggableDialog, 'Add Widget'), findsOneWidget); + + final layoutsTab = find.text('Layouts'); + expect(layoutsTab, findsOneWidget); + + await widgetTester.tap(layoutsTab); + await widgetTester.pumpAndSettle(); + + final listLayoutContainer = + find.widgetWithText(WidgetContainer, 'List Layout'); + expect(listLayoutContainer, findsNothing); + + final listLayoutTile = find.widgetWithText(LayoutDragTile, 'List Layout'); + expect(listLayoutTile, findsOneWidget); + + await widgetTester.drag(listLayoutTile, const Offset(100, 100), + kind: PointerDeviceKind.mouse); + await widgetTester.pumpAndSettle(); + + expect(listLayoutContainer, findsNothing); + + await widgetTester.drag(listLayoutTile, const Offset(300, -150), + kind: PointerDeviceKind.mouse); + await widgetTester.pumpAndSettle(); + + expect(listLayoutContainer, findsOneWidget); + + final closeButton = find.widgetWithText(TextButton, 'Close'); + expect(closeButton, findsOneWidget); + + await widgetTester.tap(closeButton); + await widgetTester.pumpAndSettle(); + + final testBooleanContainer = + find.widgetWithText(WidgetContainer, 'Test Boolean'); + expect(testBooleanContainer, findsOneWidget); + + final testBooleanInLayout = find.descendant( + of: find.widgetWithText(WidgetContainer, 'List Layout'), + matching: find.byType(BooleanBox)); + expect(testBooleanInLayout, findsNothing); + + // Drag into layout + await widgetTester.timedDrag(testBooleanContainer, const Offset(256, 32), + const Duration(milliseconds: 500)); + await widgetTester.pumpAndSettle(); + + expect(testBooleanInLayout, findsOneWidget); + + // Drag out of layout + await widgetTester.timedDrag(testBooleanContainer, const Offset(-256, -32), + const Duration(milliseconds: 500)); + await widgetTester.pumpAndSettle(); + + expect(testBooleanInLayout, findsNothing); + }); + testWidgets('Adding widgets from shuffleboard api', (widgetTester) async { FlutterError.onError = ignoreOverflowErrors; diff --git a/test_resources/test-layout.json b/test_resources/test-layout.json index e94c4acf..4138c928 100644 --- a/test_resources/test-layout.json +++ b/test_resources/test-layout.json @@ -1 +1 @@ -{"tabs":[{"name":"Teleoperated","grid_layout":{"layouts":[{"title":"List Layout","x":1280.0,"y":0.0,"width":256.0,"height":384.0,"type":"List Layout","children":[{"title":"Differential Drive","x":0.0,"y":0.0,"width":384.0,"height":256.0,"type":"DifferentialDrive","properties":{"topic":"/SmartDashboard/Differential Drive","period":0.033}},{"title":"Test Boolean","x":0.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}}]}],"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}},{"title":"Swerve Drive","x":1024.0,"y":384.0,"width":256.0,"height":256.0,"type":"SwerveDrive","properties":{"topic":"/SmartDashboard/Swerve Drive","period":0.033,"show_robot_rotation":true}}]}},{"name":"Autonomous","grid_layout":{"layouts":[],"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}}]}}]} \ No newline at end of file +{"tabs":[{"name":"Teleoperated","grid_layout":{"layouts":[{"title":"Example List Layout","x":1280.0,"y":0.0,"width":256.0,"height":384.0,"type":"List Layout","children":[{"title":"Differential Drive","x":0.0,"y":0.0,"width":384.0,"height":256.0,"type":"DifferentialDrive","properties":{"topic":"/SmartDashboard/Differential Drive","period":0.033}},{"title":"List Layout Boolean","x":0.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}}]}],"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}},{"title":"Swerve Drive","x":1024.0,"y":384.0,"width":256.0,"height":256.0,"type":"SwerveDrive","properties":{"topic":"/SmartDashboard/Swerve Drive","period":0.033,"show_robot_rotation":true}}]}},{"name":"Autonomous","grid_layout":{"layouts":[],"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 Toggle Button","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}}]}}]} \ No newline at end of file