@gogocat/data-bind 1.11.0 → 2.0.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/.editorconfig +14 -14
- package/.vscode/launch.json +12 -12
- package/CONFIGURATION.md +294 -0
- package/REACTIVE_MODE.md +553 -0
- package/README.md +266 -829
- package/babel.config.json +30 -0
- package/dist/js/_escape.d.ts +14 -0
- package/dist/js/_escape.d.ts.map +1 -0
- package/dist/js/applyBinding.d.ts +11 -0
- package/dist/js/applyBinding.d.ts.map +1 -0
- package/dist/js/attrBinding.d.ts +12 -0
- package/dist/js/attrBinding.d.ts.map +1 -0
- package/dist/js/binder.d.ts +67 -0
- package/dist/js/binder.d.ts.map +1 -0
- package/dist/js/changeBinding.d.ts +19 -0
- package/dist/js/changeBinding.d.ts.map +1 -0
- package/dist/js/commentWrapper.d.ts +39 -0
- package/dist/js/commentWrapper.d.ts.map +1 -0
- package/dist/js/config.d.ts +55 -0
- package/dist/js/config.d.ts.map +1 -0
- package/dist/js/createBindingOption.d.ts +32 -0
- package/dist/js/createBindingOption.d.ts.map +1 -0
- package/dist/js/createEventBinding.d.ts +10 -0
- package/dist/js/createEventBinding.d.ts.map +1 -0
- package/dist/js/cssBinding.d.ts +15 -0
- package/dist/js/cssBinding.d.ts.map +1 -0
- package/dist/js/dataBind.js +2772 -2519
- package/dist/js/dataBind.min.js +8 -1
- package/dist/js/dataBind.min.js.map +1 -1
- package/dist/js/domWalker.d.ts +9 -0
- package/dist/js/domWalker.d.ts.map +1 -0
- package/dist/js/forOfBinding.d.ts +12 -0
- package/dist/js/forOfBinding.d.ts.map +1 -0
- package/dist/js/hoverBinding.d.ts +13 -0
- package/dist/js/hoverBinding.d.ts.map +1 -0
- package/dist/js/ifBinding.d.ts +12 -0
- package/dist/js/ifBinding.d.ts.map +1 -0
- package/dist/js/index.d.ts +10 -0
- package/dist/js/index.d.ts.map +1 -0
- package/dist/js/modelBinding.d.ts +12 -0
- package/dist/js/modelBinding.d.ts.map +1 -0
- package/dist/js/postProcess.d.ts +3 -0
- package/dist/js/postProcess.d.ts.map +1 -0
- package/dist/js/pubSub.d.ts +11 -0
- package/dist/js/pubSub.d.ts.map +1 -0
- package/dist/js/reactiveProxy.d.ts +28 -0
- package/dist/js/reactiveProxy.d.ts.map +1 -0
- package/dist/js/renderForOfBinding.d.ts +8 -0
- package/dist/js/renderForOfBinding.d.ts.map +1 -0
- package/dist/js/renderIfBinding.d.ts +22 -0
- package/dist/js/renderIfBinding.d.ts.map +1 -0
- package/dist/js/renderIteration.d.ts +16 -0
- package/dist/js/renderIteration.d.ts.map +1 -0
- package/dist/js/renderTemplate.d.ts +14 -0
- package/dist/js/renderTemplate.d.ts.map +1 -0
- package/dist/js/renderTemplatesBinding.d.ts +19 -0
- package/dist/js/renderTemplatesBinding.d.ts.map +1 -0
- package/dist/js/showBinding.d.ts +13 -0
- package/dist/js/showBinding.d.ts.map +1 -0
- package/dist/js/switchBinding.d.ts +13 -0
- package/dist/js/switchBinding.d.ts.map +1 -0
- package/dist/js/textBinding.d.ts +13 -0
- package/dist/js/textBinding.d.ts.map +1 -0
- package/dist/js/types/_escape.d.ts +14 -0
- package/dist/js/types/_escape.d.ts.map +1 -0
- package/dist/js/types/applyBinding.d.ts +11 -0
- package/dist/js/types/applyBinding.d.ts.map +1 -0
- package/dist/js/types/attrBinding.d.ts +12 -0
- package/dist/js/types/attrBinding.d.ts.map +1 -0
- package/dist/js/types/binder.d.ts +67 -0
- package/dist/js/types/binder.d.ts.map +1 -0
- package/dist/js/types/changeBinding.d.ts +19 -0
- package/dist/js/types/changeBinding.d.ts.map +1 -0
- package/dist/js/types/commentWrapper.d.ts +39 -0
- package/dist/js/types/commentWrapper.d.ts.map +1 -0
- package/dist/js/types/config.d.ts +55 -0
- package/dist/js/types/config.d.ts.map +1 -0
- package/dist/js/types/createBindingOption.d.ts +32 -0
- package/dist/js/types/createBindingOption.d.ts.map +1 -0
- package/dist/js/types/createEventBinding.d.ts +10 -0
- package/dist/js/types/createEventBinding.d.ts.map +1 -0
- package/dist/js/types/cssBinding.d.ts +15 -0
- package/dist/js/types/cssBinding.d.ts.map +1 -0
- package/dist/js/types/domWalker.d.ts +9 -0
- package/dist/js/types/domWalker.d.ts.map +1 -0
- package/dist/js/types/forOfBinding.d.ts +12 -0
- package/dist/js/types/forOfBinding.d.ts.map +1 -0
- package/dist/js/types/hoverBinding.d.ts +13 -0
- package/dist/js/types/hoverBinding.d.ts.map +1 -0
- package/dist/js/types/ifBinding.d.ts +12 -0
- package/dist/js/types/ifBinding.d.ts.map +1 -0
- package/dist/js/types/index.d.ts +10 -0
- package/dist/js/types/index.d.ts.map +1 -0
- package/dist/js/types/modelBinding.d.ts +12 -0
- package/dist/js/types/modelBinding.d.ts.map +1 -0
- package/dist/js/types/postProcess.d.ts +3 -0
- package/dist/js/types/postProcess.d.ts.map +1 -0
- package/dist/js/types/pubSub.d.ts +11 -0
- package/dist/js/types/pubSub.d.ts.map +1 -0
- package/dist/js/types/reactiveProxy.d.ts +28 -0
- package/dist/js/types/reactiveProxy.d.ts.map +1 -0
- package/dist/js/types/renderForOfBinding.d.ts +8 -0
- package/dist/js/types/renderForOfBinding.d.ts.map +1 -0
- package/dist/js/types/renderIfBinding.d.ts +22 -0
- package/dist/js/types/renderIfBinding.d.ts.map +1 -0
- package/dist/js/types/renderIteration.d.ts +16 -0
- package/dist/js/types/renderIteration.d.ts.map +1 -0
- package/dist/js/types/renderTemplate.d.ts +14 -0
- package/dist/js/types/renderTemplate.d.ts.map +1 -0
- package/dist/js/types/renderTemplatesBinding.d.ts +19 -0
- package/dist/js/types/renderTemplatesBinding.d.ts.map +1 -0
- package/dist/js/types/showBinding.d.ts +13 -0
- package/dist/js/types/showBinding.d.ts.map +1 -0
- package/dist/js/types/switchBinding.d.ts +13 -0
- package/dist/js/types/switchBinding.d.ts.map +1 -0
- package/dist/js/types/textBinding.d.ts +13 -0
- package/dist/js/types/textBinding.d.ts.map +1 -0
- package/dist/js/types/types.d.ts +111 -0
- package/dist/js/types/types.d.ts.map +1 -0
- package/dist/js/types/util.d.ts +119 -0
- package/dist/js/types/util.d.ts.map +1 -0
- package/dist/js/types.d.ts +111 -0
- package/dist/js/types.d.ts.map +1 -0
- package/dist/js/util.d.ts +119 -0
- package/dist/js/util.d.ts.map +1 -0
- package/eslint.config.js +124 -0
- package/examples/DBMONSTER_COMPARISON.md +123 -0
- package/examples/afterRenderDemo.html +119 -0
- package/examples/bootstrap/css/animate.css +1579 -1579
- package/examples/bootstrap/css/bootstrap.min.css +6 -6
- package/examples/bootstrap/css/homeservices.css +378 -390
- package/examples/bootstrap/css/open-iconic.css +511 -511
- package/examples/bootstrap/fonts/open-iconic.svg +543 -543
- package/examples/bootstrap/js/compMessageDialog.js +20 -19
- package/examples/bootstrap/js/compSearchBar.js +12 -19
- package/examples/bootstrap/js/compSearchResults.js +50 -46
- package/examples/bootstrap/js/featureAdsResult.json +65 -65
- package/examples/bootstrap/js/searchResult.json +57 -57
- package/examples/bootstrap.html +343 -332
- package/examples/css/baseTodo.css +141 -141
- package/examples/css/dbMonsterStyles.css +27 -27
- package/examples/css/indexTodo.css +374 -374
- package/examples/dbmonsterForOfReactive.html +40 -0
- package/examples/dbmonsterReact.html +19 -0
- package/examples/forOfBindingSimpleDebug.html +45 -0
- package/examples/form.html +20 -4
- package/examples/globalConfig.html +131 -0
- package/examples/js/afterRenderDemo.js +190 -0
- package/examples/js/appTodo.js +46 -46
- package/examples/js/attrBindingDemo.js +2 -2
- package/examples/js/dbMonApp.js +24 -26
- package/examples/js/dbMonAppReact.jsx +79 -0
- package/examples/js/dbMonAppReactive.js +28 -0
- package/examples/js/fiberDemo.js +4 -4
- package/examples/js/filtersDemo.js +8 -8
- package/examples/js/forOfDemo.js +7 -9
- package/examples/js/forOfDemoComplex.js +44 -17
- package/examples/js/form.js +44 -12
- package/examples/js/globalConfig.js +117 -0
- package/examples/js/ifBindingDemo.js +16 -16
- package/examples/js/reactiveDemo.js +119 -0
- package/examples/js/switchBindingDemo.js +8 -8
- package/examples/react-dbmonster/dist/bundle.js +43 -0
- package/examples/react-dbmonster/package-lock.json +537 -0
- package/examples/react-dbmonster/package.json +16 -0
- package/examples/react-dbmonster/src/index.jsx +80 -0
- package/examples/reactiveDemo.html +127 -0
- package/examples/refreshRateTest.html +75 -75
- package/index.html +841 -0
- package/package.json +31 -34
- package/rollup.config.js +79 -36
- package/src/{_escape.js → _escape.ts} +19 -17
- package/src/applyBinding.ts +179 -0
- package/src/{attrBinding.js → attrBinding.ts} +14 -13
- package/src/binder.ts +289 -0
- package/src/changeBinding.ts +93 -0
- package/src/{commentWrapper.js → commentWrapper.ts} +33 -30
- package/src/config.ts +107 -0
- package/src/createBindingOption.ts +91 -0
- package/src/createEventBinding.ts +88 -0
- package/src/{cssBinding.js → cssBinding.ts} +13 -11
- package/src/{domWalker.js → domWalker.ts} +44 -30
- package/src/{forOfBinding.js → forOfBinding.ts} +4 -3
- package/src/hoverBinding.ts +84 -0
- package/src/{ifBinding.js → ifBinding.ts} +14 -12
- package/src/index.ts +53 -0
- package/src/{modelBinding.js → modelBinding.ts} +11 -9
- package/src/postProcess.ts +22 -0
- package/src/{pubSub.js → pubSub.ts} +24 -15
- package/src/reactiveProxy.ts +285 -0
- package/src/{renderForOfBinding.js → renderForOfBinding.ts} +55 -33
- package/src/{renderIfBinding.js → renderIfBinding.ts} +45 -20
- package/src/renderIteration.ts +53 -0
- package/src/renderTemplate.ts +165 -0
- package/src/renderTemplatesBinding.ts +73 -0
- package/src/{showBinding.js → showBinding.ts} +4 -3
- package/src/{switchBinding.js → switchBinding.ts} +18 -15
- package/src/{textBinding.js → textBinding.ts} +5 -4
- package/src/types.ts +124 -0
- package/src/util.ts +810 -0
- package/test/css/reporter.css +9 -9
- package/test/fixtures/dataBindBootstrap.html +2 -2
- package/test/fixtures/formBindings.html +9 -1
- package/test/globals.d.ts +19 -0
- package/test/helpers/testHelper.js +46 -11
- package/test/mocks/featureAdsResult.json +65 -65
- package/test/mocks/searchResult.json +57 -57
- package/test/specs/{attrBinding.spec.js → attrBinding.spec.ts} +103 -106
- package/test/specs/{binder.spec.js → binder.spec.ts} +29 -27
- package/test/specs/blurBinding.spec.ts +60 -0
- package/test/specs/chainableUse.spec.ts +125 -0
- package/test/specs/clickBinding.spec.ts +194 -0
- package/test/specs/{cssBinding.spec.js → cssBinding.spec.ts} +72 -79
- package/test/specs/{dataBindBootstrap.spec.js → dataBindBootstrap.spec.ts} +332 -313
- package/test/specs/{filter.spec.js → filter.spec.ts} +75 -76
- package/test/specs/{forOfBinding.spec.js → forOfBinding.spec.ts} +208 -219
- package/test/specs/formBinding.spec.ts +272 -0
- package/test/specs/ifBinding.spec.ts +165 -0
- package/test/specs/{nestedComponent.spec.js → nestedComponent.spec.ts} +88 -88
- package/test/specs/reactiveProxy.spec.ts +465 -0
- package/test/specs/{showBinding.spec.js → showBinding.spec.ts} +148 -149
- package/test/specs/{switchBinding.spec.js → switchBinding.spec.ts} +172 -173
- package/test/specs/templateBinding.spec.ts +273 -0
- package/test/specs/{textBinding.spec.js → textBinding.spec.ts} +47 -48
- package/test/tsconfig.json +31 -0
- package/test-output.txt +200 -0
- package/test-reactive.html +224 -0
- package/tsconfig.json +28 -0
- package/vendors/lodash.custom.js +4577 -4577
- package/vendors/lodash.custom.min.js +45 -45
- package/vitest.config.js +27 -0
- package/.eslintrc.js +0 -1
- package/.grunt/grunt-contrib-jasmine/boot.js +0 -161
- package/.grunt/grunt-contrib-jasmine/dist/js/dataBind.js +0 -9
- package/.grunt/grunt-contrib-jasmine/grunt-template-jasmine-istanbul/reporter.js +0 -23
- package/.grunt/grunt-contrib-jasmine/jasmine-html.js +0 -853
- package/.grunt/grunt-contrib-jasmine/jasmine.css +0 -271
- package/.grunt/grunt-contrib-jasmine/jasmine.js +0 -9761
- package/.grunt/grunt-contrib-jasmine/jasmine_favicon.png +0 -0
- package/.grunt/grunt-contrib-jasmine/json2.js +0 -489
- package/.grunt/grunt-contrib-jasmine/reporter.js +0 -107
- package/coverage/coverage.json +0 -1
- package/coverage/lcov/lcov-report/base.css +0 -213
- package/coverage/lcov/lcov-report/index.html +0 -93
- package/coverage/lcov/lcov-report/js/dataBind.js.html +0 -6596
- package/coverage/lcov/lcov-report/js/index.html +0 -93
- package/coverage/lcov/lcov-report/prettify.css +0 -1
- package/coverage/lcov/lcov-report/prettify.js +0 -1
- package/coverage/lcov/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov/lcov-report/sorter.js +0 -158
- package/coverage/lcov/lcov.info +0 -1991
- package/eslintrc.json +0 -40
- package/examples/bootstrap/js/bootstrap.min.js +0 -6
- package/examples/bootstrap/js/popper.min.js +0 -5
- package/examples/bootstrap/js/searchSuggestion.js +0 -58
- package/examples/bootstrap/js/typeahead.jquery.js +0 -1538
- package/gruntfile.js +0 -92
- package/gulpfile.js +0 -32
- package/src/binder.js +0 -422
- package/src/changeBinding.js +0 -57
- package/src/config.js +0 -65
- package/src/createBindingOption.js +0 -66
- package/src/createEventBinding.js +0 -46
- package/src/eventSystem.js +0 -46
- package/src/hoverBinding.js +0 -57
- package/src/index.js +0 -26
- package/src/renderTemplate.js +0 -128
- package/src/util.js +0 -648
- package/test/specs/blurBinding.spec.js +0 -57
- package/test/specs/formBinding.spec.js +0 -292
- package/test/specs/ifBinding.spec.js +0 -169
- package/test/specs/templateBinding.spec.js +0 -117
- package/vendors/jasmine-jquery.js +0 -841
- package/vendors/jquery-3.2.1.min.js +0 -4
|
@@ -1,313 +1,332 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
if (newItem.
|
|
12
|
-
newItem.
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
expect(
|
|
48
|
-
expect(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
expect(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
formData
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this.searching =
|
|
67
|
-
this.updateStatus();
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
self
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
},
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
this.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
this.
|
|
189
|
-
this.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
this.
|
|
194
|
-
this.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
expect(namespace.searchBarComponentVM.
|
|
301
|
-
expect(namespace.searchBarComponentVM.
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
},
|
|
312
|
-
|
|
313
|
-
|
|
1
|
+
import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
|
|
2
|
+
import {waitFor} from '@testing-library/dom';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
describe('Given dataBindBootstrp initised', () => {
|
|
6
|
+
const namespace: any = {};
|
|
7
|
+
const converResultsData = function (data: any[]) {
|
|
8
|
+
const ret: any[] = [];
|
|
9
|
+
data.forEach((item, _index) => {
|
|
10
|
+
const newItem = Object.assign({}, item);
|
|
11
|
+
if (newItem.bookmarked) {
|
|
12
|
+
newItem.bookmarkedCss = 'active';
|
|
13
|
+
}
|
|
14
|
+
if (newItem.highlight) {
|
|
15
|
+
newItem.highlightCss = 'result-item--highlight';
|
|
16
|
+
}
|
|
17
|
+
ret.push(newItem);
|
|
18
|
+
});
|
|
19
|
+
return ret;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
beforeEach(async () => {
|
|
23
|
+
const searchUrl = '/test/mocks/searchResult.json';
|
|
24
|
+
// var featureAdsResultUrl = '/test/mocks/featureAdsResult.json';
|
|
25
|
+
const el: any = {
|
|
26
|
+
searchResultColumns: '#search-result-columns',
|
|
27
|
+
messageModal: '#message-modal',
|
|
28
|
+
messageTextArea: '#message',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
loadFixture('test/fixtures/dataBindBootstrap.html');
|
|
32
|
+
|
|
33
|
+
for (const k in el) {
|
|
34
|
+
if (Object.prototype.hasOwnProperty.call(el, k)) {
|
|
35
|
+
const v = el[k];
|
|
36
|
+
el[k] = document.querySelector(v);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
namespace.searchBarComponentVM = {
|
|
41
|
+
searchWord: '',
|
|
42
|
+
searchLocation: '',
|
|
43
|
+
searching: false,
|
|
44
|
+
onSearchWordChange(e: Event, $el: any, newValue: any, oldValue: any) {
|
|
45
|
+
console.log('onSearchWordChange');
|
|
46
|
+
expect(typeof e.preventDefault).toBe('function');
|
|
47
|
+
expect($el instanceof HTMLElement || $el instanceof Element).toBe(true);
|
|
48
|
+
expect(newValue).not.toBe(oldValue);
|
|
49
|
+
},
|
|
50
|
+
onSearchLocationChange(e: Event, $el: any, newValue: any, oldValue: any) {
|
|
51
|
+
expect(typeof e.preventDefault).toBe('function');
|
|
52
|
+
expect($el instanceof HTMLElement || $el instanceof Element).toBe(true);
|
|
53
|
+
expect(newValue).not.toBe(oldValue);
|
|
54
|
+
},
|
|
55
|
+
onSearchSubmit(e: Event, $form: any, formData: any) {
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
expect($form instanceof HTMLElement || $form instanceof Element).toBe(true);
|
|
58
|
+
expect($form.tagName).toBe('FORM');
|
|
59
|
+
expect(typeof formData === 'object' && formData !== null).toBe(true);
|
|
60
|
+
|
|
61
|
+
// TODO: may be test publish even elsewhere
|
|
62
|
+
formData.searchWord = formData.searchWord.trim();
|
|
63
|
+
formData.location = formData.location.trim();
|
|
64
|
+
namespace.searchBarComponent.publish('SEARCH-AD', formData);
|
|
65
|
+
|
|
66
|
+
this.searching = true;
|
|
67
|
+
this.updateStatus();
|
|
68
|
+
},
|
|
69
|
+
onSearchCompleted() {
|
|
70
|
+
this.searching = false;
|
|
71
|
+
this.updateStatus();
|
|
72
|
+
},
|
|
73
|
+
updateStatus() {
|
|
74
|
+
namespace.searchBarComponent.render();
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
namespace.searchResultsComponentVM = {
|
|
79
|
+
searchResultTitle: 'Featured service providers',
|
|
80
|
+
messageTriggerCss: '',
|
|
81
|
+
bookmarkCss: '',
|
|
82
|
+
searchResults: [],
|
|
83
|
+
selectedResults: [],
|
|
84
|
+
startIndex: -1,
|
|
85
|
+
loading: false,
|
|
86
|
+
showMore: false,
|
|
87
|
+
replacedInitResults: false,
|
|
88
|
+
isNewSearch: false,
|
|
89
|
+
currentQuery: null,
|
|
90
|
+
getSearchResults(formData?: any) {
|
|
91
|
+
const self = this;
|
|
92
|
+
|
|
93
|
+
this.isNewSearch = JSON.stringify(self.currentQuery) !== JSON.stringify(formData);
|
|
94
|
+
|
|
95
|
+
self.currentQuery = formData;
|
|
96
|
+
|
|
97
|
+
// Note: $ is jQuery, used in test fixture
|
|
98
|
+
|
|
99
|
+
$.getJSON(searchUrl, self.currentQuery)
|
|
100
|
+
.done((data: any) => {
|
|
101
|
+
// mock network delay
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
self.loading = false;
|
|
104
|
+
self.onSearchResult(data);
|
|
105
|
+
namespace.searchResultsComponent.publish('SEARCH-COMPLETED', data);
|
|
106
|
+
}, 20);
|
|
107
|
+
})
|
|
108
|
+
.fail(function (jqXHR: any, textStatus: any, errorThrown: any) {
|
|
109
|
+
this.loading = false;
|
|
110
|
+
namespace.searchResultsComponent.publish('SEARCH-COMPLETED', {
|
|
111
|
+
fail: errorThrown,
|
|
112
|
+
});
|
|
113
|
+
self.logError(jqXHR, textStatus, errorThrown);
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
onSearchResult(data: any) {
|
|
117
|
+
let newResults = [];
|
|
118
|
+
|
|
119
|
+
if (this.isNewSearch) {
|
|
120
|
+
el.searchResultColumns.empty();
|
|
121
|
+
this.searchResults.length = 0;
|
|
122
|
+
}
|
|
123
|
+
// first search result - remove current results (featured items)
|
|
124
|
+
if (namespace.searchResultsComponent.isServerRendered && !this.replacedInitResults) {
|
|
125
|
+
this.searchResultTitle = 'Search results';
|
|
126
|
+
this.replacedInitResults = true;
|
|
127
|
+
} else {
|
|
128
|
+
// using append template logic - results will be append into existing results
|
|
129
|
+
// mark startIndex using current last item index
|
|
130
|
+
this.startIndex = this.searchResults.length - 1;
|
|
131
|
+
}
|
|
132
|
+
// covert raw data to searchResults view data
|
|
133
|
+
newResults = converResultsData(data);
|
|
134
|
+
// add new results into current searchResults
|
|
135
|
+
this.searchResults = this.searchResults.concat(newResults);
|
|
136
|
+
// flag display showMore button
|
|
137
|
+
this.showMore = true;
|
|
138
|
+
// update template which use startIndex to append new content
|
|
139
|
+
this.updateStatus({
|
|
140
|
+
templateBinding: true,
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
logError(...args: any[]) {
|
|
144
|
+
console.warn('search result error: ', ...args);
|
|
145
|
+
},
|
|
146
|
+
onMoreResults() {
|
|
147
|
+
// get same mock result as example only
|
|
148
|
+
this.loading = true;
|
|
149
|
+
this.updateStatus();
|
|
150
|
+
this.getSearchResults();
|
|
151
|
+
},
|
|
152
|
+
onAdBookmarkClick(e: Event, $el: any) {
|
|
153
|
+
const activeCss = 'active';
|
|
154
|
+
const isActivated = $el.hasClass(activeCss);
|
|
155
|
+
const resultIndex = $el.getAttribute('data-index');
|
|
156
|
+
|
|
157
|
+
this.searchResults[resultIndex].bookmarked = !isActivated;
|
|
158
|
+
this.searchResults[resultIndex].bookmarkedCss = isActivated ? '' : 'active';
|
|
159
|
+
this.updateStatus();
|
|
160
|
+
},
|
|
161
|
+
onAdMessageCheck(e: Event, $el: any, newValue: any, oldValue: any) {
|
|
162
|
+
expect(newValue).not.toBe(oldValue);
|
|
163
|
+
this.updateStatus();
|
|
164
|
+
},
|
|
165
|
+
onMessageTriggerClick(e: Event, $el: any) {
|
|
166
|
+
namespace.searchResultsComponent.publish('TRIGGER-MESSAGE-DIALOG', this.selectedResults);
|
|
167
|
+
console.log('onMessageTriggerClick: ', $el);
|
|
168
|
+
},
|
|
169
|
+
updateStatus(opt?: any) {
|
|
170
|
+
this.selectedResults = this.searchResults.filter((result: any, _index: number) => {
|
|
171
|
+
return result.selected;
|
|
172
|
+
});
|
|
173
|
+
this.messageTriggerCss = this.selectedResults.length ? 'show' : '';
|
|
174
|
+
namespace.searchResultsComponent.render(opt);
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
namespace.messageDialogComponentVM = {
|
|
179
|
+
numSelectedProviders: '',
|
|
180
|
+
selectedAdData: [],
|
|
181
|
+
adIds: [],
|
|
182
|
+
selectedProviders: '',
|
|
183
|
+
defaultMessageText: 'Hi,\nCould you please provide a quote for the following work:\n',
|
|
184
|
+
sendingMessage: false,
|
|
185
|
+
onMessageSubmit(e: Event, $el: any, formData: any) {
|
|
186
|
+
e.preventDefault();
|
|
187
|
+
formData.ids = this.adIds;
|
|
188
|
+
this.sendingMessage = true;
|
|
189
|
+
this.updateStatus();
|
|
190
|
+
console.log('post data: ', formData);
|
|
191
|
+
},
|
|
192
|
+
onTriggerSelectedAds(selectedAdData: any[]) {
|
|
193
|
+
this.selectedAdData = selectedAdData;
|
|
194
|
+
this.numSelectedProviders = selectedAdData.length > 1 ? selectedAdData.length : '';
|
|
195
|
+
this.selectedProviders = selectedAdData.length > 1 ? 'advertisers ID: ' : 'advertiser ID:';
|
|
196
|
+
this.adIds = selectedAdData.map((item, _index) => {
|
|
197
|
+
return item.id;
|
|
198
|
+
});
|
|
199
|
+
this.selectedProviders += this.adIds.toString();
|
|
200
|
+
this.updateStatus();
|
|
201
|
+
},
|
|
202
|
+
updateStatus() {
|
|
203
|
+
namespace.messageDialogComponent.render();
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// vitest spies - set up BEFORE render so they intercept the event handlers
|
|
208
|
+
vi.spyOn(namespace.searchBarComponentVM, 'onSearchWordChange');
|
|
209
|
+
vi.spyOn(namespace.searchBarComponentVM, 'onSearchLocationChange');
|
|
210
|
+
// vi.spyOn(namespace.searchBarComponentVM, 'onSearchSubmit');
|
|
211
|
+
|
|
212
|
+
namespace.searchBarComponent = dataBind.init(document.querySelector('[data-bind-comp="search-bar"]'), namespace.searchBarComponentVM);
|
|
213
|
+
await namespace.searchBarComponent.render().then((ctx: any) => {
|
|
214
|
+
const self = ctx;
|
|
215
|
+
namespace.searchBarComponent.subscribe('SEARCH-COMPLETED', self.viewModel.onSearchCompleted);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
namespace.searchResultsComponent = dataBind.init(
|
|
219
|
+
document.querySelector('[data-bind-comp="search-results-component"]'),
|
|
220
|
+
namespace.searchResultsComponentVM,
|
|
221
|
+
);
|
|
222
|
+
await namespace.searchResultsComponent
|
|
223
|
+
.render() // overwrite default server rendered option
|
|
224
|
+
.then((ctx: any) => {
|
|
225
|
+
const self = ctx;
|
|
226
|
+
// subscribe events
|
|
227
|
+
namespace.searchResultsComponent.subscribe('SEARCH-AD', self.viewModel.getSearchResults);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
namespace.messageDialogComponent = dataBind.init(
|
|
231
|
+
document.querySelector('[data-bind-comp="message-dialog-component"]'),
|
|
232
|
+
namespace.messageDialogComponentVM,
|
|
233
|
+
);
|
|
234
|
+
await namespace.messageDialogComponent.render().then((ctx: any) => {
|
|
235
|
+
const self = ctx;
|
|
236
|
+
namespace.messageDialogComponent.subscribe('TRIGGER-MESSAGE-DIALOG', self.viewModel.onTriggerSelectedAds);
|
|
237
|
+
|
|
238
|
+
if (el.messageModal) {
|
|
239
|
+
el.messageModal.addEventListener('shown.bs.modal', () => {
|
|
240
|
+
if (el.messageTextArea) {
|
|
241
|
+
el.messageTextArea.defaultValue = self.viewModel.defaultMessageText;
|
|
242
|
+
el.messageTextArea.focus();
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
el.messageModal.addEventListener('hidden.bs.modal', () => {
|
|
247
|
+
if (el.messageTextArea) {
|
|
248
|
+
el.messageTextArea.defaultValue = self.viewModel.defaultMessageText;
|
|
249
|
+
self.viewModel.sendingMessage = false;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
afterEach(() => {
|
|
257
|
+
// clean up all app/components
|
|
258
|
+
for (const prop in namespace) {
|
|
259
|
+
if (Object.prototype.hasOwnProperty.call(namespace, prop)) {
|
|
260
|
+
delete namespace[prop];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
vi.restoreAllMocks();
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('Then [data-bind-comp="search-bar"] should has bond with namespace.searchBarComponentVM', async () => {
|
|
267
|
+
const $searchBar = document.querySelector('[data-bind-comp="search-bar"]') as any;
|
|
268
|
+
const searchBarRoot = $searchBar['$root'];
|
|
269
|
+
|
|
270
|
+
await waitFor(() => {
|
|
271
|
+
expect(searchBarRoot).toBeDefined();
|
|
272
|
+
expect(searchBarRoot).toEqual(expect.objectContaining(namespace.searchBarComponentVM));
|
|
273
|
+
}, {timeout: 200});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('When [data-bind-comp="search-bar"] was server rendered then show binding should not update element', async () => {
|
|
277
|
+
await waitFor(() => {
|
|
278
|
+
expect(namespace.searchBarComponent.isServerRendered).toBe(true);
|
|
279
|
+
expect(namespace.searchBarComponentVM.searching).toBe(false);
|
|
280
|
+
expect((document.querySelector('.spinner--search') as HTMLElement)!.style.display !== 'none').toBe(true);
|
|
281
|
+
}, {timeout: 500});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('When change #searchWord input value to "Handyman" viewModel onSearchWordChange should have been called', async () => {
|
|
285
|
+
const newSearchWord = 'Handyman';
|
|
286
|
+
|
|
287
|
+
await waitFor(() => {
|
|
288
|
+
const $searchInput = document.getElementById('searchWord');
|
|
289
|
+
expect($searchInput).not.toBeNull();
|
|
290
|
+
}, {timeout: 500});
|
|
291
|
+
|
|
292
|
+
const $searchInput = document.getElementById('searchWord') as HTMLInputElement;
|
|
293
|
+
const evt = document.createEvent('HTMLEvents');
|
|
294
|
+
evt.initEvent('change', true, true);
|
|
295
|
+
|
|
296
|
+
$searchInput.value = newSearchWord;
|
|
297
|
+
$searchInput.dispatchEvent(evt);
|
|
298
|
+
|
|
299
|
+
await waitFor(() => {
|
|
300
|
+
expect(namespace.searchBarComponentVM.onSearchWordChange).toHaveBeenCalled();
|
|
301
|
+
expect(namespace.searchBarComponentVM.searchWord).toEqual(newSearchWord);
|
|
302
|
+
}, {timeout: 500});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it('When change #location input value to "Melbourne" viewModel onSearchLocationChange should have been called', async () => {
|
|
306
|
+
const newLocation = 'Melbourne';
|
|
307
|
+
|
|
308
|
+
await waitFor(() => {
|
|
309
|
+
const $locationInput = document.getElementById('location');
|
|
310
|
+
expect($locationInput).not.toBeNull();
|
|
311
|
+
}, {timeout: 500});
|
|
312
|
+
|
|
313
|
+
const $locationInput = document.getElementById('location') as HTMLInputElement;
|
|
314
|
+
const evt = document.createEvent('HTMLEvents');
|
|
315
|
+
evt.initEvent('change', true, true);
|
|
316
|
+
|
|
317
|
+
$locationInput.value = newLocation;
|
|
318
|
+
$locationInput.dispatchEvent(evt);
|
|
319
|
+
|
|
320
|
+
await waitFor(() => {
|
|
321
|
+
expect(namespace.searchBarComponentVM.onSearchLocationChange).toHaveBeenCalled();
|
|
322
|
+
expect(namespace.searchBarComponentVM.searchLocation).toEqual(newLocation);
|
|
323
|
+
}, {timeout: 500});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it('When [data-bind-comp="search-bar"] was server rendered "data-server-rendered" attribute should have removed', async () => {
|
|
327
|
+
await waitFor(() => {
|
|
328
|
+
const searchBar = document.querySelector('[data-bind-comp="search-bar"]');
|
|
329
|
+
expect(searchBar!.getAttribute('data-server-rendered')).toBeNull();
|
|
330
|
+
}, {timeout: 500});
|
|
331
|
+
});
|
|
332
|
+
});
|