Refactoring the setPubRootDirectory tests (#106197)
This commit is contained in:
parent
3d87343af9
commit
8ff691178c
@ -1201,84 +1201,253 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
|||||||
expect(nodes[3].runtimeType, StringProperty);
|
expect(nodes[3].runtimeType, StringProperty);
|
||||||
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag.
|
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag.
|
||||||
|
|
||||||
testWidgets('WidgetInspectorService setPubRootDirectories', (WidgetTester tester) async {
|
group(
|
||||||
await tester.pumpWidget(
|
'WidgetInspectorService',
|
||||||
Directionality(
|
() {
|
||||||
textDirection: TextDirection.ltr,
|
group('setPubRootDirectories', () {
|
||||||
child: Stack(
|
late final String pubRootTest;
|
||||||
children: const <Widget>[
|
|
||||||
Text('a'),
|
|
||||||
Text('b', textDirection: TextDirection.ltr),
|
|
||||||
Text('c', textDirection: TextDirection.ltr),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
final Element elementA = find.text('a').evaluate().first;
|
|
||||||
|
|
||||||
service.disposeAllGroups();
|
setUpAll(() {
|
||||||
service.setPubRootDirectories(<String>[]);
|
pubRootTest = generateTestPubRootDirectory(service);
|
||||||
service.setSelection(elementA, 'my-group');
|
});
|
||||||
Map<String, Object?> jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object?>;
|
|
||||||
Map<String, Object?> creationLocation = jsonObject['creationLocation']! as Map<String, Object?>;
|
|
||||||
expect(creationLocation, isNotNull);
|
|
||||||
final String fileA = creationLocation['file']! as String;
|
|
||||||
expect(fileA, endsWith('widget_inspector_test.dart'));
|
|
||||||
expect(jsonObject, isNot(contains('createdByLocalProject')));
|
|
||||||
final List<String> segments = Uri.parse(fileA).pathSegments;
|
|
||||||
// Strip a couple subdirectories away to generate a plausible pub root
|
|
||||||
// directory.
|
|
||||||
final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}';
|
|
||||||
service.setPubRootDirectories(<String>[pubRootTest]);
|
|
||||||
|
|
||||||
service.setSelection(elementA, 'my-group');
|
setUp(() {
|
||||||
expect(json.decode(service.getSelectedWidget(null, 'my-group')), contains('createdByLocalProject'));
|
service.disposeAllGroups();
|
||||||
|
service.setPubRootDirectories(<String>[]);
|
||||||
|
});
|
||||||
|
|
||||||
service.setPubRootDirectories(<String>['/invalid/$pubRootTest']);
|
testWidgets(
|
||||||
expect(json.decode(service.getSelectedWidget(null, 'my-group')), isNot(contains('createdByLocalProject')));
|
'does not have createdByLocalProject when there are no pubRootDirectories',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
final Widget widget = Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(widget);
|
||||||
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
|
||||||
service.setPubRootDirectories(<String>['file://$pubRootTest']);
|
final Map<String, Object?> jsonObject =
|
||||||
expect(json.decode(service.getSelectedWidget(null, 'my-group')), contains('createdByLocalProject'));
|
json.decode(service.getSelectedWidget(null, 'my-group'))
|
||||||
|
as Map<String, Object?>;
|
||||||
|
final Map<String, Object?> creationLocation =
|
||||||
|
jsonObject['creationLocation']! as Map<String, Object?>;
|
||||||
|
|
||||||
service.setPubRootDirectories(<String>['$pubRootTest/different']);
|
expect(creationLocation, isNotNull);
|
||||||
expect(json.decode(service.getSelectedWidget(null, 'my-group')), isNot(contains('createdByLocalProject')));
|
final String fileA = creationLocation['file']! as String;
|
||||||
|
expect(fileA, endsWith('widget_inspector_test.dart'));
|
||||||
|
expect(jsonObject, isNot(contains('createdByLocalProject')));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
service.setPubRootDirectories(<String>[
|
testWidgets(
|
||||||
'/invalid/$pubRootTest',
|
'has createdByLocalProject when the element is part of the pubRootDirectory',
|
||||||
pubRootTest,
|
(WidgetTester tester) async {
|
||||||
]);
|
final Widget widget = Directionality(
|
||||||
expect(json.decode(service.getSelectedWidget(null, 'my-group')), contains('createdByLocalProject'));
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(widget);
|
||||||
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
|
|
||||||
// The RichText child of the Text widget is created by the core framework
|
service.setPubRootDirectories(<String>[pubRootTest]);
|
||||||
// not the current package.
|
|
||||||
final Element richText = find.descendant(
|
|
||||||
of: find.text('a'),
|
|
||||||
matching: find.byType(RichText),
|
|
||||||
).evaluate().first;
|
|
||||||
service.setSelection(richText, 'my-group');
|
|
||||||
service.setPubRootDirectories(<String>[pubRootTest]);
|
|
||||||
jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object?>;
|
|
||||||
expect(jsonObject, isNot(contains('createdByLocalProject')));
|
|
||||||
creationLocation = jsonObject['creationLocation']! as Map<String, Object?>;
|
|
||||||
expect(creationLocation, isNotNull);
|
|
||||||
// This RichText widget is created by the build method of the Text widget
|
|
||||||
// thus the creation location is in text.dart not basic.dart
|
|
||||||
final List<String> pathSegmentsFramework = Uri.parse(creationLocation['file']! as String).pathSegments;
|
|
||||||
expect(pathSegmentsFramework.join('/'), endsWith('/flutter/lib/src/widgets/text.dart'));
|
|
||||||
|
|
||||||
// Strip off /src/widgets/text.dart.
|
service.setSelection(elementA, 'my-group');
|
||||||
final String pubRootFramework = '/${pathSegmentsFramework.take(pathSegmentsFramework.length - 3).join('/')}';
|
expect(
|
||||||
service.setPubRootDirectories(<String>[pubRootFramework]);
|
json.decode(service.getSelectedWidget(null, 'my-group')),
|
||||||
expect(json.decode(service.getSelectedWidget(null, 'my-group')), contains('createdByLocalProject'));
|
contains('createdByLocalProject'),
|
||||||
service.setSelection(elementA, 'my-group');
|
);
|
||||||
expect(json.decode(service.getSelectedWidget(null, 'my-group')), isNot(contains('createdByLocalProject')));
|
},
|
||||||
|
);
|
||||||
|
|
||||||
service.setPubRootDirectories(<String>[pubRootFramework, pubRootTest]);
|
testWidgets(
|
||||||
service.setSelection(elementA, 'my-group');
|
'does not have createdByLocalProject when widget package directory is a suffix of a pubRootDirectory',
|
||||||
expect(json.decode(service.getSelectedWidget(null, 'my-group')), contains('createdByLocalProject'));
|
(WidgetTester tester) async {
|
||||||
service.setSelection(richText, 'my-group');
|
final Widget widget = Directionality(
|
||||||
expect(json.decode(service.getSelectedWidget(null, 'my-group')), contains('createdByLocalProject'));
|
textDirection: TextDirection.ltr,
|
||||||
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag.
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(widget);
|
||||||
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
|
||||||
|
service.setPubRootDirectories(<String>['/invalid/$pubRootTest']);
|
||||||
|
expect(
|
||||||
|
json.decode(service.getSelectedWidget(null, 'my-group')),
|
||||||
|
isNot(contains('createdByLocalProject')),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'has createdByLocalProject when the pubRootDirectory is prefixed with file://',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
final Widget widget = Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(widget);
|
||||||
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
|
||||||
|
service.setPubRootDirectories(<String>['file://$pubRootTest']);
|
||||||
|
expect(
|
||||||
|
json.decode(service.getSelectedWidget(null, 'my-group')),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'does not have createdByLocalProject when thePubRootDirecty has a different suffix',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
final Widget widget = Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(widget);
|
||||||
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
|
||||||
|
service.setPubRootDirectories(<String>['$pubRootTest/different']);
|
||||||
|
expect(
|
||||||
|
json.decode(service.getSelectedWidget(null, 'my-group')),
|
||||||
|
isNot(contains('createdByLocalProject')),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'has createdByLocalProject even if another pubRootDirectory does not match',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
final Widget widget = Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(widget);
|
||||||
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
|
||||||
|
service.setPubRootDirectories(<String>[
|
||||||
|
'/invalid/$pubRootTest',
|
||||||
|
pubRootTest,
|
||||||
|
]);
|
||||||
|
expect(
|
||||||
|
json.decode(service.getSelectedWidget(null, 'my-group')),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'widget is part of core framework and is the child of a widget in the package pubRootDirectories',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
final Widget widget = Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(widget);
|
||||||
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
|
final Element richText = find
|
||||||
|
.descendant(
|
||||||
|
of: find.text('a'),
|
||||||
|
matching: find.byType(RichText),
|
||||||
|
)
|
||||||
|
.evaluate()
|
||||||
|
.first;
|
||||||
|
service.setSelection(richText, 'my-group');
|
||||||
|
service.setPubRootDirectories(<String>[pubRootTest]);
|
||||||
|
|
||||||
|
final Map<String, Object?> jsonObject =
|
||||||
|
json.decode(service.getSelectedWidget(null, 'my-group'))
|
||||||
|
as Map<String, Object?>;
|
||||||
|
expect(jsonObject, isNot(contains('createdByLocalProject')));
|
||||||
|
final Map<String, Object?> creationLocation =
|
||||||
|
jsonObject['creationLocation']! as Map<String, Object?>;
|
||||||
|
expect(creationLocation, isNotNull);
|
||||||
|
// This RichText widget is created by the build method of the Text widget
|
||||||
|
// thus the creation location is in text.dart not basic.dart
|
||||||
|
final List<String> pathSegmentsFramework =
|
||||||
|
Uri.parse(creationLocation['file']! as String).pathSegments;
|
||||||
|
expect(
|
||||||
|
pathSegmentsFramework.join('/'),
|
||||||
|
endsWith('/flutter/lib/src/widgets/text.dart'),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Strip off /src/widgets/text.dart.
|
||||||
|
final String pubRootFramework =
|
||||||
|
'/${pathSegmentsFramework.take(pathSegmentsFramework.length - 3).join('/')}';
|
||||||
|
service.setPubRootDirectories(<String>[pubRootFramework]);
|
||||||
|
expect(
|
||||||
|
json.decode(service.getSelectedWidget(null, 'my-group')),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
expect(
|
||||||
|
json.decode(service.getSelectedWidget(null, 'my-group')),
|
||||||
|
isNot(contains('createdByLocalProject')),
|
||||||
|
);
|
||||||
|
|
||||||
|
service
|
||||||
|
.setPubRootDirectories(<String>[pubRootFramework, pubRootTest]);
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
expect(
|
||||||
|
json.decode(service.getSelectedWidget(null, 'my-group')),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
service.setSelection(richText, 'my-group');
|
||||||
|
expect(
|
||||||
|
json.decode(service.getSelectedWidget(null, 'my-group')),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
skip: !WidgetInspectorService.instance.isWidgetCreationTracked(), // [intended] Test requires --track-widget-creation flag.
|
||||||
|
);
|
||||||
|
|
||||||
test('ext.flutter.inspector.disposeGroup', () async {
|
test('ext.flutter.inspector.disposeGroup', () async {
|
||||||
final Object a = Object();
|
final Object a = Object();
|
||||||
@ -1760,136 +1929,450 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
|||||||
expect(columnA, equals(columnB));
|
expect(columnA, equals(columnB));
|
||||||
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag.
|
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag.
|
||||||
|
|
||||||
testWidgets('ext.flutter.inspector.setPubRootDirectories', (WidgetTester tester) async {
|
group(
|
||||||
await tester.pumpWidget(
|
'ext.flutter.inspector.setPubRootDirectories group',
|
||||||
Directionality(
|
() {
|
||||||
textDirection: TextDirection.ltr,
|
late final String pubRootTest;
|
||||||
child: Stack(
|
|
||||||
children: const <Widget>[
|
|
||||||
Text('a'),
|
|
||||||
Text('b', textDirection: TextDirection.ltr),
|
|
||||||
Text('c', textDirection: TextDirection.ltr),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
final Element elementA = find.text('a').evaluate().first;
|
|
||||||
|
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{});
|
setUpAll(() async {
|
||||||
service.setSelection(elementA, 'my-group');
|
pubRootTest = generateTestPubRootDirectory(service);
|
||||||
Map<String, Object?> jsonObject = (await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}))! as Map<String, Object?>;
|
});
|
||||||
Map<String, Object?> creationLocation = jsonObject['creationLocation']! as Map<String, Object?>;
|
|
||||||
expect(creationLocation, isNotNull);
|
|
||||||
final String fileA = creationLocation['file']! as String;
|
|
||||||
expect(fileA, endsWith('widget_inspector_test.dart'));
|
|
||||||
expect(jsonObject, isNot(contains('createdByLocalProject')));
|
|
||||||
final List<String> segments = Uri.parse(fileA).pathSegments;
|
|
||||||
// Strip a couple subdirectories away to generate a plausible pub root
|
|
||||||
// directory.
|
|
||||||
final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}';
|
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': pubRootTest});
|
|
||||||
|
|
||||||
service.setSelection(elementA, 'my-group');
|
testWidgets(
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
'has createdByLocalProject when the widget is in the pubRootDirectory',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': '/invalid/$pubRootTest'});
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), isNot(contains('createdByLocalProject')));
|
service.setSelection(elementA, 'my-group');
|
||||||
|
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': 'file://$pubRootTest'});
|
await service.testExtension(
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
'setPubRootDirectories',
|
||||||
|
<String, String>{'arg0': pubRootTest},
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
await service.testExtension(
|
||||||
|
'getSelectedWidget',
|
||||||
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
|
),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': '$pubRootTest/different'});
|
testWidgets(
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), isNot(contains('createdByLocalProject')));
|
'does not have createdByLocalProject if the prefix of the pubRootDirectory is different',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
'arg0': '/unrelated/$pubRootTest',
|
service.setSelection(elementA, 'my-group');
|
||||||
'arg1': 'file://$pubRootTest',
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
await service.testExtension(
|
||||||
|
'setPubRootDirectories',
|
||||||
|
<String, String>{'arg0': '/invalid/$pubRootTest'},
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
await service.testExtension(
|
||||||
|
'getSelectedWidget',
|
||||||
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
|
),
|
||||||
|
isNot(contains('createdByLocalProject')),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// The RichText child of the Text widget is created by the core framework
|
testWidgets(
|
||||||
// not the current package.
|
'has createdByLocalProject if the pubRootDirectory is prefixed with file://',
|
||||||
final Element richText = find.descendant(
|
(WidgetTester tester) async {
|
||||||
of: find.text('a'),
|
await tester.pumpWidget(
|
||||||
matching: find.byType(RichText),
|
Directionality(
|
||||||
).evaluate().first;
|
textDirection: TextDirection.ltr,
|
||||||
service.setSelection(richText, 'my-group');
|
child: Stack(
|
||||||
service.setPubRootDirectories(<String>[pubRootTest]);
|
children: const <Widget>[
|
||||||
jsonObject = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object?>;
|
Text('a'),
|
||||||
expect(jsonObject, isNot(contains('createdByLocalProject')));
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
creationLocation = jsonObject['creationLocation']! as Map<String, Object?>;
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
expect(creationLocation, isNotNull);
|
],
|
||||||
// This RichText widget is created by the build method of the Text widget
|
),
|
||||||
// thus the creation location is in text.dart not basic.dart
|
),
|
||||||
final List<String> pathSegmentsFramework = Uri.parse(creationLocation['file']! as String).pathSegments;
|
);
|
||||||
expect(pathSegmentsFramework.join('/'), endsWith('/flutter/lib/src/widgets/text.dart'));
|
|
||||||
|
|
||||||
// Strip off /src/widgets/text.dart.
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
final String pubRootFramework = '/${pathSegmentsFramework.take(pathSegmentsFramework.length - 3).join('/')}';
|
service.setSelection(elementA, 'my-group');
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': pubRootFramework});
|
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
|
||||||
service.setSelection(elementA, 'my-group');
|
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), isNot(contains('createdByLocalProject')));
|
|
||||||
|
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': pubRootFramework, 'arg1': pubRootTest});
|
await service.testExtension(
|
||||||
service.setSelection(elementA, 'my-group');
|
'setPubRootDirectories',
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
<String, String>{'arg0': 'file://$pubRootTest'},
|
||||||
service.setSelection(richText, 'my-group');
|
);
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
expect(
|
||||||
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag.
|
await service.testExtension(
|
||||||
|
'getSelectedWidget',
|
||||||
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
|
),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
testWidgets('ext.flutter.inspector.setPubRootDirectories extra args regression test', (WidgetTester tester) async {
|
testWidgets(
|
||||||
// Ensure that passing the isolate id as an argument won't break
|
'does not have createdByLocalProject if the pubRootDirectory has a different suffix',
|
||||||
// setPubRootDirectories command.
|
(WidgetTester tester) async {
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
Directionality(
|
Directionality(
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: const <Widget>[
|
children: const <Widget>[
|
||||||
Text('a'),
|
Text('a'),
|
||||||
Text('b', textDirection: TextDirection.ltr),
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
Text('c', textDirection: TextDirection.ltr),
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final Element elementA = find.text('a').evaluate().first;
|
|
||||||
|
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{'isolateId': '34'});
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
service.setSelection(elementA, 'my-group');
|
service.setSelection(elementA, 'my-group');
|
||||||
final Map<String, Object?> jsonObject = (await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}))! as Map<String, Object?>;
|
|
||||||
final Map<String, Object?> creationLocation = jsonObject['creationLocation']! as Map<String, Object?>;
|
|
||||||
expect(creationLocation, isNotNull);
|
|
||||||
final String fileA = creationLocation['file']! as String;
|
|
||||||
expect(fileA, endsWith('widget_inspector_test.dart'));
|
|
||||||
expect(jsonObject, isNot(contains('createdByLocalProject')));
|
|
||||||
final List<String> segments = Uri.parse(fileA).pathSegments;
|
|
||||||
// Strip a couple subdirectories away to generate a plausible pub root
|
|
||||||
// directory.
|
|
||||||
final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}';
|
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': pubRootTest, 'isolateId': '34'});
|
|
||||||
|
|
||||||
service.setSelection(elementA, 'my-group');
|
await service.testExtension(
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
'setPubRootDirectories',
|
||||||
|
<String, String>{'arg0': '$pubRootTest/different'},
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
await service.testExtension(
|
||||||
|
'getSelectedWidget',
|
||||||
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
|
),
|
||||||
|
isNot(contains('createdByLocalProject')),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': '/invalid/$pubRootTest', 'isolateId': '34'});
|
testWidgets(
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), isNot(contains('createdByLocalProject')));
|
'has createdByLocalProject if at least one of the pubRootDirectories matches',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': 'file://$pubRootTest', 'isolateId': '34'});
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
service.setSelection(elementA, 'my-group');
|
||||||
|
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': '$pubRootTest/different', 'isolateId': '34'});
|
await service.testExtension('setPubRootDirectories', <String, String>{
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), isNot(contains('createdByLocalProject')));
|
'arg0': '/unrelated/$pubRootTest',
|
||||||
|
'arg1': 'file://$pubRootTest',
|
||||||
|
});
|
||||||
|
|
||||||
await service.testExtension('setPubRootDirectories', <String, String>{
|
expect(
|
||||||
'arg0': '/unrelated/$pubRootTest',
|
await service.testExtension(
|
||||||
'isolateId': '34',
|
'getSelectedWidget',
|
||||||
'arg1': 'file://$pubRootTest',
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
});
|
),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
testWidgets(
|
||||||
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag.
|
'widget is part of core framework and is the child of a widget in the package pubRootDirectories',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
|
|
||||||
|
// The RichText child of the Text widget is created by the core framework
|
||||||
|
// not the current package.
|
||||||
|
final Element richText = find
|
||||||
|
.descendant(
|
||||||
|
of: find.text('a'),
|
||||||
|
matching: find.byType(RichText),
|
||||||
|
)
|
||||||
|
.evaluate()
|
||||||
|
.first;
|
||||||
|
service.setSelection(richText, 'my-group');
|
||||||
|
service.setPubRootDirectories(<String>[pubRootTest]);
|
||||||
|
final Map<String, Object?> jsonObject =
|
||||||
|
json.decode(service.getSelectedWidget(null, 'my-group'))
|
||||||
|
as Map<String, Object?>;
|
||||||
|
expect(jsonObject, isNot(contains('createdByLocalProject')));
|
||||||
|
final Map<String, Object?> creationLocation =
|
||||||
|
jsonObject['creationLocation']! as Map<String, Object?>;
|
||||||
|
expect(creationLocation, isNotNull);
|
||||||
|
// This RichText widget is created by the build method of the Text widget
|
||||||
|
// thus the creation location is in text.dart not basic.dart
|
||||||
|
final List<String> pathSegmentsFramework =
|
||||||
|
Uri.parse(creationLocation['file']! as String).pathSegments;
|
||||||
|
expect(
|
||||||
|
pathSegmentsFramework.join('/'),
|
||||||
|
endsWith('/flutter/lib/src/widgets/text.dart'),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Strip off /src/widgets/text.dart.
|
||||||
|
final String pubRootFramework =
|
||||||
|
'/${pathSegmentsFramework.take(pathSegmentsFramework.length - 3).join('/')}';
|
||||||
|
await service.testExtension(
|
||||||
|
'setPubRootDirectories',
|
||||||
|
<String, String>{'arg0': pubRootFramework},
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
await service.testExtension(
|
||||||
|
'getSelectedWidget',
|
||||||
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
|
),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
expect(
|
||||||
|
await service.testExtension(
|
||||||
|
'getSelectedWidget',
|
||||||
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
|
),
|
||||||
|
isNot(contains('createdByLocalProject')),
|
||||||
|
);
|
||||||
|
|
||||||
|
await service.testExtension(
|
||||||
|
'setPubRootDirectories',
|
||||||
|
<String, String>{'arg0': pubRootFramework, 'arg1': pubRootTest},
|
||||||
|
);
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
expect(
|
||||||
|
await service.testExtension(
|
||||||
|
'getSelectedWidget',
|
||||||
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
|
),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
service.setSelection(richText, 'my-group');
|
||||||
|
expect(
|
||||||
|
await service.testExtension(
|
||||||
|
'getSelectedWidget',
|
||||||
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
|
),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
skip: !WidgetInspectorService.instance.isWidgetCreationTracked(), // [intended] Test requires --track-widget-creation flag.
|
||||||
|
);
|
||||||
|
|
||||||
|
group(
|
||||||
|
'ext.flutter.inspector.setPubRootDirectories extra args regression test',
|
||||||
|
() {
|
||||||
|
// Ensure that passing the isolate id as an argument won't break
|
||||||
|
// setPubRootDirectories command.
|
||||||
|
|
||||||
|
late final String pubRootTest;
|
||||||
|
|
||||||
|
setUpAll(() {
|
||||||
|
pubRootTest = generateTestPubRootDirectory(service);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'has createdByLocalProject when the widget is in the pubRootDirectory',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
|
||||||
|
await service.testExtension(
|
||||||
|
'setPubRootDirectories',
|
||||||
|
<String, String>{'arg0': pubRootTest, 'isolateId': '34'},
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
await service.testExtension(
|
||||||
|
'getSelectedWidget',
|
||||||
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
|
),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'does not have createdByLocalProject if the prefix of the pubRootDirectory is different',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
|
||||||
|
await service.testExtension('setPubRootDirectories', <String, String>{
|
||||||
|
'arg0': '/invalid/$pubRootTest',
|
||||||
|
'isolateId': '34'
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
await service.testExtension(
|
||||||
|
'getSelectedWidget',
|
||||||
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
|
),
|
||||||
|
isNot(contains('createdByLocalProject')),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'has createdByLocalProject if the pubRootDirectory is prefixed with file://',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
|
||||||
|
await service.testExtension(
|
||||||
|
'setPubRootDirectories',
|
||||||
|
<String, String>{'arg0': 'file://$pubRootTest', 'isolateId': '34'},
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
await service.testExtension(
|
||||||
|
'getSelectedWidget',
|
||||||
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
|
),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'does not have createdByLocalProject if the pubRootDirectory has a different suffix',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
|
||||||
|
await service.testExtension('setPubRootDirectories', <String, String>{
|
||||||
|
'arg0': '$pubRootTest/different',
|
||||||
|
'isolateId': '34'
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
await service.testExtension(
|
||||||
|
'getSelectedWidget',
|
||||||
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
|
),
|
||||||
|
isNot(contains('createdByLocalProject')),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'has createdByLocalProject if at least one of the pubRootDirectories matchesE',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Stack(
|
||||||
|
children: const <Widget>[
|
||||||
|
Text('a'),
|
||||||
|
Text('b', textDirection: TextDirection.ltr),
|
||||||
|
Text('c', textDirection: TextDirection.ltr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final Element elementA = find.text('a').evaluate().first;
|
||||||
|
service.setSelection(elementA, 'my-group');
|
||||||
|
|
||||||
|
await service.testExtension('setPubRootDirectories', <String, String>{
|
||||||
|
'arg0': '/unrelated/$pubRootTest',
|
||||||
|
'isolateId': '34',
|
||||||
|
'arg1': 'file://$pubRootTest',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
await service.testExtension(
|
||||||
|
'getSelectedWidget',
|
||||||
|
<String, String>{'objectGroup': 'my-group'},
|
||||||
|
),
|
||||||
|
contains('createdByLocalProject'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
skip: !WidgetInspectorService.instance.isWidgetCreationTracked(), // [intended] Test requires --track-widget-creation flag.
|
||||||
|
);
|
||||||
|
|
||||||
Map<Object, Object?> removeLastEvent(List<Map<Object, Object?>> events) {
|
Map<Object, Object?> removeLastEvent(List<Map<Object, Object?>> events) {
|
||||||
final Map<Object, Object?> event = events.removeLast();
|
final Map<Object, Object?> event = events.removeLast();
|
||||||
@ -3070,7 +3553,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setupDefaultPubRootDirectory(TestWidgetInspectorService service) {
|
static String generateTestPubRootDirectory(TestWidgetInspectorService service) {
|
||||||
final Map<String, Object?> jsonObject = const SizedBox().toDiagnosticsNode().toJsonMap(InspectorSerializationDelegate(service: service));
|
final Map<String, Object?> jsonObject = const SizedBox().toDiagnosticsNode().toJsonMap(InspectorSerializationDelegate(service: service));
|
||||||
final Map<String, Object?> creationLocation = jsonObject['creationLocation']! as Map<String, Object?>;
|
final Map<String, Object?> creationLocation = jsonObject['creationLocation']! as Map<String, Object?>;
|
||||||
expect(creationLocation, isNotNull);
|
expect(creationLocation, isNotNull);
|
||||||
@ -3079,11 +3562,17 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
|||||||
final List<String> segments = Uri
|
final List<String> segments = Uri
|
||||||
.parse(file)
|
.parse(file)
|
||||||
.pathSegments;
|
.pathSegments;
|
||||||
final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}';
|
|
||||||
|
|
||||||
// Strip a couple subdirectories away to generate a plausible pub root
|
// Strip a couple subdirectories away to generate a plausible pub root
|
||||||
// directory.
|
// directory.
|
||||||
service.setPubRootDirectories(<String>[pubRootTest]);
|
final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}';
|
||||||
|
|
||||||
|
return pubRootTest;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setupDefaultPubRootDirectory(TestWidgetInspectorService service) {
|
||||||
|
service
|
||||||
|
.setPubRootDirectories(<String>[generateTestPubRootDirectory(service)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user