esp-js-react 8.0.2-next.0 → 8.0.3-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 +41 -77
- 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/connect.d.ts +2 -6
- package/.dist/typings/connectableComponent.d.ts +0 -16
- package/.dist/typings/espModelContextProvider.d.ts +24 -7
- package/.dist/typings/espRouterContextProvider.d.ts +5 -5
- package/.dist/typings/index.d.ts +0 -1
- package/.dist/typings/useModelSelector.d.ts +25 -1
- package/.dist/typings/viewBinder.d.ts +8 -1
- package/.dist/typings/viewBindingDecorator.d.ts +1 -1
- package/package.json +4 -4
- package/src/connect.tsx +2 -6
- package/src/connectableComponent.tsx +0 -17
- package/src/espModelContextProvider.tsx +26 -9
- package/src/espRouterContextProvider.tsx +5 -5
- package/src/index.ts +0 -4
- package/src/useModelSelector.ts +29 -5
- package/src/viewBinder.tsx +13 -2
- package/src/viewBindingDecorator.ts +2 -2
- package/tests/connectableComponentTests.tsx +323 -246
- package/tests/espModelContextProviderTests.tsx +142 -0
- package/tests/espRouterContextProviderTests.tsx +54 -0
- package/tests/indexTests.ts +1 -2
- package/tests/testApi/asserts.ts +17 -2
- package/tests/testApi/testApi.tsx +37 -21
- package/tests/testApi/testModel.ts +15 -8
- package/tests/testApi/useStoreReceivedProps.ts +3 -0
- package/tests/testApi/viewFactory.tsx +31 -0
- package/tests/useModelSelectorTests.tsx +6 -8
- package/tests/viewBinderTests.tsx +61 -0
- package/.dist/typings/viewBinderConnectable.d.ts +0 -15
- package/src/viewBinderConnectable.tsx +0 -54
- package/tests/connectableComponentLegacyTests.tsx +0 -405
- package/tests/testApi/viewMetadata.tsx +0 -46
|
@@ -5,37 +5,16 @@ import {
|
|
|
5
5
|
connect,
|
|
6
6
|
ConnectableComponent,
|
|
7
7
|
ConnectableComponentProps,
|
|
8
|
-
EspRouterContextProvider,
|
|
9
8
|
getEspPolimerImmutableModel,
|
|
10
|
-
modelSelectorOptions,
|
|
11
9
|
PublishModelEventDelegate,
|
|
12
|
-
RouterContext,
|
|
13
|
-
useModelSelector,
|
|
14
10
|
viewBinding,
|
|
15
|
-
|
|
11
|
+
MapModelToProps,
|
|
12
|
+
CreatePublishEventProps,
|
|
13
|
+
GetEspPolimerImmutableModelConsts,
|
|
16
14
|
} from '../src';
|
|
17
|
-
import {TestModelImmutableState} from './testApi/testModel';
|
|
18
|
-
import {ViewMetadata} from './testApi/viewMetadata';
|
|
19
|
-
import {routerAsserts} from './testApi/asserts';
|
|
20
15
|
import {testApi, TestApi} from './testApi/testApi';
|
|
21
|
-
import {observeEvent
|
|
22
|
-
import {
|
|
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
|
-
};
|
|
16
|
+
import {observeEvent} from 'esp-js';
|
|
17
|
+
import {viewFactory} from './testApi/viewFactory';
|
|
39
18
|
|
|
40
19
|
interface MappedModel {
|
|
41
20
|
value: string;
|
|
@@ -43,8 +22,8 @@ interface MappedModel {
|
|
|
43
22
|
value3: string;
|
|
44
23
|
}
|
|
45
24
|
|
|
46
|
-
@viewBinding(
|
|
47
|
-
@viewBinding(
|
|
25
|
+
@viewBinding(viewFactory('View1'))
|
|
26
|
+
@viewBinding(viewFactory('View3'), 'alternative-view-context')
|
|
48
27
|
class TestModel {
|
|
49
28
|
public value: string;
|
|
50
29
|
|
|
@@ -73,13 +52,13 @@ class TestModel3 extends TestModel {
|
|
|
73
52
|
[GetEspPolimerImmutableModelConsts.HandlerFunctionName] = () => {
|
|
74
53
|
return {
|
|
75
54
|
value: this.value,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
} as MappedModel;
|
|
55
|
+
foo: 'the-foo'
|
|
56
|
+
};
|
|
79
57
|
};
|
|
80
58
|
}
|
|
81
59
|
|
|
82
|
-
interface
|
|
60
|
+
interface ConnectedComponentElementCreationProperties {
|
|
61
|
+
modelId: string;
|
|
83
62
|
useConnectFunction?: boolean;
|
|
84
63
|
useMapModelToProps?: boolean;
|
|
85
64
|
useCreatePublishEventProps?: boolean;
|
|
@@ -90,49 +69,37 @@ interface TestOptions {
|
|
|
90
69
|
}
|
|
91
70
|
|
|
92
71
|
describe('ConnectableComponentTests', () => {
|
|
93
|
-
let api: TestApi
|
|
94
|
-
let router,
|
|
72
|
+
let api: TestApi,
|
|
95
73
|
testModel: TestModel,
|
|
96
|
-
testModel2:
|
|
97
|
-
|
|
98
|
-
connectableComponentProps: ConnectableComponentProps<TestModel>,
|
|
99
|
-
mapModelToProps,
|
|
100
|
-
createPublishEventProps,
|
|
101
|
-
publishEventProps,
|
|
102
|
-
userAlternativeViewContext,
|
|
103
|
-
otherProps = {other1: 'other-value'};
|
|
74
|
+
testModel2: TestModel2,
|
|
75
|
+
testModel3: TestModel3;
|
|
104
76
|
|
|
105
77
|
beforeEach(() => {
|
|
106
78
|
api = testApi();
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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);
|
|
79
|
+
testModel = new TestModel();
|
|
80
|
+
testModel2 = new TestModel2();
|
|
81
|
+
testModel3 = new TestModel3();
|
|
82
|
+
api.setupModel('model-id1', testModel);
|
|
131
83
|
api.setupModel('model-id2', testModel2);
|
|
84
|
+
api.setupModel('model-id3', testModel3);
|
|
85
|
+
});
|
|
132
86
|
|
|
133
|
-
|
|
134
|
-
|
|
87
|
+
const createConnectedComponentElement = (options: ConnectedComponentElementCreationProperties): React.JSX.Element => {
|
|
88
|
+
// Refactor note:
|
|
89
|
+
// These tests were ported from some very old Enzime based tests.
|
|
90
|
+
// They have been cleaned up quite a bit.
|
|
91
|
+
// The next step in the cleanup would be to largely eliminate the option parameter.
|
|
92
|
+
// It makes sense to have a function that returns the thing to render,
|
|
93
|
+
// however, having an 'options' object just binds/funnels all the tests into one confusing API.
|
|
94
|
+
// It'd be best to take a Partial<ConnectableComponentProps> and have more localized `beforeEach` calls invoke function this using new structure.
|
|
95
|
+
let connectableComponentProps: ConnectableComponentProps<TestModel> = {
|
|
96
|
+
modelId: options.modelId
|
|
135
97
|
};
|
|
98
|
+
let mapModelToProps: MapModelToProps<any, any, any>;
|
|
99
|
+
let createPublishEventProps: CreatePublishEventProps<any>;
|
|
100
|
+
const otherProps = {other1: 'other-value'};
|
|
101
|
+
let publishEventProps: { publishEvent1: () => void };
|
|
102
|
+
let userAlternativeViewContext: string;
|
|
136
103
|
if (options.useMapModelToProps) {
|
|
137
104
|
mapModelToProps = (model: TestModel | MappedModel, publishEventProps2: any) => {
|
|
138
105
|
return {
|
|
@@ -157,7 +124,7 @@ describe('ConnectableComponentTests', () => {
|
|
|
157
124
|
const TestModelView2ConnectedComponent = connect(
|
|
158
125
|
mapModelToProps,
|
|
159
126
|
createPublishEventProps
|
|
160
|
-
)(
|
|
127
|
+
)(viewFactory('View2'));
|
|
161
128
|
viewElement = (<TestModelView2ConnectedComponent {...otherProps} {...connectableComponentProps}/>);
|
|
162
129
|
} else {
|
|
163
130
|
viewElement = (
|
|
@@ -169,26 +136,31 @@ describe('ConnectableComponentTests', () => {
|
|
|
169
136
|
/>
|
|
170
137
|
);
|
|
171
138
|
}
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function publishAnEventToModel1() {
|
|
176
|
-
router.publishEvent('model-id', 'test-event', 'the-event-value');
|
|
177
|
-
expect(testModel.value).toEqual('the-event-value');
|
|
178
|
-
}
|
|
139
|
+
return viewElement;
|
|
140
|
+
};
|
|
179
141
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
142
|
+
const publishTestEvent = (modelId: string, eventData: string) => {
|
|
143
|
+
act(() => {
|
|
144
|
+
api.router.publishEvent(modelId, 'test-event', eventData);
|
|
145
|
+
});
|
|
146
|
+
};
|
|
184
147
|
|
|
185
148
|
describe('ConnectableComponent via connect()', () => {
|
|
186
149
|
beforeEach(() => {
|
|
187
|
-
|
|
150
|
+
let elementCreationProperties: ConnectedComponentElementCreationProperties = {
|
|
151
|
+
modelId: 'model-id1',
|
|
152
|
+
useConnectFunction: true,
|
|
153
|
+
useMapModelToProps: true,
|
|
154
|
+
useCreatePublishEventProps: true
|
|
155
|
+
};
|
|
156
|
+
api.doRender(
|
|
157
|
+
createConnectedComponentElement(elementCreationProperties),
|
|
158
|
+
elementCreationProperties.modelId
|
|
159
|
+
);
|
|
188
160
|
});
|
|
189
161
|
|
|
190
|
-
it('
|
|
191
|
-
api.asserts.view.
|
|
162
|
+
it('Renders the view provided to connect', () => {
|
|
163
|
+
api.asserts.view.viewNameElementTextIs('View2');
|
|
192
164
|
});
|
|
193
165
|
|
|
194
166
|
describe('Child view props', () => {
|
|
@@ -252,168 +224,273 @@ describe('ConnectableComponentTests', () => {
|
|
|
252
224
|
);
|
|
253
225
|
});
|
|
254
226
|
});
|
|
255
|
-
//
|
|
256
|
-
// describe('View rendering', () => {
|
|
257
|
-
// it('Renders the view provided to connect', () => {
|
|
258
|
-
// expect(connectableComponentWrapper.containsMatchingElement(<TestModelView2/>)).toBeTruthy();
|
|
259
|
-
// });
|
|
260
|
-
// });
|
|
261
227
|
});
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
228
|
+
|
|
229
|
+
describe('ConnectableComponent directly', () => {
|
|
230
|
+
|
|
231
|
+
describe('Child view props', () => {
|
|
232
|
+
beforeEach(() => {
|
|
233
|
+
let elementCreationProperties: ConnectedComponentElementCreationProperties = {
|
|
234
|
+
modelId: 'model-id1',
|
|
235
|
+
useConnectFunction: false
|
|
236
|
+
};
|
|
237
|
+
api.doRender(
|
|
238
|
+
createConnectedComponentElement(elementCreationProperties),
|
|
239
|
+
elementCreationProperties.modelId
|
|
240
|
+
);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('passes modelId', () => {
|
|
244
|
+
api.asserts.props
|
|
245
|
+
.propAtIndex(
|
|
246
|
+
0,
|
|
247
|
+
props => {
|
|
248
|
+
expect(props.modelId).toBe('model-id1');
|
|
249
|
+
}
|
|
250
|
+
);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('passes router', () => {
|
|
254
|
+
api.asserts.props
|
|
255
|
+
.propAtIndex(
|
|
256
|
+
0,
|
|
257
|
+
props => {
|
|
258
|
+
expect(props.router).toBe(api.router);
|
|
259
|
+
}
|
|
260
|
+
);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('passes model', () => {
|
|
264
|
+
api.asserts.props
|
|
265
|
+
.propAtIndex(
|
|
266
|
+
0,
|
|
267
|
+
props => {
|
|
268
|
+
expect(props.model).toBeDefined();
|
|
269
|
+
expect(props.model instanceof TestModel).toBeTruthy();
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('passes other props', () => {
|
|
275
|
+
api.asserts.props
|
|
276
|
+
.propAtIndex(
|
|
277
|
+
0,
|
|
278
|
+
props => {
|
|
279
|
+
expect(props.other1).toBeDefined();
|
|
280
|
+
expect(props.other1).toBe('other-value');
|
|
281
|
+
}
|
|
282
|
+
);
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('arbitrary props are passed down to the child', () => {
|
|
287
|
+
api.doRender(
|
|
288
|
+
(
|
|
289
|
+
<ConnectableComponent className={'foo-bar'} />
|
|
290
|
+
),
|
|
291
|
+
'model-id1'
|
|
292
|
+
);
|
|
293
|
+
api.asserts.props
|
|
294
|
+
.receivedPropCountIs(1)
|
|
295
|
+
.propAtIndex(0, props => {
|
|
296
|
+
expect(props.className).toBe('foo-bar');
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
describe('Re-renders', () => {
|
|
301
|
+
beforeEach(() => {
|
|
302
|
+
let elementCreationProperties: ConnectedComponentElementCreationProperties = {
|
|
303
|
+
modelId: 'model-id1',
|
|
304
|
+
useConnectFunction: false,
|
|
305
|
+
};
|
|
306
|
+
api.doRender(
|
|
307
|
+
createConnectedComponentElement(elementCreationProperties),
|
|
308
|
+
elementCreationProperties.modelId
|
|
309
|
+
);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('Re-renders when model updates', () => {
|
|
313
|
+
publishTestEvent( 'model-id1', 'the-event-value');
|
|
314
|
+
api.asserts.props
|
|
315
|
+
.receivedPropCountIs(2)
|
|
316
|
+
.propAtIndex(
|
|
317
|
+
1,
|
|
318
|
+
props => {
|
|
319
|
+
expect(props.model).toBeDefined();
|
|
320
|
+
expect(props.model.value).toBe('the-event-value');
|
|
321
|
+
}
|
|
322
|
+
);
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
describe('Model Subscription - modelId source', () => {
|
|
327
|
+
it('subscribes to modelId via props', () => {
|
|
328
|
+
api.doRender(
|
|
329
|
+
(
|
|
330
|
+
<ConnectableComponent modelId={'model-id1'} />
|
|
331
|
+
)
|
|
332
|
+
);
|
|
333
|
+
api.asserts.props
|
|
334
|
+
.receivedPropCountIs(1)
|
|
335
|
+
.propAtIndexHasModelId(0, 'model-id1');
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('subscribes to modelId via context', () => {
|
|
339
|
+
api.doRender(
|
|
340
|
+
(
|
|
341
|
+
<ConnectableComponent />
|
|
342
|
+
),
|
|
343
|
+
'model-id1'
|
|
344
|
+
);
|
|
345
|
+
api.asserts.props
|
|
346
|
+
.receivedPropCountIs(1)
|
|
347
|
+
.propAtIndexHasModelId(0, 'model-id1');
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
describe('Model Subscription - when modelId changes', () => {
|
|
352
|
+
beforeEach(() => {
|
|
353
|
+
let elementCreationProperties: ConnectedComponentElementCreationProperties = {
|
|
354
|
+
modelId: 'model-id1',
|
|
355
|
+
useConnectFunction: false,
|
|
356
|
+
useMapModelToProps: true
|
|
357
|
+
};
|
|
358
|
+
api.doRender(
|
|
359
|
+
createConnectedComponentElement(elementCreationProperties),
|
|
360
|
+
elementCreationProperties.modelId
|
|
361
|
+
);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it('Re-subscribes to new model when modelId changes', () => {
|
|
365
|
+
api.asserts.props
|
|
366
|
+
.receivedPropCountIs(1)
|
|
367
|
+
.propAtIndexHasModelId(0,'model-id1');
|
|
368
|
+
const element = createConnectedComponentElement({modelId: 'model-id2', useConnectFunction: false, useMapModelToProps: true});
|
|
369
|
+
api.doReRender(element, 'model-id2');
|
|
370
|
+
api.asserts.props
|
|
371
|
+
.receivedPropCountIs(2)
|
|
372
|
+
.propAtIndexHasModelId(1,'model-id2');
|
|
373
|
+
publishTestEvent( 'model-id2', 'the-event-value2');
|
|
374
|
+
api.asserts.props
|
|
375
|
+
.receivedPropCountIs(3)
|
|
376
|
+
.propAtIndexHasModelId(2,'model-id2')
|
|
377
|
+
.propAtIndex(
|
|
378
|
+
2,
|
|
379
|
+
props => {
|
|
380
|
+
expect(props.model.value).toBe('the-event-value2');
|
|
381
|
+
expect(props.foo).toBe('the-event-value2');
|
|
382
|
+
}
|
|
383
|
+
);
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
describe('View rendering', () => {
|
|
388
|
+
it('Renders the view found via @viewBinding', () => {
|
|
389
|
+
let elementCreationProperties: ConnectedComponentElementCreationProperties = {
|
|
390
|
+
modelId: 'model-id1',
|
|
391
|
+
useConnectFunction: false,
|
|
392
|
+
};
|
|
393
|
+
api.doRender(
|
|
394
|
+
createConnectedComponentElement(elementCreationProperties),
|
|
395
|
+
elementCreationProperties.modelId
|
|
396
|
+
);
|
|
397
|
+
api.asserts.view.viewNameElementTextIs('View1');
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it('Renders alternative view found via @viewBinding', () => {
|
|
401
|
+
let elementCreationProperties: ConnectedComponentElementCreationProperties = {
|
|
402
|
+
modelId: 'model-id1',
|
|
403
|
+
useConnectFunction: false,
|
|
404
|
+
useAlternativeViewContext: true
|
|
405
|
+
};
|
|
406
|
+
api.doRender(
|
|
407
|
+
createConnectedComponentElement(elementCreationProperties),
|
|
408
|
+
elementCreationProperties.modelId
|
|
409
|
+
);
|
|
410
|
+
api.asserts.view.viewNameElementTextIs('View3');
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it('re-renders the view when the model changes', () => {
|
|
414
|
+
api.doRender(
|
|
415
|
+
(
|
|
416
|
+
<ConnectableComponent />
|
|
417
|
+
),
|
|
418
|
+
'model-id1'
|
|
419
|
+
);
|
|
420
|
+
api.asserts.view.viewNameElementTextIs('View1');
|
|
421
|
+
api.asserts.props.receivedPropCountIs(1);
|
|
422
|
+
act(() => {
|
|
423
|
+
api.router.publishEvent('model-id1', 'test-event', 'changed-value');
|
|
424
|
+
});
|
|
425
|
+
api.asserts.props
|
|
426
|
+
.receivedPropCountIs(2)
|
|
427
|
+
.propAtIndex(1, props => {
|
|
428
|
+
expect(props.model.value).toBe('changed-value');
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it('can pass view via prop', () => {
|
|
433
|
+
const View = viewFactory('MyPropView')
|
|
434
|
+
api.doRender(
|
|
435
|
+
(
|
|
436
|
+
<ConnectableComponent view={View} />
|
|
437
|
+
),
|
|
438
|
+
'model-id1'
|
|
439
|
+
);
|
|
440
|
+
api.asserts.view.viewNameElementTextIs('MyPropView');
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
describe('Overriding model/state selector with @getEspPolimerImmutableModel', () => {
|
|
445
|
+
it('The model returned by the function decorated with a @getEspPolimerImmutableModel decorator is passed to useMapModelToProps', () => {
|
|
446
|
+
let elementCreationProperties: ConnectedComponentElementCreationProperties = {
|
|
447
|
+
modelId: 'model-id2', // this model has a @getEspPolimerImmutableModel decorator
|
|
448
|
+
useConnectFunction: false,
|
|
449
|
+
useAlternativeViewContext: true
|
|
450
|
+
};
|
|
451
|
+
api.doRender(
|
|
452
|
+
createConnectedComponentElement(elementCreationProperties),
|
|
453
|
+
elementCreationProperties.modelId
|
|
454
|
+
);
|
|
455
|
+
api.asserts.props
|
|
456
|
+
.receivedPropCountIs(1)
|
|
457
|
+
.propAtIndex(0, props => {
|
|
458
|
+
const mappedModel = props.model as any as MappedModel;
|
|
459
|
+
expect(mappedModel.value2).toBe('initial-value');
|
|
460
|
+
expect(mappedModel.value3).toBe('value-3');
|
|
461
|
+
});
|
|
462
|
+
publishTestEvent(elementCreationProperties.modelId, 'the-event-value');
|
|
463
|
+
api.asserts.props
|
|
464
|
+
.receivedPropCountIs(2)
|
|
465
|
+
.propAtIndex(1, props => {
|
|
466
|
+
const mappedModel = props.model as any as MappedModel;
|
|
467
|
+
expect(mappedModel.value2).toBe('the-event-value');
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
it('will select esp-js-polimer model based on const', () => {
|
|
472
|
+
api.doRender(
|
|
473
|
+
(
|
|
474
|
+
<ConnectableComponent />
|
|
475
|
+
),
|
|
476
|
+
'model-id3'
|
|
477
|
+
);
|
|
478
|
+
api.asserts.props
|
|
479
|
+
.receivedPropCountIs(1)
|
|
480
|
+
.propAtIndex(0, props => {
|
|
481
|
+
expect(props.model.value).toBe('initial-value');
|
|
482
|
+
expect(props.model.foo).toBe('the-foo');
|
|
483
|
+
});
|
|
484
|
+
act(() => {
|
|
485
|
+
api.router.publishEvent('model-id3', 'test-event', 'changed-value');
|
|
486
|
+
});
|
|
487
|
+
api.asserts.props
|
|
488
|
+
.receivedPropCountIs(2)
|
|
489
|
+
.propAtIndex(1, props => {
|
|
490
|
+
expect(props.model.value).toBe('changed-value');
|
|
491
|
+
expect(props.model.foo).toBe('the-foo');
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
});
|
|
419
496
|
});
|