Skip to content

Commit cee78d4

Browse files
Set up MUI stubs in test file
1 parent 65d1d4d commit cee78d4

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

test/mui_suggestors/system_props_to_sx_migrator_test.dart

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ void main() {
3131

3232
// Set up a file with stubbed MUI components with system props, for the
3333
// test inputs to import and the suggestor to detect.
34-
final muiComponentsFile = await resolvedContext.resolvedFileContextForTest(
35-
getStubMuiComponentSource(filenameWithoutExtension: 'mui_components'),
34+
final muiFile = await resolvedContext.resolvedFileContextForTest(
35+
getStubMuiLibrarySource(filenameWithoutExtension: 'mui_components'),
3636
filename: 'mui_components.dart',
3737
);
38-
muiUri = Uri.file(muiComponentsFile.path).toString();
38+
muiUri = Uri.file(muiFile.path).toString();
3939
});
4040

4141
String withHeader(String source) => '''
@@ -1153,13 +1153,26 @@ void main() {
11531153
});
11541154
}
11551155

1156-
String getStubMuiComponentSource({required String filenameWithoutExtension}) {
1157-
const componentsWithSystemProps = [
1156+
String getStubMuiLibrarySource({required String filenameWithoutExtension}) {
1157+
final systemPropComponentsSource = [
11581158
'Box',
11591159
'Stack',
11601160
'Grid',
11611161
'Typography',
1162-
];
1162+
].map((componentName) {
1163+
return '''
1164+
UiFactory<${componentName}Props> $componentName = uiFunction((_) {}, _\$${componentName}Config);
1165+
1166+
@Props(keyNamespace: '')
1167+
mixin ${componentName}Props on UiProps {
1168+
@convertJsMapProp
1169+
Map? sx;
1170+
1171+
${systemPropNames.map((propName) => " @Deprecated('Use sx.') dynamic ${propName};").join('\n')}
1172+
}
1173+
''';
1174+
}).join('\n\n');
1175+
11631176
return '''
11641177
//@dart=2.19
11651178
import 'package:over_react/over_react.dart';
@@ -1168,7 +1181,7 @@ String getStubMuiComponentSource({required String filenameWithoutExtension}) {
11681181
// ignore: uri_has_not_been_generated
11691182
part '$filenameWithoutExtension.over_react.g.dart';
11701183
1171-
${componentsWithSystemProps.map(systemPropsComponentSource).join('\n\n')}
1184+
$systemPropComponentsSource
11721185
11731186
UiFactory<TextFieldProps> TextField = uiFunction((_) {}, _\$TextFieldConfig);
11741187
@@ -1182,20 +1195,3 @@ String getStubMuiComponentSource({required String filenameWithoutExtension}) {
11821195
}
11831196
''';
11841197
}
1185-
1186-
String systemPropsComponentSource(String componentName) {
1187-
final systemProps = systemPropNames
1188-
.map((propName) => " @Deprecated('Use sx.') dynamic ${propName};")
1189-
.join('\n');
1190-
return '''
1191-
UiFactory<${componentName}Props> $componentName = uiFunction((_) {}, _\$${componentName}Config);
1192-
1193-
@Props(keyNamespace: '')
1194-
mixin ${componentName}Props on UiProps {
1195-
@convertJsMapProp
1196-
Map? sx;
1197-
1198-
${systemProps}
1199-
}
1200-
''';
1201-
}

0 commit comments

Comments
 (0)