Skip to content

Commit

Permalink
Address reviewer feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sydneyjodon-wk committed Feb 11, 2020
1 parent 23dc002 commit 8775714
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:convert';

import 'package:over_react_codemod/src/boilerplate_suggestors/advanced_props_and_state_class_migrator.dart';
import 'package:over_react_codemod/src/boilerplate_suggestors/boilerplate_utilities.dart';
import 'package:test/test.dart';

import '../util.dart';
import 'boilerplate_utilities_test.dart';

void main() {
group('AdvancedPropsAndStateClassMigrator', () {
final converter = ClassToMixinConverter();
final testSuggestor =
getSuggestorTester(AdvancedPropsAndStateClassMigrator(converter));

setUpAll(() {
semverHelper = SemverHelper(jsonDecode(reportJson));
});

tearDown(() {
converter.setConvertedClassNames({});
});
Expand Down Expand Up @@ -65,6 +72,43 @@ void main() {

expect(converter.convertedClassNames, isEmpty);
});

test('advanced classes are public API', () {
testSuggestor(
expectedPatchCount: 0,
input: r'''
@Factory()
UiFactory<BarProps> Bar =
// ignore: undefined_identifier
$Bar;
@Props()
class BarProps extends ADifferentPropsClass {
String foo;
int bar;
}
@State()
class BarState extends ADifferentStateClass {
String foo;
int bar;
}
@Component2()
class BarComponent extends UiStatefulComponent2<BarProps, BarState> {
@override
render() {
return Dom.ul()(
Dom.li()('Foo: ', props.foo),
Dom.li()('Bar: ', props.bar),
);
}
}
''',
);

expect(converter.convertedClassNames, isEmpty);
});
});

group('operates when the classes are advanced', () {
Expand Down
37 changes: 22 additions & 15 deletions test/boilerplate_suggestors/boilerplate_utilities_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ const reportJson = r'''{
"meta": ["@Props()"]
}
},
"lib/web_skin_dart.dart/BarState": {
"type": "class",
"grammar": {
"name": "BarState",
"meta": ["@State()"]
}
},
"lib/web_skin_dart.dart/BarPropsMixin": {
"type": "class",
"grammar": {
Expand All @@ -46,7 +53,7 @@ const reportJson = r'''{
"type": "class",
"grammar": {
"name": "BarStateMixin",
"meta": ["@Props()"]
"meta": ["@State()"]
}
},
"lib/another_file.dart/ButtonProps": {
Expand Down Expand Up @@ -311,9 +318,11 @@ void main() {
});

group('isPublic() and getPublicExportLocations()', () {
test('if props class is not in export list', () {
setUpAll(() {
semverHelper = SemverHelper(jsonDecode(reportJson));
});

test('if props class is not in export list', () {
final input = '''
@Props()
class _\$FooProps extends UiProps{
Expand All @@ -330,28 +339,26 @@ void main() {
expect(isPublic(classNode), false);
});
});
});

test('if props class is in export list', () {
semverHelper = SemverHelper(jsonDecode(reportJson));

final input = '''
test('if props class is in export list', () {
final input = '''
@Props()
class ButtonProps extends UiProps{
String foo;
int bar;
}
''';

CompilationUnit unit = parseString(content: input).unit;
expect(unit.declarations.whereType<ClassDeclaration>().length, 1);
CompilationUnit unit = parseString(content: input).unit;
expect(unit.declarations.whereType<ClassDeclaration>().length, 1);

unit.declarations.whereType<ClassDeclaration>().forEach((classNode) {
expect(semverHelper.getPublicExportLocations(classNode), [
'lib/web_skin_dart.dart/ButtonProps',
'lib/another_file.dart/ButtonProps'
]);
expect(isPublic(classNode), true);
unit.declarations.whereType<ClassDeclaration>().forEach((classNode) {
expect(semverHelper.getPublicExportLocations(classNode), [
'lib/web_skin_dart.dart/ButtonProps',
'lib/another_file.dart/ButtonProps'
]);
expect(isPublic(classNode), true);
});
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/boilerplate_suggestors/props_mixin_migrator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ main() {
final converter = ClassToMixinConverter();
final testSuggestor = getSuggestorTester(PropsMixinMigrator(converter));

setUpAll(() async {
setUpAll(() {
semverHelper = SemverHelper(jsonDecode(reportJson));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ main() {
final testSuggestor =
getSuggestorTester(SimplePropsAndStateClassMigrator(converter));

setUpAll(() async {
setUpAll(() {
semverHelper = SemverHelper(jsonDecode(reportJson));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ main() {
StubbedPropsAndStateClassRemover(),
);

setUpAll(() async {
setUpAll(() {
semverHelper = SemverHelper(jsonDecode(reportJson));
});

Expand Down

0 comments on commit 8775714

Please sign in to comment.