Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some clean up and refactoring for query parameter logic #8316

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add testing
  • Loading branch information
kenzieschmoll committed Sep 10, 2024
commit 014544de8171e129a2910a82991aa6847df29070
22 changes: 11 additions & 11 deletions packages/devtools_app/lib/src/shared/query_parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ extension type DevToolsQueryParams(Map<String, String?> params) {
/// The URI for the VM Service that DevTools is connected to.
String? get vmServiceUri => params[vmServiceUriKey];

/// The current [EmbedMode] of DevTools based on the query parameters.
EmbedMode get embedMode => ideThemeParams.embedMode;

/// The set of screens that are hidden based on the query parameters.
Set<String> get hiddenScreens => {...?params[hideScreensKey]?.split(',')};

Expand All @@ -45,22 +42,25 @@ extension type DevToolsQueryParams(Map<String, String?> params) {
/// opening the Flutter Inspector.
String? get inspectorRef => params[inspectorRefKey];

/// Keys for theming values that an IDE may pass in the embedded DevTools URI.
IdeThemeQueryParams get ideThemeParams => IdeThemeQueryParams(params);
/// The file path for the base file to load on the App Size screen.
String? get appSizeBaseFilePath =>
params[AppSizeApi.baseAppSizeFilePropertyName];

/// The file path for the test file to load on the App Size screen.
String? get appSizeTestFilePath =>
params[AppSizeApi.testAppSizeFilePropertyName];

/// The IDE that DevTools is embedded in or was launched from.
String? get ide => params[ideKey];

/// The feature of the IDE that DevTools was opened from.
String? get ideFeature => params[ideFeatureKey];

/// The file path for the base file to load on the App Size screen.
String? get appSizeBaseFilePath =>
params[AppSizeApi.baseAppSizeFilePropertyName];
/// Keys for theming values that an IDE may pass in the embedded DevTools URI.
IdeThemeQueryParams get ideThemeParams => IdeThemeQueryParams(params);

/// The file path for the test file to load on the App Size screen.
String? get appSizeTestFilePath =>
params[AppSizeApi.testAppSizeFilePropertyName];
/// The current [EmbedMode] of DevTools based on the query parameters.
EmbedMode get embedMode => ideThemeParams.embedMode;

static const vmServiceUriKey = 'uri';
static const hideScreensKey = 'hide';
Expand Down
59 changes: 47 additions & 12 deletions packages/devtools_app/test/shared/query_parameters_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'dart:ui';
import 'package:devtools_app/devtools_app.dart';
import 'package:devtools_app/src/shared/query_parameters.dart';
import 'package:devtools_app_shared/shared.dart';
import 'package:devtools_app_shared/ui.dart';
import 'package:devtools_shared/devtools_shared.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
Expand All @@ -17,26 +19,36 @@ void main() {
DevToolsQueryParams.hideScreensKey:
'foo,bar,extensions,all-except-extensions',
DevToolsQueryParams.offlineScreenIdKey: 'performance',
DevToolsQueryParams.inspectorRefKey: '12345',
AppSizeApi.baseAppSizeFilePropertyName: '/path/to/base/file.json',
AppSizeApi.testAppSizeFilePropertyName: '/path/to/test/file.json',
DevToolsQueryParams.ideKey: 'Android-Studio',
DevToolsQueryParams.ideFeatureKey: 'onDebugAutomatic',
DevToolsQueryParams.legacyPageKey: 'memory',
// IdeThemeQueryParams values
'embedMode': 'one',
'backgroundColor': '#112233',
'foregroundColor': '#112244',
'fontSize': '8.0',
'theme': 'dark',
IdeThemeQueryParams.backgroundColorKey: '#112233',
IdeThemeQueryParams.foregroundColorKey: '#112244',
IdeThemeQueryParams.fontSizeKey: '8.0',
IdeThemeQueryParams.devToolsThemeKey: 'dark',
});

expect(params.vmServiceUri, 'some_uri');
expect(params.embedMode, EmbedMode.embedOne);
expect(
params.hiddenScreens,
{'foo', 'bar', 'extensions', 'all-except-extensions'},
);
expect(params.hideExtensions, true);
expect(params.hideAllExceptExtensions, true);
expect(params.offlineScreenId, 'performance');
expect(params.inspectorRef, '12345');
expect(params.appSizeBaseFilePath, '/path/to/base/file.json');
expect(params.appSizeTestFilePath, '/path/to/test/file.json');
expect(params.ide, 'Android-Studio');
expect(params.ideFeature, 'onDebugAutomatic');
expect(params.legacyPage, 'memory');
expect(params.ideThemeParams.params, isNotEmpty);
expect(params.embedMode, EmbedMode.embedOne);
expect(params.ideThemeParams.embedMode, EmbedMode.embedOne);
expect(params.ideThemeParams.backgroundColor, const Color(0xFF112233));
expect(params.ideThemeParams.foregroundColor, const Color(0xFF112244));
Expand All @@ -47,33 +59,50 @@ void main() {
test('creates empty params', () {
final params = DevToolsQueryParams.empty();
expect(params.vmServiceUri, isNull);
expect(params.embedMode, EmbedMode.none);
expect(params.hiddenScreens, isEmpty);
expect(params.hideExtensions, false);
expect(params.hideAllExceptExtensions, false);
expect(params.offlineScreenId, isNull);
expect(params.inspectorRef, isNull);
expect(params.appSizeBaseFilePath, isNull);
expect(params.appSizeTestFilePath, isNull);
expect(params.ide, isNull);
expect(params.ideFeature, isNull);
expect(params.legacyPage, isNull);
expect(params.ideThemeParams.params, isEmpty);
expect(params.embedMode, EmbedMode.none);
});

test('creates params with updates', () {
var params = DevToolsQueryParams({
DevToolsQueryParams.vmServiceUriKey: 'some_uri',
DevToolsQueryParams.hideScreensKey: 'foo,bar,baz',
DevToolsQueryParams.offlineScreenIdKey: 'performance',
DevToolsQueryParams.inspectorRefKey: '12345',
AppSizeApi.baseAppSizeFilePropertyName: '/path/to/base/file.json',
AppSizeApi.testAppSizeFilePropertyName: '/path/to/test/file.json',
DevToolsQueryParams.ideKey: 'Android-Studio',
DevToolsQueryParams.ideFeatureKey: 'onDebugAutomatic',
DevToolsQueryParams.legacyPageKey: 'memory',
// IdeThemeQueryParams values
'embedMode': 'one',
'backgroundColor': '#112233',
'foregroundColor': '#112244',
'fontSize': '8.0',
'theme': 'dark',
IdeThemeQueryParams.backgroundColorKey: '#112233',
IdeThemeQueryParams.foregroundColorKey: '#112244',
IdeThemeQueryParams.fontSizeKey: '8.0',
IdeThemeQueryParams.devToolsThemeKey: 'dark',
});

expect(params.vmServiceUri, 'some_uri');
expect(params.embedMode, EmbedMode.embedOne);
expect(params.hiddenScreens, {'foo', 'bar', 'baz'});
expect(params.offlineScreenId, 'performance');
expect(params.inspectorRef, '12345');
expect(params.appSizeBaseFilePath, '/path/to/base/file.json');
expect(params.appSizeTestFilePath, '/path/to/test/file.json');
expect(params.ide, 'Android-Studio');
expect(params.ideFeature, 'onDebugAutomatic');
expect(params.legacyPage, 'memory');
expect(params.ideThemeParams.params, isNotEmpty);
expect(params.embedMode, EmbedMode.embedOne);
expect(params.ideThemeParams.embedMode, EmbedMode.embedOne);
expect(params.ideThemeParams.backgroundColor, const Color(0xFF112233));
expect(params.ideThemeParams.foregroundColor, const Color(0xFF112244));
Expand All @@ -83,18 +112,24 @@ void main() {
params = params.withUpdates({
DevToolsQueryParams.vmServiceUriKey: 'some_other_uri',
DevToolsQueryParams.hideScreensKey: 'foo',
DevToolsQueryParams.inspectorRefKey: '23456',
// Update some IdeThemeQueryParams values
'embedMode': 'many',
'fontSize': '10.0',
'theme': 'light',
});

expect(params.vmServiceUri, 'some_other_uri');
expect(params.embedMode, EmbedMode.embedMany);
expect(params.hiddenScreens, {'foo'});
expect(params.offlineScreenId, 'performance');
expect(params.inspectorRef, '23456');
expect(params.appSizeBaseFilePath, '/path/to/base/file.json');
expect(params.appSizeTestFilePath, '/path/to/test/file.json');
expect(params.ide, 'Android-Studio');
expect(params.ideFeature, 'onDebugAutomatic');
expect(params.legacyPage, 'memory');
expect(params.ideThemeParams.params, isNotEmpty);
expect(params.embedMode, EmbedMode.embedMany);
expect(params.ideThemeParams.embedMode, EmbedMode.embedMany);
expect(params.ideThemeParams.backgroundColor, const Color(0xFF112233));
expect(params.ideThemeParams.foregroundColor, const Color(0xFF112244));
Expand Down