diff --git a/app/over_react_redux/todo_client/pubspec.yaml b/app/over_react_redux/todo_client/pubspec.yaml index c82797e8f..b75342f91 100644 --- a/app/over_react_redux/todo_client/pubspec.yaml +++ b/app/over_react_redux/todo_client/pubspec.yaml @@ -32,3 +32,8 @@ dev_dependencies: dependency_overrides: over_react: path: '../../../' + react: + git: + url: https://github.com/cleandart/react-dart.git + ref: 6.0.0-wip + diff --git a/lib/over_react.dart b/lib/over_react.dart index 9061f02f5..364dcd5b1 100644 --- a/lib/over_react.dart +++ b/lib/over_react.dart @@ -23,7 +23,6 @@ export 'package:react/react.dart' SyntheticKeyboardEvent, SyntheticFocusEvent, SyntheticFormEvent, - SyntheticDataTransfer, SyntheticMouseEvent, SyntheticTouchEvent, SyntheticTransitionEvent, @@ -43,13 +42,22 @@ export 'package:react/react.dart' createSyntheticAnimationEvent, createSyntheticUIEvent, createSyntheticWheelEvent, - SyntheticEventTypeHelpers; + fakeSyntheticFormEvent, + wrapNativeKeyboardEvent, + wrapNativeMouseEvent, + SyntheticEventTypeHelpers, + DataTransferHelper; export 'package:react/react_client/js_backed_map.dart' show JsBackedMap; export 'package:react/react_client.dart' // ignore: deprecated_member_use - show setClientConfiguration, chainRefs, ReactElement, ReactComponentFactoryProxy; + show + // ignore: deprecated_member_use + setClientConfiguration, + chainRefs, + ReactElement, + ReactComponentFactoryProxy; export 'package:react/react_client/react_interop.dart' show ReactErrorInfo, Ref; export 'package:react/hooks.dart' show StateHook, ReducerHook; @@ -58,11 +66,9 @@ export 'src/component/_deprecated/abstract_transition_props.dart'; export 'src/component/aria_mixin.dart'; export 'src/component/callback_typedefs.dart'; export 'src/component/_deprecated/error_boundary.dart'; -export 'src/component/_deprecated/error_boundary_mixins.dart' - hide LegacyErrorBoundaryApi; +export 'src/component/_deprecated/error_boundary_mixins.dart' hide LegacyErrorBoundaryApi; export 'src/component/dom_components.dart'; -export 'src/component/error_boundary_api.dart' - show defaultErrorBoundaryLoggerName; +export 'src/component/error_boundary_api.dart' show defaultErrorBoundaryLoggerName; export 'src/component/ref_util.dart'; export 'src/component/fragment_component.dart'; export 'src/component/hooks.dart'; @@ -73,8 +79,7 @@ export 'src/component/prop_typedefs.dart'; export 'src/component/pure_component_mixin.dart'; export 'src/component/_deprecated/resize_sensor.dart'; export 'src/component_declaration/annotations.dart'; -export 'src/component_declaration/builder_helpers.dart' - hide GeneratedErrorMessages; +export 'src/component_declaration/builder_helpers.dart' hide GeneratedErrorMessages; export 'src/component_declaration/component_base_2.dart' show registerComponent2, @@ -91,7 +96,6 @@ export 'src/util/constants_base.dart'; export 'src/util/css_value_util.dart'; export 'src/util/dom_util.dart'; export 'src/util/equality.dart' show propsOrStateMapsEqual; -export 'src/util/event_helpers.dart'; export 'src/util/guid_util.dart'; export 'src/util/hoc.dart'; export 'src/util/handler_chain_util.dart'; diff --git a/lib/src/util/event_helpers.dart b/lib/src/util/event_helpers.dart deleted file mode 100644 index f231a06f6..000000000 --- a/lib/src/util/event_helpers.dart +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2016 Workiva Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -library over_react.event_helpers; - -import 'dart:html'; - -import 'package:over_react/over_react.dart'; - -/// Helper util that wraps a native [KeyboardEvent] in a [SyntheticKeyboardEvent]. -/// -/// Used where a native [KeyboardEvent] is given and a [SyntheticKeyboardEvent] is needed. -SyntheticKeyboardEvent wrapNativeKeyboardEvent(KeyboardEvent nativeKeyboardEvent) { - return createSyntheticKeyboardEvent( - bubbles: nativeKeyboardEvent.bubbles, - cancelable: nativeKeyboardEvent.cancelable, - currentTarget: nativeKeyboardEvent.currentTarget, - defaultPrevented: nativeKeyboardEvent.defaultPrevented, - preventDefault: nativeKeyboardEvent.preventDefault, - stopPropagation: nativeKeyboardEvent.stopPropagation, - eventPhase: nativeKeyboardEvent.eventPhase, - nativeEvent: nativeKeyboardEvent, - target: nativeKeyboardEvent.target, - timeStamp: nativeKeyboardEvent.timeStamp, - type: nativeKeyboardEvent.type, - altKey: nativeKeyboardEvent.altKey, - char: nativeKeyboardEvent.charCode == null ? null : String.fromCharCode(nativeKeyboardEvent.charCode), - charCode: nativeKeyboardEvent.charCode, - ctrlKey: nativeKeyboardEvent.ctrlKey, - location: nativeKeyboardEvent.location, - keyCode: nativeKeyboardEvent.keyCode, - metaKey: nativeKeyboardEvent.metaKey, - repeat: nativeKeyboardEvent.repeat, - shiftKey: nativeKeyboardEvent.shiftKey, - ); -} - -/// Helper util that wraps a native [MouseEvent] in a [SyntheticMouseEvent]. -/// -/// Used where a native [MouseEvent] is given and a [SyntheticMouseEvent] is needed. -SyntheticMouseEvent wrapNativeMouseEvent(MouseEvent nativeMouseEvent) { - return createSyntheticMouseEvent( - bubbles: nativeMouseEvent.bubbles, - cancelable: nativeMouseEvent.cancelable, - currentTarget: nativeMouseEvent.currentTarget, - defaultPrevented: nativeMouseEvent.defaultPrevented, - preventDefault: nativeMouseEvent.preventDefault, - stopPropagation: nativeMouseEvent.stopPropagation, - eventPhase: nativeMouseEvent.eventPhase, - nativeEvent: nativeMouseEvent, - target: nativeMouseEvent.target, - timeStamp: nativeMouseEvent.timeStamp, - type: nativeMouseEvent.type, - altKey: nativeMouseEvent.altKey, - button: nativeMouseEvent.button, - ctrlKey: nativeMouseEvent.ctrlKey, - metaKey: nativeMouseEvent.metaKey, - relatedTarget: nativeMouseEvent.relatedTarget, - shiftKey: nativeMouseEvent.shiftKey, - ); -} - -/// If the consumer specifies a callback like `onChange` on one of our custom form components that are not *actually* -/// form elements - we still need a valid [SyntheticFormEvent] to pass as the expected parameter to that callback. -/// -/// This helper method generates a "fake" [SyntheticFormEvent], with nothing but the `target` set to [element], -/// `type` set to [type] and `timeStamp` set to the current time. All other arguments are `noop`, `false` or `null`. -SyntheticFormEvent fakeSyntheticFormEvent(Element element, String type) { - return createSyntheticFormEvent( - cancelable: false, - currentTarget: element, - eventPhase: Event.AT_TARGET, - target: element, - timeStamp: DateTime.now().millisecondsSinceEpoch, - type: type, - ); -} diff --git a/pubspec.yaml b/pubspec.yaml index 0bf09a02d..4dc65d520 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,3 +47,13 @@ dev_dependencies: pedantic: ^1.8.0 test: ^1.9.1 yaml: ^2.2.1 + +dependency_overrides: + react: + git: + url: https://github.com/cleandart/react-dart.git + ref: 6.0.0-wip + over_react_test: + git: + url: https://github.com/Workiva/over_react_test.git + ref: widen-over-react-constraint diff --git a/test/over_react/util/event_helpers_test.dart b/test/over_react/util/event_helpers_test.dart deleted file mode 100644 index c04f2efa8..000000000 --- a/test/over_react/util/event_helpers_test.dart +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright 2016 Workiva Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -@TestOn('browser') -library event_helpers_test; - -import 'dart:html'; - -import 'package:mockito/mockito.dart'; -import 'package:over_react/over_react.dart'; -import 'package:test/test.dart'; - -/// Main entry point for Event Helpers testing -main() { - test('wrapNativeKeyboardEvent', () { - var nativeKeyboardEvent = MockKeyboardEvent(); - var currentTarget = DivElement(); - var target = DivElement(); - var calls = []; - - when(nativeKeyboardEvent.bubbles).thenReturn(true); - when(nativeKeyboardEvent.cancelable).thenReturn(true); - when(nativeKeyboardEvent.currentTarget).thenReturn(currentTarget); - when(nativeKeyboardEvent.defaultPrevented).thenReturn(false); - when(nativeKeyboardEvent.preventDefault()).thenAnswer((_) => calls.add('preventDefault')); - when(nativeKeyboardEvent.stopPropagation()).thenAnswer((_) => calls.add('stopPropagation')); - when(nativeKeyboardEvent.eventPhase).thenReturn(0); - when(nativeKeyboardEvent.target).thenReturn(target); - when(nativeKeyboardEvent.timeStamp).thenReturn(0); - when(nativeKeyboardEvent.type).thenReturn('type'); - when(nativeKeyboardEvent.altKey).thenReturn(false); - when(nativeKeyboardEvent.charCode).thenReturn(0); - when(nativeKeyboardEvent.ctrlKey).thenReturn(false); - when(nativeKeyboardEvent.location).thenReturn(0); - when(nativeKeyboardEvent.keyCode).thenReturn(0); - when(nativeKeyboardEvent.metaKey).thenReturn(false); - when(nativeKeyboardEvent.repeat).thenReturn(false); - when(nativeKeyboardEvent.shiftKey).thenReturn(false); - - expect(nativeKeyboardEvent.defaultPrevented, isFalse); - - var syntheticKeyboardEvent = wrapNativeKeyboardEvent(nativeKeyboardEvent); - - expect(syntheticKeyboardEvent.bubbles, isTrue); - expect(syntheticKeyboardEvent.cancelable, isTrue); - expect(syntheticKeyboardEvent.currentTarget, currentTarget); - expect(syntheticKeyboardEvent.defaultPrevented, isFalse); - expect(() => syntheticKeyboardEvent.preventDefault(), returnsNormally); - expect(calls, contains('preventDefault')); - expect(() => syntheticKeyboardEvent.stopPropagation(), returnsNormally); - expect(calls, contains('stopPropagation')); - expect(syntheticKeyboardEvent.eventPhase, 0); - expect(syntheticKeyboardEvent.isTrusted, isFalse); - expect(syntheticKeyboardEvent.nativeEvent, nativeKeyboardEvent); - expect(syntheticKeyboardEvent.target, target); - expect(syntheticKeyboardEvent.timeStamp, 0); - expect(syntheticKeyboardEvent.type, 'type'); - expect(syntheticKeyboardEvent.altKey, isFalse); - expect(syntheticKeyboardEvent.char, String.fromCharCode(0)); - expect(syntheticKeyboardEvent.charCode, 0); - expect(syntheticKeyboardEvent.ctrlKey, isFalse); - expect(syntheticKeyboardEvent.locale, isNull); - expect(syntheticKeyboardEvent.location, 0); - expect(syntheticKeyboardEvent.key, isNull); - expect(syntheticKeyboardEvent.keyCode, 0); - expect(syntheticKeyboardEvent.metaKey, isFalse); - expect(syntheticKeyboardEvent.repeat, isFalse); - expect(syntheticKeyboardEvent.shiftKey, isFalse); - }); - - test('wrapNativeMouseEvent', () { - var nativeMouseEvent = MockMouseEvent(); - var currentTarget = DivElement(); - var target = DivElement(); - var relatedTarget = DivElement(); - var calls = []; - - when(nativeMouseEvent.bubbles).thenReturn(true); - when(nativeMouseEvent.cancelable).thenReturn(true); - when(nativeMouseEvent.currentTarget).thenReturn(currentTarget); - when(nativeMouseEvent.defaultPrevented).thenReturn(false); - when(nativeMouseEvent.preventDefault()).thenAnswer((_) => calls.add('preventDefault')); - when(nativeMouseEvent.stopPropagation()).thenAnswer((_) => calls.add('stopPropagation')); - when(nativeMouseEvent.eventPhase).thenReturn(0); - when(nativeMouseEvent.target).thenReturn(target); - when(nativeMouseEvent.timeStamp).thenReturn(0); - when(nativeMouseEvent.type).thenReturn('type'); - when(nativeMouseEvent.altKey).thenReturn(false); - when(nativeMouseEvent.button).thenReturn(0); - when(nativeMouseEvent.ctrlKey).thenReturn(false); - when(nativeMouseEvent.metaKey).thenReturn(false); - when(nativeMouseEvent.relatedTarget).thenReturn(relatedTarget); - when(nativeMouseEvent.shiftKey).thenReturn(false); - - var syntheticMouseEvent = wrapNativeMouseEvent(nativeMouseEvent); - - expect(syntheticMouseEvent.bubbles, isTrue); - expect(syntheticMouseEvent.cancelable, isTrue); - expect(syntheticMouseEvent.currentTarget, currentTarget); - expect(syntheticMouseEvent.defaultPrevented, isFalse); - expect(() => syntheticMouseEvent.preventDefault(), returnsNormally); - expect(calls, contains('preventDefault')); - expect(() => syntheticMouseEvent.stopPropagation(), returnsNormally); - expect(calls, contains('stopPropagation')); - expect(syntheticMouseEvent.eventPhase, 0); - expect(syntheticMouseEvent.isTrusted, isFalse); - expect(syntheticMouseEvent.nativeEvent, nativeMouseEvent); - expect(syntheticMouseEvent.target, target); - expect(syntheticMouseEvent.timeStamp, 0); - expect(syntheticMouseEvent.type, 'type'); - expect(syntheticMouseEvent.altKey, isFalse); - expect(syntheticMouseEvent.button, 0); - expect(syntheticMouseEvent.buttons, isNull); - expect(syntheticMouseEvent.clientX, isNull); - expect(syntheticMouseEvent.clientY, isNull); - expect(syntheticMouseEvent.ctrlKey, isFalse); - expect(syntheticMouseEvent.dataTransfer, isNull); - expect(syntheticMouseEvent.metaKey, isFalse); - expect(syntheticMouseEvent.pageX, isNull); - expect(syntheticMouseEvent.pageY, isNull); - expect(syntheticMouseEvent.relatedTarget, relatedTarget); - expect(syntheticMouseEvent.screenX, isNull); - expect(syntheticMouseEvent.screenY, isNull); - expect(syntheticMouseEvent.shiftKey, isFalse); - }); - - test('fakeSyntheticFormEvent', () { - var element = DivElement(); - var fakeEvent = fakeSyntheticFormEvent(element, 'change'); - - expect(fakeEvent.bubbles, isFalse); - expect(fakeEvent.cancelable, isFalse); - expect(fakeEvent.currentTarget, element); - expect(fakeEvent.defaultPrevented, false); - expect(() => fakeEvent.preventDefault(), returnsNormally); - expect(() => fakeEvent.stopPropagation(), returnsNormally); - expect(fakeEvent.eventPhase, Event.AT_TARGET); - expect(fakeEvent.isTrusted, isFalse); - expect(fakeEvent.nativeEvent, isNull); - expect(fakeEvent.target, element); - expect(fakeEvent.timeStamp, isA()); - expect(fakeEvent.type, 'change'); - }); -} - - -// ignore: avoid_implementing_value_types -class MockKeyboardEvent extends Mock implements KeyboardEvent {} -// ignore: avoid_implementing_value_types -class MockMouseEvent extends Mock implements MouseEvent {} diff --git a/test/over_react_redux/connect_flux_test.dart b/test/over_react_redux/connect_flux_test.dart index 2a8cfac43..2c5f6dd70 100644 --- a/test/over_react_redux/connect_flux_test.dart +++ b/test/over_react_redux/connect_flux_test.dart @@ -53,8 +53,7 @@ main() { JsConnectOptions options, ]) { connectOptions = options; - return originalConnect( - mapStateToProps, mapDispatchToProps, mergeProps, options); + return originalConnect(mapStateToProps, mapDispatchToProps, mergeProps, options); }; }); @@ -76,16 +75,17 @@ main() { }); group('behaves like redux with', () { - test('errors when wrapping a UiComponent', (){ - expect(() => connectFlux()(NonComponentTwoCounter), throwsArgumentError); + test('errors when wrapping a UiComponent', () { + expect( + () => connectFlux()( + NonComponentTwoCounter), + throwsArgumentError); }); group('Provider Usage', () { test('throws without a provider', () { - ConnectedCounter = - connectFlux( - mapStateToProps: (state) => - (ConnectFluxCounter()..currentCount = state.count), + ConnectedCounter = connectFlux( + mapStateToProps: (state) => (ConnectFluxCounter()..currentCount = state.count), mapActionsToProps: (actions) => (ConnectFluxCounter() ..increment = actions.incrementAction ..decrement = actions.decrementAction), @@ -96,8 +96,7 @@ main() { test('does not throw with a provider', () { ConnectedCounter = - connectFlux()( - ConnectFluxCounter); + connectFlux()(ConnectFluxCounter); expect( () => render( @@ -112,9 +111,8 @@ main() { group('forwardRef', () { test('when true: forwards the ref to the wrapped component', () { - ConnectedCounter = - connectFlux( - forwardRef: true)(ConnectFluxCounter); + ConnectedCounter = connectFlux( + forwardRef: true)(ConnectFluxCounter); render( (ReduxProvider()..store = store1)( @@ -125,14 +123,11 @@ main() { }); }); - group('mapStateToProps properly maps the state to the components props', - () { + group('mapStateToProps properly maps the state to the components props', () { test('on inital load', () { - ConnectedCounter = - connectFlux( - mapStateToProps: (state) => - (ConnectFluxCounter()..currentCount = state.count), - forwardRef: true)(ConnectFluxCounter); + ConnectedCounter = connectFlux( + mapStateToProps: (state) => (ConnectFluxCounter()..currentCount = state.count), + forwardRef: true)(ConnectFluxCounter); jacket = mount( (ReduxProvider()..store = store1)( @@ -145,14 +140,12 @@ main() { }); test('after triggered', () async { - ConnectedCounter = - connectFlux( - mapStateToProps: (state) => - (ConnectFluxCounter()..currentCount = state.count), - mapActionsToProps: (actions) => (ConnectFluxCounter() - ..increment = actions.incrementAction - ..decrement = actions.decrementAction), - forwardRef: true)(ConnectFluxCounter); + ConnectedCounter = connectFlux( + mapStateToProps: (state) => (ConnectFluxCounter()..currentCount = state.count), + mapActionsToProps: (actions) => (ConnectFluxCounter() + ..increment = actions.incrementAction + ..decrement = actions.decrementAction), + forwardRef: true)(ConnectFluxCounter); jacket = mount( (ReduxProvider()..store = store1)( @@ -163,8 +156,7 @@ main() { expect(counterRef.current.props.currentCount, 0); expect(jacket.mountNode.innerHtml, contains('Count: 0')); - var dispatchButton = - queryByTestId(jacket.mountNode, 'button-increment'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-increment'); click(dispatchButton); // wait for the next tick for the async dispatch to propagate @@ -175,15 +167,12 @@ main() { }); }); - group( - 'mapStateToPropsWithOwnProps properly maps the state to the components props', - () { + group('mapStateToPropsWithOwnProps properly maps the state to the components props', () { test('on inital load', () { - ConnectedCounter = - connectFlux( - mapStateToPropsWithOwnProps: (state, ownProps) => - (ConnectFluxCounter()..currentCount = state.count), - forwardRef: true)(ConnectFluxCounter); + ConnectedCounter = connectFlux( + mapStateToPropsWithOwnProps: (state, ownProps) => + (ConnectFluxCounter()..currentCount = state.count), + forwardRef: true)(ConnectFluxCounter); jacket = mount( (ReduxProvider()..store = store1)( @@ -196,8 +185,7 @@ main() { }); test('after dispatch', () async { - ConnectedCounter = - connectFlux( + ConnectedCounter = connectFlux( mapStateToPropsWithOwnProps: (state, ownProps) => (ConnectFluxCounter()..currentCount = state.count), mapActionsToProps: (actions) => (ConnectFluxCounter() @@ -215,8 +203,7 @@ main() { expect(counterRef.current.props.currentCount, 0); expect(jacket.mountNode.innerHtml, contains('Count: 0')); - var dispatchButton = - queryByTestId(jacket.mountNode, 'button-increment'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-increment'); click(dispatchButton); // wait for the next tick for the async dispatch to propagate @@ -231,8 +218,7 @@ main() { test('maps actions to props correctly', () async { final stateReferences = []; - ConnectedCounter = - connectFlux( + ConnectedCounter = connectFlux( mapStateToProps: (state) { return ConnectFluxCounter()..currentCount = state.count; }, @@ -254,8 +240,7 @@ main() { expect(jacket.mountNode.innerHtml, contains('Count: 0')); // Click button mapped to trigger `propFromDispatch` prop. - var dispatchButton = - queryByTestId(jacket.mountNode, 'button-decrement'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-decrement'); click(dispatchButton); // wait for the next tick for the async dispatch to propagate @@ -270,8 +255,7 @@ main() { group('mapActionsToPropsWithOwnProps', () { test('maps actions to props correctly', () async { final stateReferences = []; - ConnectedCounter = - connectFlux( + ConnectedCounter = connectFlux( mapStateToProps: (state) { stateReferences.add(state); return ConnectFluxCounter()..currentCount = state.count; @@ -294,8 +278,7 @@ main() { expect(jacket.mountNode.innerHtml, contains('Count: 0')); // Click button mapped to trigger `propFromDispatch` prop. - var dispatchButton = - queryByTestId(jacket.mountNode, 'button-decrement'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-decrement'); click(dispatchButton); // wait for the next tick for the async dispatch to propagate @@ -310,10 +293,8 @@ main() { group('mergeProps', () { test('properly merges props based on consumer map', () async { final propsReferences = []; - ConnectedCounter = - connectFlux( - mapStateToProps: (state) => - (ConnectFluxCounter()..currentCount = state.count), + ConnectedCounter = connectFlux( + mapStateToProps: (state) => (ConnectFluxCounter()..currentCount = state.count), mapActionsToProps: (actions) { return ConnectFluxCounter()..decrement = actions.decrementAction; }, @@ -321,9 +302,8 @@ main() { propsReferences.addAll([stateProps, dispatchProps, ownProps]); return ConnectFluxCounter() // Return whatever value is passed through ownProps until the state count is over 1 - ..currentCount = stateProps.currentCount < 1 - ? ownProps.currentCount - : stateProps.currentCount + ..currentCount = + stateProps.currentCount < 1 ? ownProps.currentCount : stateProps.currentCount ..decrement = ownProps.decrement; }, forwardRef: true, @@ -337,13 +317,11 @@ main() { ..decrement = () { store1.dispatch(IncrementAction()); } - ..currentCount = 900 - )('test'), + ..currentCount = 900)('test'), ), ); // `button-decrement` will be incrementing now - var dispatchButton = - queryByTestId(jacket.mountNode, 'button-decrement'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-decrement'); expect(counterRef.current.props.decrement, isA()); @@ -359,8 +337,7 @@ main() { expect(counterRef.current.props.currentCount, 1); expect(jacket.mountNode.innerHtml, contains('Count: 1')); - propsReferences.forEach( - (store) => expect(store, isA())); + propsReferences.forEach((store) => expect(store, isA())); }); }); @@ -368,8 +345,7 @@ main() { group('areOwnPropsEqual', () { test('', () { final propsReferences = []; - ConnectedCounter = - connectFlux( + ConnectedCounter = connectFlux( areOwnPropsEqual: expectAsync2((next, prev) { propsReferences.addAll([prev, next]); expect(next.id, 'test'); @@ -383,8 +359,7 @@ main() { JsBackedMap.from({'id': 'test2'}).jsObject); expect(whatever, isTrue); - propsReferences.forEach( - (store) => expect(store, isA())); + propsReferences.forEach((store) => expect(store, isA())); }); }); @@ -406,8 +381,7 @@ main() { }); test('', () async { - ConnectedCounter = - connectFlux( + ConnectedCounter = connectFlux( mapStateToProps: (state) { methodsCalled.add({'called': 'mapStateToProps', 'state': state}); return ConnectFluxCounter()..currentCount = state.count; @@ -447,8 +421,7 @@ main() { methodsCalled.clear(); - var dispatchButton = - queryByTestId(jacket.mountNode, 'button-increment'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-increment'); click(dispatchButton); // wait for the next tick for the async dispatch to propagate @@ -470,13 +443,11 @@ main() { expect(jacket.mountNode.innerHtml, contains('Count: 0')); }); - test( - 'matches a Redux component with impure state when `areStatesEqual` is false', + test('matches a Redux component with impure state when `areStatesEqual` is false', () async { final localReduxRef = createRef(); - final ReduxConnectedCounter = - connect( + final ReduxConnectedCounter = connect( mapStateToProps: (state) { methodsCalled.add({ 'called': 'mapStateToProps', @@ -527,8 +498,7 @@ main() { } methodsCalled.clear(); - var dispatchButton = - queryByTestId(jacket.mountNode, 'button-increment'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-increment'); click(dispatchButton); // wait for the next tick for the async dispatch to propagate @@ -540,8 +510,7 @@ main() { expectedUpdateMethodCalls .map((expected) => containsPair('called', expected)) .toList(), - reason: - 'connect\'s sequence of calls should match expectedUpdateMethodCalls'); + reason: 'connect\'s sequence of calls should match expectedUpdateMethodCalls'); for (final methodCall in methodsCalled) { if (methodCall['called'] == 'areStatePropsEqual') { @@ -558,8 +527,7 @@ main() { test('', () { final propsReferences = []; - ConnectedCounter = - connectFlux( + ConnectedCounter = connectFlux( areMergedPropsEqual: expectAsync2((next, prev) { expect(next.id, 'test'); expect(prev.id, 'test2'); @@ -573,8 +541,7 @@ main() { JsBackedMap.from({'id': 'test2'}).jsObject); expect(whatever, isTrue); - propsReferences.forEach( - (store) => expect(store, isA())); + propsReferences.forEach((store) => expect(store, isA())); }); }); }); @@ -582,10 +549,8 @@ main() { group('context', () { test('correctly renders with multiple contexts/stores', () async { var bigCounterContext = createContext(); - ConnectedCounter = - connectFlux( - mapStateToProps: (state) => - (ConnectFluxCounter()..currentCount = state.count), + ConnectedCounter = connectFlux( + mapStateToProps: (state) => (ConnectFluxCounter()..currentCount = state.count), mapActionsToProps: (actions) { return ConnectFluxCounter() ..increment = actions.incrementAction @@ -593,10 +558,8 @@ main() { }, forwardRef: true, )(ConnectFluxCounter); - var ConnectedBigCounter = - connectFlux( - mapStateToProps: (state) => - (ConnectFluxCounter()..currentCount = state.count), + var ConnectedBigCounter = connectFlux( + mapStateToProps: (state) => (ConnectFluxCounter()..currentCount = state.count), mapActionsToProps: (actions) => (ConnectFluxCounter() ..increment = actions.incrementAction ..decrement = actions.decrementAction), @@ -607,8 +570,7 @@ main() { jacket = mount((ReduxProvider()..store = store1)( (ReduxProvider() ..store = store2 - ..context = bigCounterContext - )( + ..context = bigCounterContext)( Dom.div()( ConnectedCounter()('test'), (ConnectedBigCounter()..addTestId('big-counter'))(), @@ -628,20 +590,16 @@ main() { test('correctly renders when contexts are nested', () async { var bigCounterContext = createContext(); - ConnectedCounter = - connectFlux( - mapStateToProps: (state) => - (ConnectFluxCounter()..currentCount = state.count), + ConnectedCounter = connectFlux( + mapStateToProps: (state) => (ConnectFluxCounter()..currentCount = state.count), mapActionsToProps: (actions) => (ConnectFluxCounter() ..increment = actions.incrementAction ..decrement = actions.decrementAction), forwardRef: true, )(ConnectFluxCounter); - var ConnectedBigCounter = - connectFlux( - mapStateToProps: (state) => - (ConnectFluxCounter()..currentCount = state.count), + var ConnectedBigCounter = connectFlux( + mapStateToProps: (state) => (ConnectFluxCounter()..currentCount = state.count), mapActionsToProps: (actions) => (ConnectFluxCounter() ..increment = actions.incrementAction ..decrement = actions.decrementAction), @@ -652,8 +610,7 @@ main() { jacket = mount((ReduxProvider()..store = store1)( (ReduxProvider() ..store = store2 - ..context = bigCounterContext - )( + ..context = bigCounterContext)( Dom.div()( (ConnectedCounter()..addTestId('outside'))('test'), ), @@ -668,8 +625,7 @@ main() { var bigCounter = queryByTestId(jacket.mountNode, 'big-counter'); var smallCounter = queryByTestId(jacket.mountNode, 'small-counter'); - var smallDispatchButton = - queryByTestId(smallCounter, 'button-increment'); + var smallDispatchButton = queryByTestId(smallCounter, 'button-increment'); var dispatchButton = queryByTestId(bigCounter, 'button-increment'); click(dispatchButton); @@ -682,8 +638,7 @@ main() { reason: 'Should have a count of 100'); // Normal counter incremented only 1 at both instances - expect( - findDomNode(queryByTestId(jacket.mountNode, 'outside')).innerHtml, + expect(findDomNode(queryByTestId(jacket.mountNode, 'outside')).innerHtml, contains('Count: 1')); expect(findDomNode(bigCounter).innerHtml, contains('Count: 1')); }); @@ -723,30 +678,25 @@ main() { }; testCases.forEach((parameterCase, parameters) { - bool shouldDomUpdate(Map parameters) => - (parameters['mapStateToProps'] != null || - parameters['mapStateToPropsWithOwnProps'] != null); + bool shouldDomUpdate(Map parameters) => (parameters['mapStateToProps'] != null || + parameters['mapStateToPropsWithOwnProps'] != null); test(parameterCase, () async { final ConnectedFluxComponent = connectFlux( mapStateToProps: parameters['mapStateToProps'], mapActionsToProps: parameters['mapActionsToProps'], - mapStateToPropsWithOwnProps: - parameters['mapStateToPropsWithOwnProps'], - mapActionsToPropsWithOwnProps: - parameters['mapActionsToPropsWithOwnProps'], + mapStateToPropsWithOwnProps: parameters['mapStateToPropsWithOwnProps'], + mapActionsToPropsWithOwnProps: parameters['mapActionsToPropsWithOwnProps'], )(ConnectFluxCounter); final jacket2 = mount((ReduxProvider()..store = store1)( (ConnectedFluxComponent() ..actions = fluxActions - ..addTestId('flux-component') - )(), + ..addTestId('flux-component'))(), )); - final fluxCounter = - queryByTestId(jacket2.mountNode, 'flux-component'); + final fluxCounter = queryByTestId(jacket2.mountNode, 'flux-component'); final fluxButton = queryByTestId(fluxCounter, 'button-increment'); expect(fluxStore.state.count, 0); @@ -772,12 +722,11 @@ main() { }); test('prints a warning when state is mutated directly', () async { - final ConnectedFluxComponent = - connectFlux( - mapStateToProps: (state) => (ConnectFluxCounter() - ..mutatedList = state.listYouDefShouldntMutate), - mapActionsToProps: (actions) => (ConnectFluxCounter() - ..mutateStoreDirectly = actions.mutateStoreDirectly), + final ConnectedFluxComponent = connectFlux( + mapStateToProps: (state) => + (ConnectFluxCounter()..mutatedList = state.listYouDefShouldntMutate), + mapActionsToProps: (actions) => + (ConnectFluxCounter()..mutateStoreDirectly = actions.mutateStoreDirectly), )(ConnectFluxCounter); final jacket = mount((ReduxProvider()..store = store1)( @@ -792,6 +741,7 @@ main() { await Future(() {}); }); + logs.removeWhere((log) => log.contains('Cannot find native JavaScript type')); expect( logs.first, contains( @@ -802,10 +752,8 @@ main() { typedef mapStateToProps = Map Function(FluxStore); typedef mapActionsToProps = Map Function(FluxActions); -typedef mapStateToPropsWithOwnProps = Map Function( - FluxStore, ConnectFluxCounterProps); -typedef mapActionsToPropsWithOwnProps = Map Function( - FluxActions, ConnectFluxCounterProps); +typedef mapStateToPropsWithOwnProps = Map Function(FluxStore, ConnectFluxCounterProps); +typedef mapActionsToPropsWithOwnProps = Map Function(FluxActions, ConnectFluxCounterProps); mapStateToProps get testMapStateToProps => (state) => (ConnectFluxCounter()..currentCount = state.count); @@ -814,5 +762,4 @@ mapActionsToProps get testMapActionsToProps => mapStateToPropsWithOwnProps get testMapStateToPropsWithOwnProps => (state, ownProps) => (ConnectFluxCounter()..currentCount = state.count); mapActionsToPropsWithOwnProps get testMapActionsToPropsWithOwnProps => - (actions, ownProps) => - (ConnectFluxCounter()..increment = actions.incrementAction); + (actions, ownProps) => (ConnectFluxCounter()..increment = actions.incrementAction); diff --git a/test/over_react_util_test.dart b/test/over_react_util_test.dart index 2c816d090..2a8023ec9 100644 --- a/test/over_react_util_test.dart +++ b/test/over_react_util_test.dart @@ -26,7 +26,6 @@ import 'over_react/util/class_names_test.dart' as class_names_test; import 'over_react/util/constants_base_test.dart' as constants_base_test; import 'over_react/util/css_value_util_test.dart' as css_value_util_test; import 'over_react/util/dom_util_test.dart' as dom_util_test; -import 'over_react/util/event_helpers_test.dart' as event_helpers_test; import 'over_react/util/equality_test.dart' as equality_test; import 'over_react/util/guid_util_test.dart' as guid_util_test; import 'over_react/util/handler_chain_util_test.dart' as handler_chain_util_test; @@ -49,7 +48,6 @@ void main() { constants_base_test.main(); css_value_util_test.main(); dom_util_test.main(); - event_helpers_test.main(); equality_test.main(); guid_util_test.main(); handler_chain_util_test.main(); diff --git a/tools/analyzer_plugin/playground/pubspec.yaml b/tools/analyzer_plugin/playground/pubspec.yaml index 7e563fd2e..34c687b23 100644 --- a/tools/analyzer_plugin/playground/pubspec.yaml +++ b/tools/analyzer_plugin/playground/pubspec.yaml @@ -13,3 +13,7 @@ dependency_overrides: # Pull in the local copy of over_react so it pulls in the local copy of the plugin over_react: path: ../../.. + react: + git: + url: https://github.com/cleandart/react-dart.git + ref: 6.0.0-wip diff --git a/tools/analyzer_plugin/pubspec.yaml b/tools/analyzer_plugin/pubspec.yaml index 991ee882e..c22119c0c 100644 --- a/tools/analyzer_plugin/pubspec.yaml +++ b/tools/analyzer_plugin/pubspec.yaml @@ -44,3 +44,8 @@ dev_dependencies: # dependency_overrides: # over_react: # path: /Users/me/workspaces/over_react +dependency_overrides: + react: + git: + url: https://github.com/cleandart/react-dart.git + ref: 6.0.0-wip