esp-js-react 8.0.0-next.0 → 8.0.2-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dist/esp-react.js +132 -90
- package/.dist/esp-react.js.map +1 -1
- package/.dist/esp-react.min.js +1 -1
- package/.dist/esp-react.min.js.map +1 -1
- package/.dist/typings/{espModelContext.d.ts → espModelContextProvider.d.ts} +2 -2
- package/.dist/typings/{espRouterContext.d.ts → espRouterContextProvider.d.ts} +8 -8
- package/.dist/typings/index.d.ts +5 -5
- package/.dist/typings/polimer/getEspPolimerImmutableModel.d.ts +21 -0
- package/.dist/typings/useModelSelector.d.ts +20 -6
- package/package.json +4 -4
- package/src/connectableComponent.tsx +10 -9
- package/src/{espModelContext.tsx → espModelContextProvider.tsx} +5 -5
- package/src/{espRouterContext.tsx → espRouterContextProvider.tsx} +8 -8
- package/src/index.ts +19 -13
- package/src/polimer/getEspPolimerImmutableModel.ts +50 -0
- package/src/useModelSelector.ts +85 -20
- package/src/viewBinder.tsx +1 -1
- package/src/viewBinderConnectable.tsx +11 -10
- package/tests/connectableComponentLegacyTests.tsx +26 -26
- package/tests/connectableComponentTests.tsx +419 -0
- package/tests/indexTests.ts +25 -91
- package/tests/testApi/asserts.ts +75 -0
- package/tests/testApi/routerSpy.ts +24 -0
- package/tests/testApi/testApi.tsx +84 -0
- package/tests/testApi/testModel.ts +37 -0
- package/tests/testApi/useStoreReceivedProps.ts +11 -0
- package/tests/testApi/viewMetadata.tsx +46 -0
- package/tests/useModelSelectorTests.tsx +257 -0
- package/.dist/typings/polimer/getEspReactRenderModel.d.ts +0 -21
- package/src/polimer/getEspReactRenderModel.ts +0 -50
- package/tests/connectWithSelectorTests.tsx +0 -67
- /package/.dist/typings/polimer/{polimerExtentsions.d.ts → polimerModelBuilderExtentsions.d.ts} +0 -0
- /package/src/polimer/{polimerExtentsions.ts → polimerModelBuilderExtentsions.ts} +0 -0
|
@@ -5,25 +5,25 @@ import {
|
|
|
5
5
|
ConnectableComponent,
|
|
6
6
|
ConnectableComponentProps,
|
|
7
7
|
viewBinding,
|
|
8
|
-
|
|
8
|
+
getEspPolimerImmutableModel,
|
|
9
9
|
PublishModelEventDelegate,
|
|
10
10
|
RouterContext,
|
|
11
|
-
|
|
11
|
+
EspRouterContextProvider
|
|
12
12
|
} from '../src';
|
|
13
13
|
import {Router, observeEvent, utils} from 'esp-js';
|
|
14
14
|
import {render, RenderResult} from '@testing-library/react';
|
|
15
15
|
|
|
16
|
-
const getPropsAsDataAttributesWithMetadata = (props: any) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
16
|
+
// const getPropsAsDataAttributesWithMetadata = (props: any) => {
|
|
17
|
+
// const propsAsDataAttributes: {[key: string]: string} = Object.keys(props).reduce((result: any, key: string) => {
|
|
18
|
+
// let prop = props[key];
|
|
19
|
+
// // need to lower case data-* attributes else React throws a warning
|
|
20
|
+
// result[`data-${key.toLowerCase()}`] = utils.isString(prop)
|
|
21
|
+
// ? prop
|
|
22
|
+
// : typeof prop;
|
|
23
|
+
// return result;
|
|
24
|
+
// }, {});
|
|
25
|
+
// return propsAsDataAttributes;
|
|
26
|
+
// };
|
|
27
27
|
|
|
28
28
|
class TestModelView1 extends React.Component {
|
|
29
29
|
constructor(props) {
|
|
@@ -77,7 +77,7 @@ class TestModel {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
class TestModel2 extends TestModel {
|
|
80
|
-
@
|
|
80
|
+
@getEspPolimerImmutableModel()
|
|
81
81
|
_getOtherState() {
|
|
82
82
|
return {
|
|
83
83
|
value: this.value,
|
|
@@ -88,7 +88,7 @@ class TestModel2 extends TestModel {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
class TestModel3 extends TestModel {
|
|
91
|
-
|
|
91
|
+
getEspPolimerImmutableModel() {
|
|
92
92
|
return {
|
|
93
93
|
value: this.value,
|
|
94
94
|
value2: this.value,
|
|
@@ -109,11 +109,11 @@ interface TestOptions {
|
|
|
109
109
|
useCreatePublishEventProps?: boolean;
|
|
110
110
|
useAlternativeViewContext?: boolean;
|
|
111
111
|
passOtherProps?: boolean;
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
useImmutableModelSelectorDecorator?: boolean;
|
|
113
|
+
useImmutableModelSelectorFunction?: boolean;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
xdescribe('ConnectableComponent', () => {
|
|
117
117
|
let router,
|
|
118
118
|
testModel: TestModel,
|
|
119
119
|
testModel2: TestModel,
|
|
@@ -126,10 +126,10 @@ describe('ConnectableComponent', () => {
|
|
|
126
126
|
otherProps = {other1: 'other-value'};
|
|
127
127
|
|
|
128
128
|
function createModel(options: TestOptions) {
|
|
129
|
-
if (options.
|
|
129
|
+
if (options.useImmutableModelSelectorDecorator) {
|
|
130
130
|
return new TestModel2();
|
|
131
131
|
}
|
|
132
|
-
if (options.
|
|
132
|
+
if (options.useImmutableModelSelectorFunction) {
|
|
133
133
|
return new TestModel3();
|
|
134
134
|
}
|
|
135
135
|
return new TestModel();
|
|
@@ -177,14 +177,14 @@ describe('ConnectableComponent', () => {
|
|
|
177
177
|
);
|
|
178
178
|
} else {
|
|
179
179
|
renderResult = render(
|
|
180
|
-
<
|
|
180
|
+
<EspRouterContextProvider router={router} >
|
|
181
181
|
<ConnectableComponent
|
|
182
182
|
{...connectableComponentProps}
|
|
183
183
|
mapModelToProps={mapModelToProps}
|
|
184
184
|
viewContext={userAlternativeViewContext}
|
|
185
185
|
{...otherProps}
|
|
186
186
|
/>
|
|
187
|
-
</
|
|
187
|
+
</EspRouterContextProvider>
|
|
188
188
|
);
|
|
189
189
|
}
|
|
190
190
|
}
|
|
@@ -379,24 +379,24 @@ describe('ConnectableComponent', () => {
|
|
|
379
379
|
//
|
|
380
380
|
// describe('using @stateToRenderSelector', () => {
|
|
381
381
|
// it('Swaps the model for that returned by the function decorated with a @stateToRenderSelector decorator', () => {
|
|
382
|
-
// setup({useConnectFunction: false,
|
|
382
|
+
// setup({useConnectFunction: false, useImmutableModelSelectorDecorator: true});
|
|
383
383
|
// testModelHasBeenReplacedWithMappedModel('value-3');
|
|
384
384
|
// });
|
|
385
385
|
//
|
|
386
386
|
// it('passes the swapped model to mapModelToProps function', () => {
|
|
387
|
-
// setup({useConnectFunction: false,
|
|
387
|
+
// setup({useConnectFunction: false, useImmutableModelSelectorDecorator: true, useMapModelToProps: true});
|
|
388
388
|
// testSwappedModelPassedToMapModelToPropsFunction('value-3');
|
|
389
389
|
// });
|
|
390
390
|
// });
|
|
391
391
|
//
|
|
392
392
|
// describe('using state to render function', () => {
|
|
393
393
|
// it('Swaps the model for that returned by the function decorated with a @stateToRenderSelector decorator', () => {
|
|
394
|
-
// setup({useConnectFunction: false,
|
|
394
|
+
// setup({useConnectFunction: false, useImmutableModelSelectorFunction: true});
|
|
395
395
|
// testModelHasBeenReplacedWithMappedModel('value-3.1');
|
|
396
396
|
// });
|
|
397
397
|
//
|
|
398
398
|
// it('passes the swapped model to mapModelToProps function', () => {
|
|
399
|
-
// setup({useConnectFunction: false,
|
|
399
|
+
// setup({useConnectFunction: false, useImmutableModelSelectorFunction: true, useMapModelToProps: true});
|
|
400
400
|
// testSwappedModelPassedToMapModelToPropsFunction('value-3.1');
|
|
401
401
|
// });
|
|
402
402
|
// });
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import 'jest';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import {act} from 'react';
|
|
4
|
+
import {
|
|
5
|
+
connect,
|
|
6
|
+
ConnectableComponent,
|
|
7
|
+
ConnectableComponentProps,
|
|
8
|
+
EspRouterContextProvider,
|
|
9
|
+
getEspPolimerImmutableModel,
|
|
10
|
+
modelSelectorOptions,
|
|
11
|
+
PublishModelEventDelegate,
|
|
12
|
+
RouterContext,
|
|
13
|
+
useModelSelector,
|
|
14
|
+
viewBinding,
|
|
15
|
+
GetEspPolimerImmutableModelConsts
|
|
16
|
+
} from '../src';
|
|
17
|
+
import {TestModelImmutableState} from './testApi/testModel';
|
|
18
|
+
import {ViewMetadata} from './testApi/viewMetadata';
|
|
19
|
+
import {routerAsserts} from './testApi/asserts';
|
|
20
|
+
import {testApi, TestApi} from './testApi/testApi';
|
|
21
|
+
import {observeEvent, Router} from 'esp-js';
|
|
22
|
+
import {render, RenderResult} from '@testing-library/react';
|
|
23
|
+
import {useTestPropStore} from './testApi/useStoreReceivedProps';
|
|
24
|
+
|
|
25
|
+
type SelectedObject = { id: string, value: string };
|
|
26
|
+
|
|
27
|
+
const createView = (name: string) => {
|
|
28
|
+
return (props: { modelId: string; value: string, [key: string]: any }) => {
|
|
29
|
+
let testPropStore = useTestPropStore();
|
|
30
|
+
testPropStore.pushProps(props);
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
<span data-testid='view-name'>{name}</span>
|
|
34
|
+
<ViewMetadata modelId={props.modelId} modelValue={props.value} {...props}/>
|
|
35
|
+
</>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
interface MappedModel {
|
|
41
|
+
value: string;
|
|
42
|
+
value2: string;
|
|
43
|
+
value3: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@viewBinding(createView('View1'))
|
|
47
|
+
@viewBinding(createView('View3'), 'alternative-view-context')
|
|
48
|
+
class TestModel {
|
|
49
|
+
public value: string;
|
|
50
|
+
|
|
51
|
+
constructor() {
|
|
52
|
+
this.value = 'initial-value';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@observeEvent('test-event')
|
|
56
|
+
_onTestEvent(ev: string) {
|
|
57
|
+
this.value = ev;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
class TestModel2 extends TestModel {
|
|
62
|
+
@getEspPolimerImmutableModel()
|
|
63
|
+
_getOtherState() {
|
|
64
|
+
return {
|
|
65
|
+
value: this.value,
|
|
66
|
+
value2: this.value,
|
|
67
|
+
value3: 'value-3'
|
|
68
|
+
} as MappedModel;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
class TestModel3 extends TestModel {
|
|
73
|
+
[GetEspPolimerImmutableModelConsts.HandlerFunctionName] = () => {
|
|
74
|
+
return {
|
|
75
|
+
value: this.value,
|
|
76
|
+
value2: this.value,
|
|
77
|
+
value3: 'value-3.1'
|
|
78
|
+
} as MappedModel;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface TestOptions {
|
|
83
|
+
useConnectFunction?: boolean;
|
|
84
|
+
useMapModelToProps?: boolean;
|
|
85
|
+
useCreatePublishEventProps?: boolean;
|
|
86
|
+
useAlternativeViewContext?: boolean;
|
|
87
|
+
passOtherProps?: boolean;
|
|
88
|
+
useImmutableModelSelectorDecorator?: boolean;
|
|
89
|
+
useImmutableModelSelectorFunction?: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
describe('ConnectableComponentTests', () => {
|
|
93
|
+
let api: TestApi;
|
|
94
|
+
let router,
|
|
95
|
+
testModel: TestModel,
|
|
96
|
+
testModel2: TestModel,
|
|
97
|
+
renderResult: RenderResult,
|
|
98
|
+
connectableComponentProps: ConnectableComponentProps<TestModel>,
|
|
99
|
+
mapModelToProps,
|
|
100
|
+
createPublishEventProps,
|
|
101
|
+
publishEventProps,
|
|
102
|
+
userAlternativeViewContext,
|
|
103
|
+
otherProps = {other1: 'other-value'};
|
|
104
|
+
|
|
105
|
+
beforeEach(() => {
|
|
106
|
+
api = testApi();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
function createModel(options?: TestOptions) {
|
|
110
|
+
if (options?.useImmutableModelSelectorDecorator) {
|
|
111
|
+
return new TestModel2();
|
|
112
|
+
}
|
|
113
|
+
if (options?.useImmutableModelSelectorFunction) {
|
|
114
|
+
return new TestModel3();
|
|
115
|
+
}
|
|
116
|
+
return new TestModel();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function setup(options: TestOptions) {
|
|
120
|
+
testModel = createModel(options);
|
|
121
|
+
testModel2 = createModel();
|
|
122
|
+
|
|
123
|
+
// testModel = createModel(options);
|
|
124
|
+
// router.addModel('model-id', testModel);
|
|
125
|
+
// router.observeEventsOn('model-id', testModel);
|
|
126
|
+
// testModel2 = new TestModel();
|
|
127
|
+
// router.addModel('model-id2', testModel2);
|
|
128
|
+
// router.observeEventsOn('model-id2', testModel2);
|
|
129
|
+
|
|
130
|
+
api.setupModel('model-id', testModel);
|
|
131
|
+
api.setupModel('model-id2', testModel2);
|
|
132
|
+
|
|
133
|
+
connectableComponentProps = {
|
|
134
|
+
modelId: 'model-id'
|
|
135
|
+
};
|
|
136
|
+
if (options.useMapModelToProps) {
|
|
137
|
+
mapModelToProps = (model: TestModel | MappedModel, publishEventProps2: any) => {
|
|
138
|
+
return {
|
|
139
|
+
foo: model.value,
|
|
140
|
+
publishEventPropsPassedMapModelToProps: publishEventProps2 && typeof publishEventProps2.publishEvent1 === 'function',
|
|
141
|
+
...model
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (options.useCreatePublishEventProps) {
|
|
146
|
+
publishEventProps = {
|
|
147
|
+
publishEvent1: () => {
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
createPublishEventProps = (publishEvent: PublishModelEventDelegate) => publishEventProps;
|
|
151
|
+
}
|
|
152
|
+
if (options.useAlternativeViewContext) {
|
|
153
|
+
userAlternativeViewContext = 'alternative-view-context';
|
|
154
|
+
}
|
|
155
|
+
let viewElement: React.JSX.Element;
|
|
156
|
+
if (options.useConnectFunction) {
|
|
157
|
+
const TestModelView2ConnectedComponent = connect(
|
|
158
|
+
mapModelToProps,
|
|
159
|
+
createPublishEventProps
|
|
160
|
+
)(createView('View2'));
|
|
161
|
+
viewElement = (<TestModelView2ConnectedComponent {...otherProps} {...connectableComponentProps}/>);
|
|
162
|
+
} else {
|
|
163
|
+
viewElement = (
|
|
164
|
+
<ConnectableComponent
|
|
165
|
+
{...connectableComponentProps}
|
|
166
|
+
mapModelToProps={mapModelToProps}
|
|
167
|
+
viewContext={userAlternativeViewContext}
|
|
168
|
+
{...otherProps}
|
|
169
|
+
/>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
api.doRender(viewElement, 'model-id');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function publishAnEventToModel1() {
|
|
176
|
+
router.publishEvent('model-id', 'test-event', 'the-event-value');
|
|
177
|
+
expect(testModel.value).toEqual('the-event-value');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function publishAnEventToModel2() {
|
|
181
|
+
router.publishEvent('model-id2', 'test-event', 'the-event-value2');
|
|
182
|
+
expect(testModel2.value).toEqual('the-event-value2');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
describe('ConnectableComponent via connect()', () => {
|
|
186
|
+
beforeEach(() => {
|
|
187
|
+
setup({useConnectFunction: true, useMapModelToProps: true, useCreatePublishEventProps: true});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('renders correct view', () => {
|
|
191
|
+
api.asserts.view.htmlElementInnerTextIs('view-name', 'View2');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe('Child view props', () => {
|
|
195
|
+
|
|
196
|
+
it('renders only once', () => {
|
|
197
|
+
api.asserts.props
|
|
198
|
+
.receivedPropCountIs(1);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('passes mapped props', () => {
|
|
202
|
+
api.asserts.props
|
|
203
|
+
.propAtIndex(
|
|
204
|
+
0,
|
|
205
|
+
props => {
|
|
206
|
+
expect(props.foo).toBe('initial-value');
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('passes results of publishEventProps to mapModelToProps', () => {
|
|
212
|
+
api.asserts.props
|
|
213
|
+
.propAtIndex(
|
|
214
|
+
0,
|
|
215
|
+
props => {
|
|
216
|
+
expect(props.publishEventPropsPassedMapModelToProps).toBeTruthy();
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('passes model', () => {
|
|
222
|
+
api.asserts.props
|
|
223
|
+
.propAtIndex(
|
|
224
|
+
0,
|
|
225
|
+
props => {
|
|
226
|
+
expect(props.model).toBeDefined();
|
|
227
|
+
expect(props.model instanceof TestModel).toBeTruthy();
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('flattens and passes results of createPublishEventProps', () => {
|
|
233
|
+
api.asserts.props
|
|
234
|
+
.receivedPropCountIs(1)
|
|
235
|
+
.propAtIndex(
|
|
236
|
+
0,
|
|
237
|
+
props => {
|
|
238
|
+
expect(props.publishEvent1).toBeDefined();
|
|
239
|
+
expect(typeof props.publishEvent1).toBe('function');
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('passes other props', () => {
|
|
245
|
+
api.asserts.props
|
|
246
|
+
.propAtIndex(
|
|
247
|
+
0,
|
|
248
|
+
props => {
|
|
249
|
+
expect(props.other1).toBeDefined();
|
|
250
|
+
expect(props.other1).toBe('other-value');
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
//
|
|
256
|
+
// describe('View rendering', () => {
|
|
257
|
+
// it('Renders the view provided to connect', () => {
|
|
258
|
+
// expect(connectableComponentWrapper.containsMatchingElement(<TestModelView2/>)).toBeTruthy();
|
|
259
|
+
// });
|
|
260
|
+
// });
|
|
261
|
+
});
|
|
262
|
+
//
|
|
263
|
+
// describe('ConnectableComponent directly', () => {
|
|
264
|
+
//
|
|
265
|
+
// const getSpanWithPropsAsAttributes = () => {
|
|
266
|
+
// return connectableComponentWrapper.childAt(0).props() as ConnectableComponentChildProps<TestModel>;
|
|
267
|
+
// };
|
|
268
|
+
//
|
|
269
|
+
// describe('Child view props', () => {
|
|
270
|
+
// beforeEach(() => {
|
|
271
|
+
// setup({useConnectFunction: false});
|
|
272
|
+
// });
|
|
273
|
+
//
|
|
274
|
+
// it('passes modelId', () => {
|
|
275
|
+
// let span = getSpanWithPropsAsAttributes();
|
|
276
|
+
// expect(props.modelId).toEqual('model-id');
|
|
277
|
+
// });
|
|
278
|
+
//
|
|
279
|
+
// it('passes router', () => {
|
|
280
|
+
// let span = getSpanWithPropsAsAttributes();
|
|
281
|
+
// expect(props.router).toBe(router);
|
|
282
|
+
// });
|
|
283
|
+
//
|
|
284
|
+
// it('passes model', () => {
|
|
285
|
+
// let span = getSpanWithPropsAsAttributes();
|
|
286
|
+
// expect(props.model).toBe(testModel);
|
|
287
|
+
// });
|
|
288
|
+
//
|
|
289
|
+
// it('passes other props', () => {
|
|
290
|
+
// let span = getSpanWithPropsAsAttributes();
|
|
291
|
+
// expect(props.other1).toEqual('other-value');
|
|
292
|
+
// });
|
|
293
|
+
// });
|
|
294
|
+
//
|
|
295
|
+
// describe('Re-renders', () => {
|
|
296
|
+
// beforeEach(() => {
|
|
297
|
+
// setup({useConnectFunction: false});
|
|
298
|
+
// });
|
|
299
|
+
//
|
|
300
|
+
// it('Re-renders when model updates', () => {
|
|
301
|
+
// publishAnEventToModel1();
|
|
302
|
+
// let span = getSpanWithPropsAsAttributes();
|
|
303
|
+
// expect(props.model.value).toBe('the-event-value');
|
|
304
|
+
// });
|
|
305
|
+
// });
|
|
306
|
+
//
|
|
307
|
+
// describe('Model Subscription', () => {
|
|
308
|
+
// beforeEach(() => {
|
|
309
|
+
// setup({useConnectFunction: false});
|
|
310
|
+
// });
|
|
311
|
+
//
|
|
312
|
+
// it('Re-subscribes to new model when modelId changes', () => {
|
|
313
|
+
// const newProps = {
|
|
314
|
+
// ...connectableComponentWrapper.props(),
|
|
315
|
+
// modelId: 'model-id2',
|
|
316
|
+
// };
|
|
317
|
+
// connectableComponentWrapper.setProps(newProps);
|
|
318
|
+
// publishAnEventToModel2();
|
|
319
|
+
// let span = getSpanWithPropsAsAttributes();
|
|
320
|
+
// expect(props.foo).toBe('the-event-value2');
|
|
321
|
+
// });
|
|
322
|
+
// });
|
|
323
|
+
//
|
|
324
|
+
// describe('Publish Event Context', () => {
|
|
325
|
+
// beforeEach(() => {
|
|
326
|
+
// setup({useConnectFunction: false});
|
|
327
|
+
// });
|
|
328
|
+
//
|
|
329
|
+
// // Cant test hooks yet, will test using state below
|
|
330
|
+
// // https://github.com/enzymejs/enzyme/issues/2011
|
|
331
|
+
// xit('Can publish event via context', () => {
|
|
332
|
+
// const childViewContext = connectableComponentWrapper.context();
|
|
333
|
+
// let publishEvent: PublishModelEventDelegate = React.useContext(PublishModelEventContext);
|
|
334
|
+
// publishEvent('test-event', 'the-event-value');
|
|
335
|
+
// let span = getSpanWithPropsAsAttributes();
|
|
336
|
+
// expect(props.foo).toBe('the-event-value');
|
|
337
|
+
// });
|
|
338
|
+
//
|
|
339
|
+
// // Note this is a a best effort to test the context hook created via state
|
|
340
|
+
// it('publishEvent set', () => {
|
|
341
|
+
// const state = connectableComponentWrapper.state();
|
|
342
|
+
// state.publishEvent('test-event', 'the-event-value');
|
|
343
|
+
// let span = getSpanWithPropsAsAttributes();
|
|
344
|
+
// expect(props.model.value).toBe('the-event-value');
|
|
345
|
+
// });
|
|
346
|
+
//
|
|
347
|
+
// it('publishEvent recreated on model change', () => {
|
|
348
|
+
// const newProps = {
|
|
349
|
+
// ...connectableComponentWrapper.props(),
|
|
350
|
+
// modelId: 'model-id2',
|
|
351
|
+
// };
|
|
352
|
+
// connectableComponentWrapper.setProps(newProps);
|
|
353
|
+
// const state = connectableComponentWrapper.state();
|
|
354
|
+
// state.publishEvent('test-event', 'the-event-value');
|
|
355
|
+
// let span = getSpanWithPropsAsAttributes();
|
|
356
|
+
// expect(props.model.value).toBe('the-event-value');
|
|
357
|
+
// expect(testModel2.value).toBe('the-event-value');
|
|
358
|
+
// });
|
|
359
|
+
// });
|
|
360
|
+
//
|
|
361
|
+
// describe('View rendering', () => {
|
|
362
|
+
// it('Renders the view found via @viewBinding', () => {
|
|
363
|
+
// setup({useConnectFunction: false});
|
|
364
|
+
// expect(connectableComponentWrapper.containsMatchingElement(<TestModelView1/>)).toBeTruthy();
|
|
365
|
+
// });
|
|
366
|
+
//
|
|
367
|
+
// it('Renders alternative view found via @viewBinding', () => {
|
|
368
|
+
// setup({useConnectFunction: false, useAlternativeViewContext: true});
|
|
369
|
+
// expect(connectableComponentWrapper.containsMatchingElement(<TestModelView3/>)).toBeTruthy();
|
|
370
|
+
// });
|
|
371
|
+
// });
|
|
372
|
+
//
|
|
373
|
+
// describe('Overriding model/state selector', () => {
|
|
374
|
+
// function testModelHasBeenReplacedWithMappedModel(expectedValue3) {
|
|
375
|
+
// let span = getSpanWithPropsAsAttributes();
|
|
376
|
+
// let mappedModel = props.model as any as MappedModel;
|
|
377
|
+
// expect(mappedModel.value2).toBe('initial-value');
|
|
378
|
+
// expect(mappedModel.value3).toBe(expectedValue3);
|
|
379
|
+
// publishAnEventToModel1();
|
|
380
|
+
// props = getSpanWithPropsAsAttributes();
|
|
381
|
+
// mappedModel = props.model as any as MappedModel;
|
|
382
|
+
// expect(mappedModel.value2).toBe('the-event-value');
|
|
383
|
+
// }
|
|
384
|
+
//
|
|
385
|
+
// function testSwappedModelPassedToMapModelToPropsFunction(expectedValue3) {
|
|
386
|
+
// let span = getSpanWithPropsAsAttributes();
|
|
387
|
+
// expect(props.value2).toBe('initial-value');
|
|
388
|
+
// expect(props.value3).toBe(expectedValue3);
|
|
389
|
+
// publishAnEventToModel1();
|
|
390
|
+
// props = getSpanWithPropsAsAttributes();
|
|
391
|
+
// expect(props.value2).toBe('the-event-value');
|
|
392
|
+
// }
|
|
393
|
+
//
|
|
394
|
+
// describe('using @stateToRenderSelector', () => {
|
|
395
|
+
// it('Swaps the model for that returned by the function decorated with a @stateToRenderSelector decorator', () => {
|
|
396
|
+
// setup({useConnectFunction: false, useImmutableModelSelectorDecorator: true});
|
|
397
|
+
// testModelHasBeenReplacedWithMappedModel('value-3');
|
|
398
|
+
// });
|
|
399
|
+
//
|
|
400
|
+
// it('passes the swapped model to mapModelToProps function', () => {
|
|
401
|
+
// setup({useConnectFunction: false, useImmutableModelSelectorDecorator: true, useMapModelToProps: true});
|
|
402
|
+
// testSwappedModelPassedToMapModelToPropsFunction('value-3');
|
|
403
|
+
// });
|
|
404
|
+
// });
|
|
405
|
+
//
|
|
406
|
+
// describe('using state to render function', () => {
|
|
407
|
+
// it('Swaps the model for that returned by the function decorated with a @stateToRenderSelector decorator', () => {
|
|
408
|
+
// setup({useConnectFunction: false, useImmutableModelSelectorFunction: true});
|
|
409
|
+
// testModelHasBeenReplacedWithMappedModel('value-3.1');
|
|
410
|
+
// });
|
|
411
|
+
//
|
|
412
|
+
// it('passes the swapped model to mapModelToProps function', () => {
|
|
413
|
+
// setup({useConnectFunction: false, useImmutableModelSelectorFunction: true, useMapModelToProps: true});
|
|
414
|
+
// testSwappedModelPassedToMapModelToPropsFunction('value-3.1');
|
|
415
|
+
// });
|
|
416
|
+
// });
|
|
417
|
+
// });
|
|
418
|
+
// });
|
|
419
|
+
});
|
package/tests/indexTests.ts
CHANGED
|
@@ -17,100 +17,34 @@
|
|
|
17
17
|
// notice_end
|
|
18
18
|
|
|
19
19
|
import * as espReact from '../src/index';
|
|
20
|
-
import {
|
|
21
|
-
ViewBinder,
|
|
22
|
-
viewBinding,
|
|
23
|
-
getEspReactRenderModel,
|
|
24
|
-
GetEspReactRenderModelConsts,
|
|
25
|
-
|
|
26
|
-
useRouter,
|
|
27
|
-
RouterContext,
|
|
28
|
-
RouterProvider,
|
|
29
|
-
|
|
30
|
-
useGetModelId,
|
|
31
|
-
GetModelIdContext,
|
|
32
|
-
|
|
33
|
-
PublishEventContext,
|
|
34
|
-
usePublishEvent,
|
|
35
|
-
|
|
36
|
-
PublishModelEventContext,
|
|
37
|
-
usePublishModelEvent,
|
|
38
|
-
|
|
39
|
-
PublishModelEventWithEntityKeyContext,
|
|
40
|
-
usePublishModelEventWithEntityKey,
|
|
41
|
-
} from '../src';
|
|
42
20
|
|
|
43
21
|
describe('index exports', () => {
|
|
44
|
-
it('
|
|
45
|
-
expect(espReact.RouterProvider).toBeDefined();
|
|
46
|
-
expect(RouterProvider).toBeDefined();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should export RouterContext', () => {
|
|
50
|
-
expect(espReact.RouterContext).toBeDefined();
|
|
51
|
-
expect(RouterContext).toBeDefined();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should export ViewBinder', () => {
|
|
22
|
+
it('check exports', () => {
|
|
55
23
|
expect(espReact.ViewBinder).toBeDefined();
|
|
56
|
-
expect(
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should export viewBinding', () => {
|
|
24
|
+
expect(espReact.ViewBinderConnectable).toBeDefined();
|
|
60
25
|
expect(espReact.viewBinding).toBeDefined();
|
|
61
|
-
expect(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
expect(espReact.
|
|
66
|
-
expect(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
expect(espReact.
|
|
71
|
-
expect(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
it('should export useGetModelId and related', () => {
|
|
85
|
-
expect(espReact.useGetModelId).toBeDefined();
|
|
86
|
-
expect(useGetModelId).toBeDefined();
|
|
87
|
-
|
|
88
|
-
expect(espReact.GetModelIdContext).toBeDefined();
|
|
89
|
-
expect(GetModelIdContext).toBeDefined();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should export usePublishEvent and related', () => {
|
|
93
|
-
expect(espReact.usePublishEvent).toBeDefined();
|
|
94
|
-
expect(usePublishEvent).toBeDefined();
|
|
95
|
-
|
|
96
|
-
expect(espReact.PublishEventContext).toBeDefined();
|
|
97
|
-
expect(PublishEventContext).toBeDefined();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('should export usePublishModelEvent and related', () => {
|
|
101
|
-
expect(espReact.usePublishModelEvent).toBeDefined();
|
|
102
|
-
expect(usePublishModelEvent).toBeDefined();
|
|
103
|
-
|
|
104
|
-
expect(espReact.PublishModelEventContext).toBeDefined();
|
|
105
|
-
expect(PublishModelEventContext).toBeDefined();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should export usePublishModelEventWithEntityKey and related', () => {
|
|
109
|
-
expect(espReact.usePublishModelEventWithEntityKey).toBeDefined();
|
|
110
|
-
expect(usePublishModelEventWithEntityKey).toBeDefined();
|
|
111
|
-
|
|
112
|
-
expect(espReact.PublishModelEventContext).toBeDefined();
|
|
113
|
-
expect(PublishModelEventWithEntityKeyContext).toBeDefined();
|
|
114
|
-
});
|
|
26
|
+
expect(espReact.DEFAULT_VIEW_KEY).toBeDefined();
|
|
27
|
+
expect(espReact.GetEspPolimerImmutableModelConsts).toBeDefined();
|
|
28
|
+
expect(espReact.getEspPolimerImmutableModel).toBeDefined();
|
|
29
|
+
expect(espReact.createViewForModel).toBeDefined();
|
|
30
|
+
expect(espReact.connect).toBeDefined();
|
|
31
|
+
expect(espReact.ConnectableComponent).toBeDefined();
|
|
32
|
+
expect(espReact.useModelSelector).toBeDefined();
|
|
33
|
+
expect(espReact.modelSelectorOptions).toBeDefined();
|
|
34
|
+
expect(espReact.RouterProvider).toBeDefined();
|
|
35
|
+
expect(espReact.EspRouterContextProvider).toBeDefined();
|
|
36
|
+
expect(espReact.RouterContext).toBeDefined();
|
|
37
|
+
expect(espReact.useRouter).toBeDefined();
|
|
38
|
+
expect(espReact.PublishEventContext).toBeDefined();
|
|
39
|
+
expect(espReact.usePublishEvent).toBeDefined();
|
|
40
|
+
expect(espReact.useGetModelId).toBeDefined();
|
|
41
|
+
expect(espReact.GetModelIdContext).toBeDefined();
|
|
42
|
+
expect(espReact.useGetModel).toBeDefined();
|
|
43
|
+
expect(espReact.GetModelContext).toBeDefined();
|
|
44
|
+
expect(espReact.PublishModelEventContext).toBeDefined();
|
|
45
|
+
expect(espReact.usePublishModelEvent).toBeDefined();
|
|
46
|
+
expect(espReact.PublishModelEventWithEntityKeyContext).toBeDefined();
|
|
47
|
+
expect(espReact.usePublishModelEventWithEntityKey).toBeDefined();
|
|
48
|
+
expect(espReact.EspModelContextProvider).toBeDefined();
|
|
115
49
|
});
|
|
116
50
|
});
|