From a504319ee7c154ecd697d47534d1614b82a80930 Mon Sep 17 00:00:00 2001 From: git-elliot Date: Tue, 12 Nov 2024 19:14:14 +0530 Subject: [PATCH] changed keys to widgetkeys --- .github/workflows/flutter_test.yml | 2 +- integration_test/app_test.dart | 29 +++++------- lib/pages/home_page.dart | 4 +- .../widgets/host_scan_widget.dart | 4 +- .../network_troubleshoot/port_scan_page.dart | 24 +++++----- lib/values/keys.dart | 44 ++++++++++--------- pubspec.yaml | 4 -- test/widget_test.dart | 11 +---- 8 files changed, 55 insertions(+), 67 deletions(-) diff --git a/.github/workflows/flutter_test.yml b/.github/workflows/flutter_test.yml index 9bbc411..0e87da7 100644 --- a/.github/workflows/flutter_test.yml +++ b/.github/workflows/flutter_test.yml @@ -96,7 +96,7 @@ jobs: - name: Run tests run: flutter test - name: Run integration tests - if: ${{ steps.extract_branch.outputs.branch == 'main' }} + if: ${{ steps.extract_branch.outputs.branch == 'dev' }} run: flutter test integration_test -d macos android-linux-build: diff --git a/integration_test/app_test.dart b/integration_test/app_test.dart index 4a09d9e..704bd9d 100644 --- a/integration_test/app_test.dart +++ b/integration_test/app_test.dart @@ -1,10 +1,3 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility that Flutter provides. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; @@ -44,7 +37,7 @@ void main() { expect(find.bySubtype(), findsAtLeastNWidgets(4)); // Finds the scan for devices button to tap on. - final devicesButton = find.byKey(Keys.scanForDevicesButton); + final devicesButton = find.byKey(WidgetKey.scanForDevicesButton.key); // Emulate a tap on the button. await tester.tap(devicesButton); @@ -54,22 +47,23 @@ void main() { await tester.pump(); expect(find.byType(AdaptiveListTile), findsAtLeast(2)); - final routerIconButton = find.byKey(Keys.routerOrGatewayTileIconButton); + final routerIconButton = + find.byKey(WidgetKey.routerOrGatewayTileIconButton.key); await tester.tap(routerIconButton); await tester.pumpAndSettle(); expect(find.byType(AppBar), findsOne); - final radioButton = find.byKey(Keys.rangePortScanRadioButton); + final radioButton = find.byKey(WidgetKey.rangePortScanRadioButton.key); await tester.tap(radioButton); await tester.pumpAndSettle(); - final portChip = find.byKey(Keys.knownPortChip); + final portChip = find.byKey(WidgetKey.knownPortChip.key); await tester.tap(portChip); await tester.pumpAndSettle(); - final portScanButton = find.byKey(Keys.portScanButton); + final portScanButton = find.byKey(WidgetKey.portScanButton.key); await tester.tap(portScanButton); await tester.pumpAndSettle(); }); @@ -83,25 +77,26 @@ void main() { expect(find.bySubtype(), findsAtLeastNWidgets(4)); // Finds the open ports button to tap on. - final scanForOpenPortsButton = find.byKey(Keys.scanForOpenPortsButton); + final scanForOpenPortsButton = + find.byKey(WidgetKey.scanForOpenPortsButton.key); await tester.tap(scanForOpenPortsButton); await tester.pumpAndSettle(); expect(find.byType(AppBar), findsOne); - final googleChip = find.byKey(Keys.googleChip); + final googleChip = find.byKey(WidgetKey.googleChip.key); await tester.tap(googleChip); await tester.pumpAndSettle(); - final radioButton = find.byKey(Keys.rangePortScanRadioButton); + final radioButton = find.byKey(WidgetKey.rangePortScanRadioButton.key); await tester.tap(radioButton); await tester.pumpAndSettle(); - final portChip = find.byKey(Keys.knownPortChip); + final portChip = find.byKey(WidgetKey.knownPortChip.key); await tester.tap(portChip); await tester.pumpAndSettle(); - final portScanButton = find.byKey(Keys.portScanButton); + final portScanButton = find.byKey(WidgetKey.portScanButton.key); await tester.tap(portScanButton); await tester.pumpAndSettle(const Duration(seconds: 20)); await tester.pump(); diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index 7357029..0efe4e9 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -169,7 +169,7 @@ class _WifiDetailState extends State { width: 4, ), ElevatedButton( - key: Keys.scanForDevicesButton, + key: WidgetKey.scanForDevicesButton.key, onPressed: () { Navigator.push( context, @@ -223,7 +223,7 @@ class _WifiDetailState extends State { ), const SizedBox(width: 10), ElevatedButton.icon( - key: Keys.scanForOpenPortsButton, + key: WidgetKey.scanForOpenPortsButton.key, onPressed: () { Navigator.push( context, diff --git a/lib/pages/host_scan_page/widgets/host_scan_widget.dart b/lib/pages/host_scan_page/widgets/host_scan_widget.dart index 59c7645..d784c27 100644 --- a/lib/pages/host_scan_page/widgets/host_scan_widget.dart +++ b/lib/pages/host_scan_page/widgets/host_scan_widget.dart @@ -73,7 +73,7 @@ class HostScanWidget extends StatelessWidget { trailing: loading ? const SizedBox() : IconButton( - key: Keys.rescanIconButton, + key: WidgetKey.rescanIconButton.key, onPressed: () { context .read() @@ -95,7 +95,7 @@ class HostScanWidget extends StatelessWidget { ), trailing: IconButton( key: host.deviceMake == 'Router/Gateway' - ? Keys.routerOrGatewayTileIconButton + ? WidgetKey.routerOrGatewayTileIconButton.key : null, tooltip: TooltipMessages.currentDevicePortScan, icon: const Icon(Icons.radar), diff --git a/lib/pages/network_troubleshoot/port_scan_page.dart b/lib/pages/network_troubleshoot/port_scan_page.dart index 7a050fe..3e56525 100644 --- a/lib/pages/network_troubleshoot/port_scan_page.dart +++ b/lib/pages/network_troubleshoot/port_scan_page.dart @@ -311,7 +311,7 @@ class _PortScanPageState extends State Expanded( child: CustomTile( leading: Radio( - key: Keys.rangePortScanRadioButton, + key: WidgetKey.rangePortScanRadioButton.key, value: ScanType.range, groupValue: _type, onChanged: (ScanType? value) { @@ -345,7 +345,7 @@ class _PortScanPageState extends State Padding( padding: const EdgeInsets.all(3.0), child: ElevatedButton( - key: Keys.portScanButton, + key: WidgetKey.portScanButton.key, onPressed: _completed ? () { if (_formKey.currentState!.validate()) { @@ -384,27 +384,27 @@ class _PortScanPageState extends State Wrap( children: [ _getDomainChip( - Keys.localIpChip, + WidgetKey.localIpChip.key, '192.168.1.1', ), _getDomainChip( - Keys.googleChip, + WidgetKey.googleChip.key, 'google.com', ), _getDomainChip( - Keys.youtubeChip, + WidgetKey.youtubeChip.key, 'youtube.com', ), _getDomainChip( - Keys.appleChip, + WidgetKey.appleChip.key, 'apple.com', ), _getDomainChip( - Keys.amazonChip, + WidgetKey.amazonChip.key, 'amazon.com', ), _getDomainChip( - Keys.cloudflareChip, + WidgetKey.cloudflareChip.key, 'cloudflare.com', ), ], @@ -412,25 +412,25 @@ class _PortScanPageState extends State Wrap( children: [ _getCustomRangeChip( - Keys.knownPortChip, + WidgetKey.knownPortChip.key, '0-1024 (known)', '0', '1024', ), _getCustomRangeChip( - Keys.shortPortChip, + WidgetKey.shortPortChip.key, '0-100 (short)', '0', '100', ), _getCustomRangeChip( - Keys.veryShortPortChip, + WidgetKey.veryShortPortChip.key, '0-10 (very short)', '0', '10', ), _getCustomRangeChip( - Keys.fullPortChip, + WidgetKey.fullPortChip.key, '0-65535 (Full)', '0', '65535', diff --git a/lib/values/keys.dart b/lib/values/keys.dart index ce4486f..583fd6b 100644 --- a/lib/values/keys.dart +++ b/lib/values/keys.dart @@ -1,23 +1,27 @@ import 'package:flutter/material.dart'; -class Keys { - static const ValueKey scanForDevicesButton = ValueKey('scanForDevicesButton'); - static const ValueKey scanForOpenPortsButton = - ValueKey('scanForOpenPortsButton'); - static const ValueKey rescanIconButton = ValueKey('rescanIconButton'); - static const ValueKey portScanButton = ValueKey('portScanButton'); - static const ValueKey routerOrGatewayTileIconButton = - ValueKey('Router/Gateway'); - static const ValueKey rangePortScanRadioButton = - ValueKey('rangePortScanRadioButton'); - static const ValueKey knownPortChip = ValueKey('knowPortChip'); - static const ValueKey shortPortChip = ValueKey('shortPortChip'); - static const ValueKey veryShortPortChip = ValueKey('veryShortPortChip'); - static const ValueKey fullPortChip = ValueKey('fullPortChip'); - static const ValueKey localIpChip = ValueKey('localIpChip'); - static const ValueKey googleChip = ValueKey('googleChip'); - static const ValueKey youtubeChip = ValueKey('youtubeChip'); - static const ValueKey appleChip = ValueKey('appleChip'); - static const ValueKey amazonChip = ValueKey('amazonChip'); - static const ValueKey cloudflareChip = ValueKey('cloudflareChip'); +enum WidgetKey implements Comparable { + routerOrGatewayTileIconButton('routerOrGatewayTileIconButton'), + rangePortScanRadioButton('rangePortScanRadioButton'), + scanForOpenPortsButton('scanForOpenPortsButton'), + scanForDevicesButton('scanForDevicesButton'), + veryShortPortChip('veryShortPortChip'), + rescanIconButton('rescanIconButton'), + portScanButton('portScanButton'), + cloudflareChip('cloudflareChip'), + knownPortChip('knownPortChip'), + shortPortChip('shortPortChip'), + fullPortChip('fullPortChip'), + youtubeChip('youtubeChip'), + localIpChip('localIpChip'), + googleChip('googleChip'), + amazonChip('amazonChip'), + appleChip('appleChip'); + + const WidgetKey(this.value); + final String value; + ValueKey get key => ValueKey(value); + + @override + int compareTo(WidgetKey other) => value.compareTo(other.value); } diff --git a/pubspec.yaml b/pubspec.yaml index 1c3dfbc..2475515 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -49,10 +49,6 @@ dependencies: network_info_plus: ^4.0.2 # Helps you discover open ports, devices on subnet and more. network_tools_flutter: ^2.0.2 - # network_tools_flutter: - # git: - # url: https://github.com/osociety/network_tools_flutter.git - # ref: dev # branch name # Querying information about the application package, such as CFBundleVersion package_info_plus: ^4.1.0 path_provider: ^2.1.1 diff --git a/test/widget_test.dart b/test/widget_test.dart index 1b60fe8..a23e454 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -1,16 +1,9 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility that Flutter provides. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - import 'package:flutter_test/flutter_test.dart'; import 'package:vernet/main.dart'; Future main() async { - group('widget test', () { - testWidgets('my first widget test', (tester) async { + group('Widget test', () { + testWidgets('My first widget test', (tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const MyApp(false)); });