-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #407 from Workiva/lazy-tests-and-wrapper
Add lazy test coverage, add wrapper in react-dart
- Loading branch information
Showing
4 changed files
with
102 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,79 @@ | ||
@TestOn('browser') | ||
@JS() | ||
library react.react_lazy_test; | ||
|
||
import 'dart:js_util'; | ||
|
||
import 'package:js/js.dart'; | ||
import 'package:react/hooks.dart'; | ||
import 'package:react/react.dart' as react; | ||
import 'package:react/react_client/component_factory.dart'; | ||
import 'package:react/react_client/react_interop.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'factory/common_factory_tests.dart'; | ||
|
||
main() { | ||
group('lazy', () { | ||
group('- common factory behavior -', () { | ||
final LazyTest = react.lazy(() async => react.registerFunctionComponent((props) { | ||
group('Dart component', () { | ||
final LazyTest = react.lazy(() async => react.forwardRef2((props, ref) { | ||
useImperativeHandle(ref, () => TestImperativeHandle()); | ||
props['onDartRender']?.call(props); | ||
return react.div({...props}); | ||
})); | ||
|
||
commonFactoryTests( | ||
LazyTest, | ||
// ignore: invalid_use_of_protected_member | ||
dartComponentVersion: ReactDartComponentVersion.component2, | ||
renderWrapper: (child) => react.Suspense({'fallback': 'Loading...'}, child), | ||
); | ||
group('- common factory behavior -', () { | ||
commonFactoryTests( | ||
LazyTest, | ||
// ignore: invalid_use_of_protected_member | ||
dartComponentVersion: ReactDartComponentVersion.component2, | ||
renderWrapper: (child) => react.Suspense({'fallback': 'Loading...'}, child), | ||
); | ||
}); | ||
|
||
group('- dom event handler wrapping -', () { | ||
domEventHandlerWrappingTests(LazyTest); | ||
}); | ||
|
||
group('- refs -', () { | ||
refTests<TestImperativeHandle>(LazyTest, verifyRefValue: (ref) { | ||
expect(ref, isA<TestImperativeHandle>()); | ||
}); | ||
}); | ||
}); | ||
|
||
group('JS component', () { | ||
final LazyJsTest = react.lazy(() async => ReactJsComponentFactoryProxy(_JsFoo)); | ||
|
||
group('- common factory behavior -', () { | ||
commonFactoryTests( | ||
LazyJsTest, | ||
// ignore: invalid_use_of_protected_member | ||
dartComponentVersion: ReactDartComponentVersion.component2, | ||
// This isn't a Dart component, but it's detected as one by tests due to the factory's dartComponentVersion | ||
isNonDartComponentWithDartWrapper: true, | ||
renderWrapper: (child) => react.Suspense({'fallback': 'Loading...'}, child), | ||
); | ||
}); | ||
|
||
group('- dom event handler wrapping -', () { | ||
domEventHandlerWrappingTests( | ||
LazyJsTest, | ||
// This isn't a Dart component, but it's detected as one by tests due to the factory's dartComponentVersion | ||
isNonDartComponentWithDartWrapper: true, | ||
); | ||
}); | ||
|
||
group('- refs -', () { | ||
refTests<ReactComponent>(LazyJsTest, verifyRefValue: (ref) { | ||
expect(getProperty(ref as Object, 'constructor'), same(_JsFoo)); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
class TestImperativeHandle {} | ||
|
||
@JS() | ||
external ReactClass get _JsFoo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters