Skip to content

Commit

Permalink
changed keys to widgetkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
git-elliot committed Nov 12, 2024
1 parent a74b540 commit a504319
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flutter_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 12 additions & 17 deletions integration_test/app_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -44,7 +37,7 @@ void main() {
expect(find.bySubtype<AdaptiveListTile>(), 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);
Expand All @@ -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();
});
Expand All @@ -83,25 +77,26 @@ void main() {
expect(find.bySubtype<AdaptiveListTile>(), 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();
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class _WifiDetailState extends State<HomePage> {
width: 4,
),
ElevatedButton(
key: Keys.scanForDevicesButton,
key: WidgetKey.scanForDevicesButton.key,
onPressed: () {
Navigator.push(
context,
Expand Down Expand Up @@ -223,7 +223,7 @@ class _WifiDetailState extends State<HomePage> {
),
const SizedBox(width: 10),
ElevatedButton.icon(
key: Keys.scanForOpenPortsButton,
key: WidgetKey.scanForOpenPortsButton.key,
onPressed: () {
Navigator.push(
context,
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/host_scan_page/widgets/host_scan_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class HostScanWidget extends StatelessWidget {
trailing: loading
? const SizedBox()
: IconButton(
key: Keys.rescanIconButton,
key: WidgetKey.rescanIconButton.key,
onPressed: () {
context
.read<HostScanBloc>()
Expand All @@ -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),
Expand Down
24 changes: 12 additions & 12 deletions lib/pages/network_troubleshoot/port_scan_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class _PortScanPageState extends State<PortScanPage>
Expanded(
child: CustomTile(
leading: Radio<ScanType>(
key: Keys.rangePortScanRadioButton,
key: WidgetKey.rangePortScanRadioButton.key,
value: ScanType.range,
groupValue: _type,
onChanged: (ScanType? value) {
Expand Down Expand Up @@ -345,7 +345,7 @@ class _PortScanPageState extends State<PortScanPage>
Padding(
padding: const EdgeInsets.all(3.0),
child: ElevatedButton(
key: Keys.portScanButton,
key: WidgetKey.portScanButton.key,
onPressed: _completed
? () {
if (_formKey.currentState!.validate()) {
Expand Down Expand Up @@ -384,53 +384,53 @@ class _PortScanPageState extends State<PortScanPage>
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',
),
],
),
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',
Expand Down
44 changes: 24 additions & 20 deletions lib/values/keys.dart
Original file line number Diff line number Diff line change
@@ -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<WidgetKey> {
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);
}
4 changes: 0 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
@@ -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<void> 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));
});
Expand Down

0 comments on commit a504319

Please sign in to comment.