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);
|
||||
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag.
|
||||
|
||||
testWidgets('WidgetInspectorService setPubRootDirectories', (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;
|
||||
group(
|
||||
'WidgetInspectorService',
|
||||
() {
|
||||
group('setPubRootDirectories', () {
|
||||
late final String pubRootTest;
|
||||
|
||||
service.disposeAllGroups();
|
||||
service.setPubRootDirectories(<String>[]);
|
||||
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]);
|
||||
setUpAll(() {
|
||||
pubRootTest = generateTestPubRootDirectory(service);
|
||||
});
|
||||
|
||||
service.setSelection(elementA, 'my-group');
|
||||
expect(json.decode(service.getSelectedWidget(null, 'my-group')), contains('createdByLocalProject'));
|
||||
setUp(() {
|
||||
service.disposeAllGroups();
|
||||
service.setPubRootDirectories(<String>[]);
|
||||
});
|
||||
|
||||
service.setPubRootDirectories(<String>['/invalid/$pubRootTest']);
|
||||
expect(json.decode(service.getSelectedWidget(null, 'my-group')), isNot(contains('createdByLocalProject')));
|
||||
testWidgets(
|
||||
'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']);
|
||||
expect(json.decode(service.getSelectedWidget(null, 'my-group')), contains('createdByLocalProject'));
|
||||
final Map<String, Object?> jsonObject =
|
||||
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(json.decode(service.getSelectedWidget(null, 'my-group')), isNot(contains('createdByLocalProject')));
|
||||
expect(creationLocation, isNotNull);
|
||||
final String fileA = creationLocation['file']! as String;
|
||||
expect(fileA, endsWith('widget_inspector_test.dart'));
|
||||
expect(jsonObject, isNot(contains('createdByLocalProject')));
|
||||
},
|
||||
);
|
||||
|
||||
service.setPubRootDirectories(<String>[
|
||||
'/invalid/$pubRootTest',
|
||||
pubRootTest,
|
||||
]);
|
||||
expect(json.decode(service.getSelectedWidget(null, 'my-group')), contains('createdByLocalProject'));
|
||||
testWidgets(
|
||||
'has createdByLocalProject when the element is part of the pubRootDirectory',
|
||||
(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;
|
||||
|
||||
// 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]);
|
||||
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'));
|
||||
service.setPubRootDirectories(<String>[pubRootTest]);
|
||||
|
||||
// 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.setSelection(elementA, 'my-group');
|
||||
expect(
|
||||
json.decode(service.getSelectedWidget(null, 'my-group')),
|
||||
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.
|
||||
testWidgets(
|
||||
'does not have createdByLocalProject when widget package directory is a suffix of a pubRootDirectory',
|
||||
(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']);
|
||||
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 {
|
||||
final Object a = Object();
|
||||
@ -1760,136 +1929,450 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
||||
expect(columnA, equals(columnB));
|
||||
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag.
|
||||
|
||||
testWidgets('ext.flutter.inspector.setPubRootDirectories', (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;
|
||||
group(
|
||||
'ext.flutter.inspector.setPubRootDirectories group',
|
||||
() {
|
||||
late final String pubRootTest;
|
||||
|
||||
await service.testExtension('setPubRootDirectories', <String, String>{});
|
||||
service.setSelection(elementA, 'my-group');
|
||||
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});
|
||||
setUpAll(() async {
|
||||
pubRootTest = generateTestPubRootDirectory(service);
|
||||
});
|
||||
|
||||
service.setSelection(elementA, 'my-group');
|
||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
||||
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),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': '/invalid/$pubRootTest'});
|
||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), isNot(contains('createdByLocalProject')));
|
||||
final Element elementA = find.text('a').evaluate().first;
|
||||
service.setSelection(elementA, 'my-group');
|
||||
|
||||
await service.testExtension('setPubRootDirectories', <String, String>{'arg0': 'file://$pubRootTest'});
|
||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
||||
await service.testExtension(
|
||||
'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'});
|
||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), isNot(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),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await service.testExtension('setPubRootDirectories', <String, String>{
|
||||
'arg0': '/unrelated/$pubRootTest',
|
||||
'arg1': 'file://$pubRootTest',
|
||||
});
|
||||
final Element elementA = find.text('a').evaluate().first;
|
||||
service.setSelection(elementA, 'my-group');
|
||||
|
||||
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
|
||||
// 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'));
|
||||
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),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// 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')));
|
||||
final Element elementA = find.text('a').evaluate().first;
|
||||
service.setSelection(elementA, 'my-group');
|
||||
|
||||
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.
|
||||
await service.testExtension(
|
||||
'setPubRootDirectories',
|
||||
<String, String>{'arg0': 'file://$pubRootTest'},
|
||||
);
|
||||
expect(
|
||||
await service.testExtension(
|
||||
'getSelectedWidget',
|
||||
<String, String>{'objectGroup': 'my-group'},
|
||||
),
|
||||
contains('createdByLocalProject'),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('ext.flutter.inspector.setPubRootDirectories extra args regression test', (WidgetTester tester) async {
|
||||
// Ensure that passing the isolate id as an argument won't break
|
||||
// setPubRootDirectories command.
|
||||
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;
|
||||
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),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await service.testExtension('setPubRootDirectories', <String, String>{'isolateId': '34'});
|
||||
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'});
|
||||
final Element elementA = find.text('a').evaluate().first;
|
||||
service.setSelection(elementA, 'my-group');
|
||||
|
||||
service.setSelection(elementA, 'my-group');
|
||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
||||
await service.testExtension(
|
||||
'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'});
|
||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), isNot(contains('createdByLocalProject')));
|
||||
testWidgets(
|
||||
'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'});
|
||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
||||
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')));
|
||||
await service.testExtension('setPubRootDirectories', <String, String>{
|
||||
'arg0': '/unrelated/$pubRootTest',
|
||||
'arg1': 'file://$pubRootTest',
|
||||
});
|
||||
|
||||
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'),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
expect(await service.testExtension('getSelectedWidget', <String, String>{'objectGroup': 'my-group'}), contains('createdByLocalProject'));
|
||||
}, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag.
|
||||
testWidgets(
|
||||
'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) {
|
||||
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?> creationLocation = jsonObject['creationLocation']! as Map<String, Object?>;
|
||||
expect(creationLocation, isNotNull);
|
||||
@ -3079,11 +3562,17 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
||||
final List<String> segments = Uri
|
||||
.parse(file)
|
||||
.pathSegments;
|
||||
final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}';
|
||||
|
||||
// Strip a couple subdirectories away to generate a plausible pub root
|
||||
// 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