angular-slickgrid 9.0.0 → 9.0.2

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.
Files changed (395) hide show
  1. package/LICENSE +1 -1
  2. package/{dist/fesm2022 → fesm2022}/angular-slickgrid.mjs +16 -16
  3. package/package.json +27 -14
  4. package/.gitbook.yaml +0 -5
  5. package/CHANGELOG.md +0 -1691
  6. package/CONTRIBUTING.md +0 -17
  7. package/angular.json +0 -133
  8. package/coverage/base.css +0 -224
  9. package/coverage/block-navigation.js +0 -87
  10. package/coverage/clover.xml +0 -1620
  11. package/coverage/coverage-final.json +0 -9
  12. package/coverage/favicon.png +0 -0
  13. package/coverage/index.html +0 -176
  14. package/coverage/library/components/angular-slickgrid.component.ts.html +0 -5074
  15. package/coverage/library/components/index.html +0 -116
  16. package/coverage/library/constants.ts.html +0 -397
  17. package/coverage/library/extensions/index.html +0 -116
  18. package/coverage/library/extensions/slickRowDetailView.ts.html +0 -1261
  19. package/coverage/library/index.html +0 -116
  20. package/coverage/library/modules/angular-slickgrid.module.ts.html +0 -166
  21. package/coverage/library/modules/index.html +0 -116
  22. package/coverage/library/services/angularUtil.service.ts.html +0 -445
  23. package/coverage/library/services/container.service.ts.html +0 -163
  24. package/coverage/library/services/index.html +0 -161
  25. package/coverage/library/services/translater.service.ts.html +0 -199
  26. package/coverage/library/services/utilities.ts.html +0 -142
  27. package/coverage/prettify.css +0 -1
  28. package/coverage/prettify.js +0 -2
  29. package/coverage/sort-arrow-sprite.png +0 -0
  30. package/coverage/sorter.js +0 -196
  31. package/dist/LICENSE +0 -21
  32. package/dist/README.md +0 -142
  33. package/docs/README.md +0 -5
  34. package/docs/TOC.md +0 -105
  35. package/docs/backend-services/Custom-Backend-Service.md +0 -50
  36. package/docs/backend-services/GraphQL.md +0 -276
  37. package/docs/backend-services/OData.md +0 -245
  38. package/docs/backend-services/graphql/GraphQL-Filtering.md +0 -156
  39. package/docs/backend-services/graphql/GraphQL-JSON-Result.md +0 -85
  40. package/docs/backend-services/graphql/GraphQL-Pagination.md +0 -77
  41. package/docs/backend-services/graphql/GraphQL-Sorting.md +0 -78
  42. package/docs/column-functionalities/cell-menu.md +0 -212
  43. package/docs/column-functionalities/editors/autocomplete-editor.md +0 -466
  44. package/docs/column-functionalities/editors/date-editor-flatpickr.md +0 -71
  45. package/docs/column-functionalities/editors/date-editor-vanilla-calendar.md +0 -91
  46. package/docs/column-functionalities/editors/longtext-editor-textarea.md +0 -80
  47. package/docs/column-functionalities/editors/select-dropdown-editor.md +0 -227
  48. package/docs/column-functionalities/editors.md +0 -604
  49. package/docs/column-functionalities/filters/autocomplete-filter.md +0 -183
  50. package/docs/column-functionalities/filters/compound-filters.md +0 -234
  51. package/docs/column-functionalities/filters/custom-filter.md +0 -117
  52. package/docs/column-functionalities/filters/filter-intro.md +0 -81
  53. package/docs/column-functionalities/filters/input-filter.md +0 -260
  54. package/docs/column-functionalities/filters/range-filters.md +0 -188
  55. package/docs/column-functionalities/filters/select-filter.md +0 -695
  56. package/docs/column-functionalities/filters/single-search-filter.md +0 -77
  57. package/docs/column-functionalities/filters/styling-filled-filters.md +0 -45
  58. package/docs/column-functionalities/formatters.md +0 -325
  59. package/docs/column-functionalities/sorting.md +0 -200
  60. package/docs/developer-guides/csp-compliance.md +0 -64
  61. package/docs/events/Available-Events.md +0 -223
  62. package/docs/events/Grid-&-DataView-Events.md +0 -211
  63. package/docs/getting-started/quick-start.md +0 -230
  64. package/docs/getting-started/troubleshooting.md +0 -80
  65. package/docs/grid-functionalities/Column-Picker.md +0 -22
  66. package/docs/grid-functionalities/Composite-Editor-Modal.md +0 -627
  67. package/docs/grid-functionalities/Context-Menu.md +0 -226
  68. package/docs/grid-functionalities/Custom-Footer.md +0 -80
  69. package/docs/grid-functionalities/Custom-Tooltip-(plugin).md +0 -258
  70. package/docs/grid-functionalities/Export-to-Excel.md +0 -457
  71. package/docs/grid-functionalities/Export-to-Text-File.md +0 -165
  72. package/docs/grid-functionalities/FAQ.md +0 -53
  73. package/docs/grid-functionalities/Global-Options.md +0 -29
  74. package/docs/grid-functionalities/Grid-Auto-Resize.md +0 -218
  75. package/docs/grid-functionalities/Grid-Menu.md +0 -134
  76. package/docs/grid-functionalities/Grid-State-&-Preset.md +0 -245
  77. package/docs/grid-functionalities/Header-Menu-&-Header-Buttons.md +0 -125
  78. package/docs/grid-functionalities/Resize-by-Cell-Content.md +0 -138
  79. package/docs/grid-functionalities/Row-Selection.md +0 -247
  80. package/docs/grid-functionalities/Row-based-edit.md +0 -71
  81. package/docs/grid-functionalities/add-update-highlight.md +0 -258
  82. package/docs/grid-functionalities/column-row-spanning.md +0 -74
  83. package/docs/grid-functionalities/dynamic-item-metadata.md +0 -124
  84. package/docs/grid-functionalities/excel-copy-buffer.md +0 -145
  85. package/docs/grid-functionalities/frozen-columns-rows.md +0 -164
  86. package/docs/grid-functionalities/grouping-and-aggregators.md +0 -269
  87. package/docs/grid-functionalities/header-footer-slots.md +0 -22
  88. package/docs/grid-functionalities/infinite-scroll.md +0 -150
  89. package/docs/grid-functionalities/providing-grid-data.md +0 -61
  90. package/docs/grid-functionalities/row-detail.md +0 -530
  91. package/docs/grid-functionalities/tree-data-grid.md +0 -391
  92. package/docs/localization/Localization---Component-Sample.md +0 -87
  93. package/docs/localization/Localization-with-Custom-Locales.md +0 -66
  94. package/docs/localization/Localization-with-ngx-translate.md +0 -148
  95. package/docs/migrations/migration-to-2.x.md +0 -304
  96. package/docs/migrations/migration-to-3.x.md +0 -295
  97. package/docs/migrations/migration-to-4.x.md +0 -83
  98. package/docs/migrations/migration-to-5.x.md +0 -160
  99. package/docs/migrations/migration-to-6.x.md +0 -128
  100. package/docs/migrations/migration-to-7.x.md +0 -294
  101. package/docs/migrations/migration-to-8.x.md +0 -316
  102. package/docs/migrations/migration-to-9.x.md +0 -219
  103. package/docs/slick-grid-dataview-objects/slickgrid-dataview-objects.md +0 -79
  104. package/docs/styling/dark-mode.md +0 -100
  105. package/docs/styling/styling.md +0 -250
  106. package/docs/testing/testing-patterns.md +0 -73
  107. package/eslint.config.mjs +0 -60
  108. package/ng-package.json +0 -10
  109. package/src/assets/angular-logo.png +0 -0
  110. package/src/assets/angular-logo2.png +0 -0
  111. package/src/assets/data/collection_100_numbers.json +0 -12
  112. package/src/assets/data/collection_500_numbers.json +0 -52
  113. package/src/assets/data/countries.json +0 -245
  114. package/src/assets/data/country_names.json +0 -245
  115. package/src/assets/data/customers_100.json +0 -102
  116. package/src/assets/data/users.csv +0 -5
  117. package/src/assets/i18n/en.json +0 -102
  118. package/src/assets/i18n/fr.json +0 -103
  119. package/src/demos/app-routing.module.ts +0 -108
  120. package/src/demos/app.component.html +0 -187
  121. package/src/demos/app.component.scss +0 -79
  122. package/src/demos/app.component.ts +0 -11
  123. package/src/demos/app.module.ts +0 -196
  124. package/src/demos/environments/environment.dev.ts +0 -3
  125. package/src/demos/environments/environment.prod.ts +0 -3
  126. package/src/demos/environments/environment.ts +0 -8
  127. package/src/demos/examples/custom-angularComponentEditor.ts +0 -187
  128. package/src/demos/examples/custom-angularComponentFilter.ts +0 -123
  129. package/src/demos/examples/custom-buttonFormatter.component.ts +0 -13
  130. package/src/demos/examples/custom-inputEditor.ts +0 -132
  131. package/src/demos/examples/custom-inputFilter.ts +0 -134
  132. package/src/demos/examples/custom-titleFormatter.component.ts +0 -9
  133. package/src/demos/examples/data/collection_100_numbers.json +0 -12
  134. package/src/demos/examples/data/collection_500_numbers.json +0 -52
  135. package/src/demos/examples/data/countries.json +0 -245
  136. package/src/demos/examples/data/country_names.json +0 -245
  137. package/src/demos/examples/data/customers_100.json +0 -102
  138. package/src/demos/examples/data/users.csv +0 -5
  139. package/src/demos/examples/editor-ng-select.component.ts +0 -38
  140. package/src/demos/examples/example01.component.html +0 -48
  141. package/src/demos/examples/example01.component.ts +0 -109
  142. package/src/demos/examples/example02.component.html +0 -45
  143. package/src/demos/examples/example02.component.ts +0 -218
  144. package/src/demos/examples/example03.component.html +0 -118
  145. package/src/demos/examples/example03.component.ts +0 -694
  146. package/src/demos/examples/example04.component.html +0 -87
  147. package/src/demos/examples/example04.component.ts +0 -326
  148. package/src/demos/examples/example05.component.html +0 -151
  149. package/src/demos/examples/example05.component.ts +0 -474
  150. package/src/demos/examples/example06.component.html +0 -163
  151. package/src/demos/examples/example06.component.ts +0 -446
  152. package/src/demos/examples/example07.component.html +0 -56
  153. package/src/demos/examples/example07.component.scss +0 -10
  154. package/src/demos/examples/example07.component.ts +0 -216
  155. package/src/demos/examples/example08.component.html +0 -51
  156. package/src/demos/examples/example08.component.scss +0 -23
  157. package/src/demos/examples/example08.component.ts +0 -195
  158. package/src/demos/examples/example09.component.html +0 -55
  159. package/src/demos/examples/example09.component.scss +0 -22
  160. package/src/demos/examples/example09.component.ts +0 -302
  161. package/src/demos/examples/example10.component.html +0 -103
  162. package/src/demos/examples/example10.component.ts +0 -309
  163. package/src/demos/examples/example11.component.html +0 -91
  164. package/src/demos/examples/example11.component.ts +0 -276
  165. package/src/demos/examples/example12.component.html +0 -98
  166. package/src/demos/examples/example12.component.ts +0 -317
  167. package/src/demos/examples/example13.component.html +0 -96
  168. package/src/demos/examples/example13.component.ts +0 -370
  169. package/src/demos/examples/example14.component.html +0 -50
  170. package/src/demos/examples/example14.component.scss +0 -11
  171. package/src/demos/examples/example14.component.ts +0 -156
  172. package/src/demos/examples/example15.component.html +0 -56
  173. package/src/demos/examples/example15.component.ts +0 -304
  174. package/src/demos/examples/example16.component.html +0 -77
  175. package/src/demos/examples/example16.component.ts +0 -277
  176. package/src/demos/examples/example17.component.html +0 -50
  177. package/src/demos/examples/example17.component.ts +0 -109
  178. package/src/demos/examples/example18.component.html +0 -132
  179. package/src/demos/examples/example18.component.ts +0 -445
  180. package/src/demos/examples/example19-rowdetail.component.html +0 -40
  181. package/src/demos/examples/example19-rowdetail.component.ts +0 -54
  182. package/src/demos/examples/example19.component.html +0 -79
  183. package/src/demos/examples/example19.component.ts +0 -316
  184. package/src/demos/examples/example20.component.html +0 -76
  185. package/src/demos/examples/example20.component.scss +0 -11
  186. package/src/demos/examples/example20.component.ts +0 -341
  187. package/src/demos/examples/example21.component.html +0 -86
  188. package/src/demos/examples/example21.component.scss +0 -16
  189. package/src/demos/examples/example21.component.ts +0 -140
  190. package/src/demos/examples/example22.component.html +0 -41
  191. package/src/demos/examples/example22.component.ts +0 -117
  192. package/src/demos/examples/example23.component.html +0 -111
  193. package/src/demos/examples/example23.component.ts +0 -323
  194. package/src/demos/examples/example24.component.html +0 -120
  195. package/src/demos/examples/example24.component.scss +0 -62
  196. package/src/demos/examples/example24.component.ts +0 -641
  197. package/src/demos/examples/example25.component.html +0 -60
  198. package/src/demos/examples/example25.component.scss +0 -8
  199. package/src/demos/examples/example25.component.ts +0 -255
  200. package/src/demos/examples/example26.component.html +0 -98
  201. package/src/demos/examples/example26.component.scss +0 -42
  202. package/src/demos/examples/example26.component.ts +0 -383
  203. package/src/demos/examples/example27.component.html +0 -138
  204. package/src/demos/examples/example27.component.scss +0 -10
  205. package/src/demos/examples/example27.component.ts +0 -369
  206. package/src/demos/examples/example28.component.html +0 -143
  207. package/src/demos/examples/example28.component.scss +0 -54
  208. package/src/demos/examples/example28.component.ts +0 -453
  209. package/src/demos/examples/example29.component.html +0 -30
  210. package/src/demos/examples/example29.component.ts +0 -70
  211. package/src/demos/examples/example30.component.html +0 -116
  212. package/src/demos/examples/example30.component.scss +0 -20
  213. package/src/demos/examples/example30.component.ts +0 -1070
  214. package/src/demos/examples/example32.component.html +0 -77
  215. package/src/demos/examples/example32.component.scss +0 -8
  216. package/src/demos/examples/example32.component.ts +0 -905
  217. package/src/demos/examples/example33.component.html +0 -50
  218. package/src/demos/examples/example33.component.scss +0 -46
  219. package/src/demos/examples/example33.component.ts +0 -571
  220. package/src/demos/examples/example34.component.html +0 -82
  221. package/src/demos/examples/example34.component.scss +0 -77
  222. package/src/demos/examples/example34.component.ts +0 -434
  223. package/src/demos/examples/example35.component.html +0 -77
  224. package/src/demos/examples/example35.component.scss +0 -18
  225. package/src/demos/examples/example35.component.ts +0 -264
  226. package/src/demos/examples/example36.component.html +0 -56
  227. package/src/demos/examples/example36.component.scss +0 -26
  228. package/src/demos/examples/example36.component.ts +0 -504
  229. package/src/demos/examples/example37.component.html +0 -30
  230. package/src/demos/examples/example37.component.ts +0 -123
  231. package/src/demos/examples/example38.component.html +0 -104
  232. package/src/demos/examples/example38.component.scss +0 -8
  233. package/src/demos/examples/example38.component.ts +0 -420
  234. package/src/demos/examples/example39.component.html +0 -112
  235. package/src/demos/examples/example39.component.scss +0 -8
  236. package/src/demos/examples/example39.component.ts +0 -371
  237. package/src/demos/examples/example40.component.html +0 -76
  238. package/src/demos/examples/example40.component.ts +0 -226
  239. package/src/demos/examples/example41.component.html +0 -50
  240. package/src/demos/examples/example41.component.scss +0 -42
  241. package/src/demos/examples/example41.component.ts +0 -229
  242. package/src/demos/examples/example42.component.html +0 -47
  243. package/src/demos/examples/example42.component.ts +0 -203
  244. package/src/demos/examples/example43.component.html +0 -94
  245. package/src/demos/examples/example43.component.scss +0 -30
  246. package/src/demos/examples/example43.component.ts +0 -449
  247. package/src/demos/examples/example44.component.html +0 -78
  248. package/src/demos/examples/example44.component.scss +0 -50
  249. package/src/demos/examples/example44.component.ts +0 -375
  250. package/src/demos/examples/example45-detail.component.html +0 -15
  251. package/src/demos/examples/example45-detail.component.ts +0 -97
  252. package/src/demos/examples/example45.component.html +0 -110
  253. package/src/demos/examples/example45.component.scss +0 -50
  254. package/src/demos/examples/example45.component.ts +0 -243
  255. package/src/demos/examples/filter-ng-select.component.ts +0 -33
  256. package/src/demos/examples/grid-custom-pager.component.html +0 -60
  257. package/src/demos/examples/grid-custom-pager.component.scss +0 -57
  258. package/src/demos/examples/grid-custom-pager.component.ts +0 -107
  259. package/src/demos/examples/grid-remote.component.html +0 -44
  260. package/src/demos/examples/grid-remote.component.ts +0 -164
  261. package/src/demos/examples/home.component.html +0 -39
  262. package/src/demos/examples/home.component.ts +0 -10
  263. package/src/demos/examples/jsonp.ts +0 -89
  264. package/src/demos/examples/rowdetail-preload.component.ts +0 -10
  265. package/src/demos/examples/swt-common-grid-pagination.component.ts +0 -160
  266. package/src/demos/examples/swt-common-grid-test.component.html +0 -37
  267. package/src/demos/examples/swt-common-grid-test.component.ts +0 -214
  268. package/src/demos/examples/swt-common-grid.component.ts +0 -436
  269. package/src/demos/examples/swt-logger.service.ts +0 -173
  270. package/src/demos/examples/utilities.ts +0 -9
  271. package/src/favicon.ico +0 -0
  272. package/src/index.html +0 -17
  273. package/src/library/components/__tests__/angular-slickgrid.component.spec.ts +0 -2638
  274. package/src/library/components/angular-slickgrid.component.html +0 -5
  275. package/src/library/components/angular-slickgrid.component.ts +0 -1662
  276. package/src/library/constants.ts +0 -105
  277. package/src/library/extensions/__tests__/slickRowDetailView.spec.ts +0 -751
  278. package/src/library/extensions/index.ts +0 -1
  279. package/src/library/extensions/slickRowDetailView.ts +0 -395
  280. package/src/library/global-grid-options.ts +0 -273
  281. package/src/library/index.ts +0 -11
  282. package/src/library/models/angularComponentOutput.interface.ts +0 -6
  283. package/src/library/models/angularGridInstance.interface.ts +0 -76
  284. package/src/library/models/externalTestingDependencies.interface.ts +0 -37
  285. package/src/library/models/gridOption.interface.ts +0 -15
  286. package/src/library/models/index.ts +0 -5
  287. package/src/library/models/rowDetailView.interface.ts +0 -16
  288. package/src/library/modules/angular-slickgrid.module.spec.ts +0 -25
  289. package/src/library/modules/angular-slickgrid.module.ts +0 -27
  290. package/src/library/services/__tests__/angularUtilService.spec.ts +0 -156
  291. package/src/library/services/__tests__/container.service.spec.ts +0 -25
  292. package/src/library/services/__tests__/translater.service.spec.ts +0 -43
  293. package/src/library/services/__tests__/utilities.spec.ts +0 -22
  294. package/src/library/services/angularUtil.service.ts +0 -120
  295. package/src/library/services/container.service.ts +0 -26
  296. package/src/library/services/index.ts +0 -4
  297. package/src/library/services/translater.service.ts +0 -38
  298. package/src/library/services/utilities.ts +0 -19
  299. package/src/library/slickgrid-config.ts +0 -10
  300. package/src/main.ts +0 -13
  301. package/src/public_api.ts +0 -1
  302. package/src/styles.scss +0 -178
  303. package/test/cypress/e2e/example01.cy.ts +0 -367
  304. package/test/cypress/e2e/example02.cy.ts +0 -60
  305. package/test/cypress/e2e/example03.cy.ts +0 -268
  306. package/test/cypress/e2e/example04.cy.ts +0 -254
  307. package/test/cypress/e2e/example05.cy.ts +0 -804
  308. package/test/cypress/e2e/example06.cy.ts +0 -890
  309. package/test/cypress/e2e/example07.cy.ts +0 -384
  310. package/test/cypress/e2e/example08.cy.ts +0 -190
  311. package/test/cypress/e2e/example09.cy.ts +0 -392
  312. package/test/cypress/e2e/example10.cy.ts +0 -650
  313. package/test/cypress/e2e/example11.cy.ts +0 -86
  314. package/test/cypress/e2e/example12.cy.ts +0 -269
  315. package/test/cypress/e2e/example13.cy.ts +0 -246
  316. package/test/cypress/e2e/example14.cy.ts +0 -122
  317. package/test/cypress/e2e/example15.cy.ts +0 -598
  318. package/test/cypress/e2e/example16.cy.ts +0 -427
  319. package/test/cypress/e2e/example17.cy.ts +0 -83
  320. package/test/cypress/e2e/example18.cy.ts +0 -431
  321. package/test/cypress/e2e/example19.cy.ts +0 -263
  322. package/test/cypress/e2e/example20.cy.ts +0 -264
  323. package/test/cypress/e2e/example21.cy.ts +0 -77
  324. package/test/cypress/e2e/example22.cy.ts +0 -94
  325. package/test/cypress/e2e/example23.cy.ts +0 -259
  326. package/test/cypress/e2e/example24.cy.ts +0 -707
  327. package/test/cypress/e2e/example25.cy.ts +0 -193
  328. package/test/cypress/e2e/example26.cy.ts +0 -111
  329. package/test/cypress/e2e/example27.cy.ts +0 -261
  330. package/test/cypress/e2e/example28.cy.ts +0 -740
  331. package/test/cypress/e2e/example29.cy.ts +0 -30
  332. package/test/cypress/e2e/example30.cy.ts +0 -757
  333. package/test/cypress/e2e/example31.cy.ts +0 -69
  334. package/test/cypress/e2e/example32.cy.ts +0 -272
  335. package/test/cypress/e2e/example33.cy.ts +0 -278
  336. package/test/cypress/e2e/example34.cy.ts +0 -84
  337. package/test/cypress/e2e/example35.cy.ts +0 -178
  338. package/test/cypress/e2e/example36.cy.ts +0 -219
  339. package/test/cypress/e2e/example37.cy.ts +0 -52
  340. package/test/cypress/e2e/example38.cy.ts +0 -160
  341. package/test/cypress/e2e/example39.cy.ts +0 -150
  342. package/test/cypress/e2e/example40.cy.ts +0 -126
  343. package/test/cypress/e2e/example41.cy.ts +0 -90
  344. package/test/cypress/e2e/example42.cy.ts +0 -82
  345. package/test/cypress/e2e/example43.cy.ts +0 -482
  346. package/test/cypress/e2e/example44.cy.ts +0 -458
  347. package/test/cypress/e2e/example45.cy.ts +0 -455
  348. package/test/cypress/e2e/home.cy.ts +0 -7
  349. package/test/cypress/fixtures/example.json +0 -5
  350. package/test/cypress/plugins/index.ts +0 -17
  351. package/test/cypress/plugins/utilities.ts +0 -28
  352. package/test/cypress/support/commands.ts +0 -88
  353. package/test/cypress/support/common.ts +0 -47
  354. package/test/cypress/support/drag.ts +0 -101
  355. package/test/cypress/support/index.ts +0 -20
  356. package/test/cypress/tsconfig.json +0 -9
  357. package/test/cypress.config.ts +0 -34
  358. package/test/mockSlickEvent.ts +0 -77
  359. package/test/rxjsResourceStub.ts +0 -69
  360. package/test/test-setup.ts +0 -6
  361. package/test/translateServiceStub.ts +0 -230
  362. package/test/translaterServiceStub.ts +0 -239
  363. package/test/tsconfig.json +0 -17
  364. package/test/vitest-global-mocks.ts +0 -41
  365. package/test/vitest-global-setup.ts +0 -3
  366. package/test/vitest-pretest.ts +0 -5
  367. package/tsconfig.app.json +0 -14
  368. package/tsconfig.json +0 -31
  369. package/tsconfig.spec.json +0 -11
  370. package/types/sortablejs.d.ts +0 -4
  371. package/vite.config.mts +0 -51
  372. /package/{dist/fesm2022 → fesm2022}/angular-slickgrid.mjs.map +0 -0
  373. /package/{dist/i18n → i18n}/en.json +0 -0
  374. /package/{dist/i18n → i18n}/fr.json +0 -0
  375. /package/{dist/index.d.ts → index.d.ts} +0 -0
  376. /package/{dist/library → library}/components/angular-slickgrid.component.d.ts +0 -0
  377. /package/{dist/library → library}/constants.d.ts +0 -0
  378. /package/{dist/library → library}/extensions/index.d.ts +0 -0
  379. /package/{dist/library → library}/extensions/slickRowDetailView.d.ts +0 -0
  380. /package/{dist/library → library}/global-grid-options.d.ts +0 -0
  381. /package/{dist/library → library}/index.d.ts +0 -0
  382. /package/{dist/library → library}/models/angularComponentOutput.interface.d.ts +0 -0
  383. /package/{dist/library → library}/models/angularGridInstance.interface.d.ts +0 -0
  384. /package/{dist/library → library}/models/externalTestingDependencies.interface.d.ts +0 -0
  385. /package/{dist/library → library}/models/gridOption.interface.d.ts +0 -0
  386. /package/{dist/library → library}/models/index.d.ts +0 -0
  387. /package/{dist/library → library}/models/rowDetailView.interface.d.ts +0 -0
  388. /package/{dist/library → library}/modules/angular-slickgrid.module.d.ts +0 -0
  389. /package/{dist/library → library}/services/angularUtil.service.d.ts +0 -0
  390. /package/{dist/library → library}/services/container.service.d.ts +0 -0
  391. /package/{dist/library → library}/services/index.d.ts +0 -0
  392. /package/{dist/library → library}/services/translater.service.d.ts +0 -0
  393. /package/{dist/library → library}/services/utilities.d.ts +0 -0
  394. /package/{dist/library → library}/slickgrid-config.d.ts +0 -0
  395. /package/{dist/public_api.d.ts → public_api.d.ts} +0 -0
@@ -1,2638 +0,0 @@
1
- import { ApplicationRef, ChangeDetectorRef, Component, ElementRef } from '@angular/core';
2
- import { TestBed } from '@angular/core/testing';
3
- import { TranslateService, TranslateModule } from '@ngx-translate/core';
4
- import {
5
- autoAddEditorFormatterToColumnsWithEditor,
6
- BackendService,
7
- BackendServiceApi,
8
- BackendUtilityService,
9
- type BasePaginationComponent,
10
- CollectionService,
11
- Column,
12
- ColumnFilters,
13
- CurrentFilter,
14
- CurrentPagination,
15
- CurrentPinning,
16
- CurrentSorter,
17
- Editor,
18
- Editors,
19
- ExtensionList,
20
- ExtensionService,
21
- ExtensionUtility,
22
- Filters,
23
- FilterService,
24
- Formatter,
25
- GridEventService,
26
- GridService,
27
- GridState,
28
- GridStateService,
29
- HeaderGroupingService,
30
- OnRowCountChangedEventArgs,
31
- OnRowsChangedEventArgs,
32
- OnSetItemsCalledEventArgs,
33
- Pagination,
34
- PaginationMetadata,
35
- PaginationService,
36
- ResizerService,
37
- SharedService,
38
- SlickDataView,
39
- SlickEventHandler,
40
- SlickGrid,
41
- SlickGroupItemMetadataProvider,
42
- SortService,
43
- TreeDataService,
44
- } from '@slickgrid-universal/common';
45
- import { SlickFooterComponent } from '@slickgrid-universal/custom-footer-component';
46
- import { EventPubSubService } from '@slickgrid-universal/event-pub-sub';
47
- import { SlickEmptyWarningComponent } from '@slickgrid-universal/empty-warning-component';
48
- import { GraphqlPaginatedResult, GraphqlService, GraphqlServiceApi, GraphqlServiceOption } from '@slickgrid-universal/graphql';
49
- import { of, throwError } from 'rxjs';
50
- import { afterEach, beforeEach, describe, expect, it, type Mock, vi } from 'vitest';
51
-
52
- import { AngularSlickgridComponent } from '../angular-slickgrid.component.js';
53
- import { SlickRowDetailView } from '../../extensions/slickRowDetailView.js';
54
- import { TranslaterServiceStub } from '../../../../test/translaterServiceStub.js';
55
- import { AngularUtilService, ContainerService, TranslaterService } from '../../services/index.js';
56
- import { GridOption } from '../../models/index.js';
57
- import { MockSlickEvent, MockSlickEventHandler } from '../../../../test/mockSlickEvent.js';
58
- import { RxJsResourceStub } from '../../../../test/rxjsResourceStub.js';
59
-
60
- const addVanillaEventPropagation = function (event: Event) {
61
- Object.defineProperty(event, 'isPropagationStopped', { writable: true, configurable: true, value: vi.fn() });
62
- Object.defineProperty(event, 'isImmediatePropagationStopped', { writable: true, configurable: true, value: vi.fn() });
63
- return event;
64
- };
65
-
66
- const viewportElm = document.createElement('div');
67
- viewportElm.className = 'slick-viewport';
68
- Object.defineProperty(viewportElm, 'offsetHeight', { writable: true, configurable: true, value: 12 });
69
-
70
- const mockSlickRowDetailView = {
71
- create: vi.fn(),
72
- init: vi.fn(),
73
- } as unknown as SlickRowDetailView;
74
-
75
- vi.mock('../../extensions/slickRowDetailView', () => ({
76
- SlickRowDetailView: vi.fn().mockImplementation(() => mockSlickRowDetailView),
77
- }));
78
-
79
- const angularUtilServiceStub = {
80
- createAngularComponent: vi.fn(),
81
- createAngularComponentAppendToDom: vi.fn(),
82
- } as unknown as AngularUtilService;
83
-
84
- const backendUtilityServiceStub = {
85
- addRxJsResource: vi.fn(),
86
- executeBackendProcessesCallback: vi.fn(),
87
- executeBackendCallback: vi.fn(),
88
- onBackendError: vi.fn(),
89
- refreshBackendDataset: vi.fn(),
90
- setInfiniteScrollBottomHit: vi.fn(),
91
- } as unknown as BackendUtilityService;
92
-
93
- const collectionServiceStub = {
94
- filterCollection: vi.fn(),
95
- singleFilterCollection: vi.fn(),
96
- sortCollection: vi.fn(),
97
- } as unknown as CollectionService;
98
-
99
- const mockAppRef = {
100
- detachView: vi.fn(),
101
- } as unknown as ApplicationRef;
102
-
103
- const extensionServiceStub = {
104
- addExtensionToList: vi.fn(),
105
- bindDifferentExtensions: vi.fn(),
106
- createExtensionsBeforeGridCreation: vi.fn(),
107
- dispose: vi.fn(),
108
- renderColumnHeaders: vi.fn(),
109
- translateAllExtensions: vi.fn(),
110
- translateColumnHeaders: vi.fn(),
111
- } as unknown as ExtensionService;
112
- Object.defineProperty(extensionServiceStub, 'extensionList', { get: vi.fn(() => {}), set: vi.fn(), configurable: true });
113
-
114
- const mockExtensionUtility = {
115
- translateItems: vi.fn(),
116
- } as unknown as ExtensionUtility;
117
-
118
- const headerGroupingServiceStub = {
119
- init: vi.fn(),
120
- dispose: vi.fn(),
121
- translateHeaderGrouping: vi.fn(),
122
- } as unknown as HeaderGroupingService;
123
-
124
- const mockGraphqlService = {
125
- getDatasetName: vi.fn(),
126
- buildQuery: vi.fn(),
127
- init: vi.fn(),
128
- updateFilters: vi.fn(),
129
- updateSorters: vi.fn(),
130
- updatePagination: vi.fn(),
131
- } as unknown as GraphqlService;
132
-
133
- const filterServiceStub = {
134
- addRxJsResource: vi.fn(),
135
- clearFilters: vi.fn(),
136
- dispose: vi.fn(),
137
- init: vi.fn(),
138
- bindBackendOnFilter: vi.fn(),
139
- bindLocalOnFilter: vi.fn(),
140
- bindLocalOnSort: vi.fn(),
141
- bindBackendOnSort: vi.fn(),
142
- populateColumnFilterSearchTermPresets: vi.fn(),
143
- refreshTreeDataFilters: vi.fn(),
144
- getColumnFilters: vi.fn(),
145
- } as unknown as FilterService;
146
-
147
- const gridEventServiceStub = {
148
- init: vi.fn(),
149
- dispose: vi.fn(),
150
- bindOnCellChange: vi.fn(),
151
- bindOnClick: vi.fn(),
152
- } as unknown as GridEventService;
153
-
154
- const gridServiceStub = {
155
- init: vi.fn(),
156
- dispose: vi.fn(),
157
- setSelectedRows: vi.fn(),
158
- } as unknown as GridService;
159
-
160
- const gridStateServiceStub = {
161
- init: vi.fn(),
162
- dispose: vi.fn(),
163
- getAssociatedGridColumns: vi.fn(),
164
- getCurrentGridState: vi.fn(),
165
- needToPreserveRowSelection: vi.fn(),
166
- } as unknown as GridStateService;
167
-
168
- const paginationServiceStub = {
169
- totalItems: 0,
170
- addRxJsResource: vi.fn(),
171
- init: vi.fn(),
172
- dispose: vi.fn(),
173
- getFullPagination: vi.fn(),
174
- goToNextPage: vi.fn(),
175
- updateTotalItems: vi.fn(),
176
- } as unknown as PaginationService;
177
-
178
- Object.defineProperty(paginationServiceStub, 'totalItems', {
179
- get: vi.fn(() => 0),
180
- set: vi.fn(),
181
- });
182
-
183
- const resizerServiceStub = {
184
- isAutoHeightEnabled: true,
185
- autoHeightRecalcRow: 100,
186
- init: vi.fn(),
187
- dispose: vi.fn(),
188
- bindAutoResizeDataGrid: vi.fn(),
189
- resizeGrid: vi.fn(),
190
- resizeColumnsByCellContent: vi.fn(),
191
- } as unknown as ResizerService;
192
-
193
- const sortServiceStub = {
194
- addRxJsResource: vi.fn(),
195
- bindBackendOnSort: vi.fn(),
196
- bindLocalOnSort: vi.fn(),
197
- dispose: vi.fn(),
198
- loadGridSorters: vi.fn(),
199
- processTreeDataInitialSort: vi.fn(),
200
- sortHierarchicalDataset: vi.fn(),
201
- } as unknown as SortService;
202
-
203
- const treeDataServiceStub = {
204
- convertFlatParentChildToTreeDataset: vi.fn(),
205
- init: vi.fn(),
206
- convertFlatParentChildToTreeDatasetAndSort: vi.fn(),
207
- dispose: vi.fn(),
208
- handleOnCellClick: vi.fn(),
209
- sortHierarchicalDataset: vi.fn(),
210
- toggleTreeDataCollapse: vi.fn(),
211
- } as unknown as TreeDataService;
212
-
213
- const mockDataView = {
214
- constructor: vi.fn(),
215
- init: vi.fn(),
216
- destroy: vi.fn(),
217
- beginUpdate: vi.fn(),
218
- endUpdate: vi.fn(),
219
- getFilteredItemCount: vi.fn(),
220
- getItem: vi.fn(),
221
- getItemCount: vi.fn(),
222
- getItems: vi.fn(),
223
- getItemMetadata: vi.fn(),
224
- getLength: vi.fn(),
225
- getPagingInfo: vi.fn(),
226
- mapIdsToRows: vi.fn(),
227
- mapRowsToIds: vi.fn(),
228
- onRowsChanged: new MockSlickEvent<OnRowsChangedEventArgs>(),
229
- onRowCountChanged: new MockSlickEvent<OnRowCountChangedEventArgs>(),
230
- onSetItemsCalled: new MockSlickEvent<OnSetItemsCalledEventArgs>(),
231
- reSort: vi.fn(),
232
- setItems: vi.fn(),
233
- setSelectedIds: vi.fn(),
234
- syncGridSelection: vi.fn(),
235
- } as unknown as SlickDataView;
236
-
237
- const mockGetEditorLock = {
238
- isActive: () => true,
239
- commitCurrentEdit: vi.fn(),
240
- };
241
-
242
- const mockGrid = {
243
- applyHtmlCode: (elm: HTMLElement, val: string) => (elm.innerHTML = val || ''),
244
- autosizeColumns: vi.fn(),
245
- destroy: vi.fn(),
246
- init: vi.fn(),
247
- invalidate: vi.fn(),
248
- invalidateRows: vi.fn(),
249
- getActiveCellNode: vi.fn(),
250
- getColumns: vi.fn(),
251
- getCellEditor: vi.fn(),
252
- getEditorLock: () => mockGetEditorLock,
253
- getViewportNode: () => viewportElm,
254
- getUID: () => 'slickgrid_12345',
255
- getContainerNode: vi.fn(),
256
- getGridPosition: vi.fn(),
257
- getOptions: vi.fn(),
258
- getRenderedRange: vi.fn(),
259
- getSelectionModel: vi.fn(),
260
- getScrollbarDimensions: vi.fn(),
261
- updateRow: vi.fn(),
262
- render: vi.fn(),
263
- registerPlugin: vi.fn(),
264
- reRenderColumns: vi.fn(),
265
- resizeCanvas: vi.fn(),
266
- setColumns: vi.fn(),
267
- setHeaderRowVisibility: vi.fn(),
268
- setOptions: vi.fn(),
269
- setSelectedRows: vi.fn(),
270
- onClick: new MockSlickEvent(),
271
- onClicked: new MockSlickEvent(),
272
- onColumnsReordered: new MockSlickEvent(),
273
- onSetOptions: new MockSlickEvent(),
274
- onRendered: vi.fn(),
275
- onScroll: new MockSlickEvent(),
276
- onSelectedRowsChanged: new MockSlickEvent(),
277
- onDataviewCreated: new MockSlickEvent(),
278
- } as unknown as SlickGrid;
279
-
280
- const mockSlickEventHandler = {
281
- handlers: [],
282
- notify: vi.fn(),
283
- subscribe: vi.fn(),
284
- unsubscribe: vi.fn(),
285
- unsubscribeAll: vi.fn(),
286
- } as unknown as SlickEventHandler;
287
-
288
- const slickEventHandler = new MockSlickEventHandler() as unknown as SlickEventHandler;
289
-
290
- vi.mock('@slickgrid-universal/common', async () => ({
291
- ...((await vi.importActual('@slickgrid-universal/common')) as any),
292
- autoAddEditorFormatterToColumnsWithEditor: vi.fn(),
293
- SlickGrid: vi.fn().mockImplementation(() => mockGrid),
294
- SlickEventHandler: vi.fn().mockImplementation(() => mockSlickEventHandler),
295
- SlickDataView: vi.fn().mockImplementation(() => mockDataView),
296
- }));
297
-
298
- @Component({ template: `<h1>Some Title</h1>` })
299
- class TestPaginationComponent implements BasePaginationComponent {
300
- init = vi.fn();
301
- dispose = vi.fn();
302
- renderPagination = vi.fn();
303
- }
304
-
305
- describe('Angular-Slickgrid Custom Component instantiated via Constructor', () => {
306
- let component: AngularSlickgridComponent;
307
- let columnDefinitions: Column[] = [];
308
- let eventPubSubService: EventPubSubService;
309
- let gridOptions!: GridOption;
310
- let divContainer: HTMLDivElement;
311
- let cellDiv: HTMLDivElement;
312
- let mockElementRef: ElementRef;
313
- let sharedService: SharedService;
314
- let translate: TranslateService;
315
- let mockChangeDetectorRef: ChangeDetectorRef;
316
- let translaterService: TranslaterServiceStub;
317
- const containerService = new ContainerService();
318
-
319
- const template = `
320
- <div id="grid1" style="height: 800px; width: 600px;">
321
- <div id="slickGridContainer-grid1" class="gridPane" style="width: 100%;">
322
- </div>
323
- </div>
324
- <angular-slickgrid
325
- gridId="grid1"
326
- [columns]="columnDefinitions"
327
- [options]="gridOptions"
328
- [dataset]="dataset">
329
- </angular-slickgrid>`;
330
-
331
- beforeEach(async () => {
332
- divContainer = document.createElement('div');
333
- cellDiv = document.createElement('div');
334
- divContainer.innerHTML = template;
335
- divContainer.appendChild(cellDiv);
336
- document.body.appendChild(divContainer);
337
- columnDefinitions = [{ id: 'name', field: 'name' }];
338
- gridOptions = {
339
- enableExcelExport: false,
340
- dataView: null,
341
- autoResize: {
342
- bottomPadding: 45,
343
- calculateAvailableSizeBy: 'window',
344
- minHeight: 180,
345
- minWidth: 300,
346
- rightPadding: 0,
347
- },
348
- backendServiceApi: null,
349
- } as unknown as GridOption;
350
- vi.spyOn(mockGrid, 'getOptions').mockReturnValue(gridOptions);
351
-
352
- eventPubSubService = new EventPubSubService(divContainer);
353
- sharedService = new SharedService();
354
- translaterService = new TranslaterServiceStub();
355
- await TestBed.configureTestingModule({
356
- imports: [TranslateModule.forRoot()],
357
- teardown: { destroyAfterEach: false },
358
- });
359
- translate = TestBed.inject(TranslateService);
360
-
361
- mockChangeDetectorRef = {
362
- detectChanges: vi.fn(),
363
- markForCheck: vi.fn(),
364
- } as unknown as ChangeDetectorRef;
365
-
366
- mockElementRef = {
367
- nativeElement: divContainer,
368
- } as ElementRef;
369
-
370
- component = new AngularSlickgridComponent(
371
- angularUtilServiceStub,
372
- mockAppRef,
373
- mockChangeDetectorRef,
374
- containerService,
375
- mockElementRef,
376
- translate as unknown as TranslateService,
377
- translaterService as unknown as TranslaterService,
378
- {} as GridOption,
379
- {
380
- backendUtilityService: backendUtilityServiceStub,
381
- collectionService: collectionServiceStub,
382
- extensionService: extensionServiceStub,
383
- extensionUtility: mockExtensionUtility,
384
- eventPubSubService,
385
- filterService: filterServiceStub,
386
- gridEventService: gridEventServiceStub,
387
- gridService: gridServiceStub,
388
- gridStateService: gridStateServiceStub,
389
- headerGroupingService: headerGroupingServiceStub,
390
- resizerService: resizerServiceStub,
391
- paginationService: paginationServiceStub,
392
- sharedService,
393
- sortService: sortServiceStub,
394
- treeDataService: treeDataServiceStub,
395
- }
396
- );
397
-
398
- component.gridId = 'grid1';
399
- component.columns = [{ id: 'name', field: 'name' }];
400
- component.dataset = [];
401
- component.options = { enableExcelExport: false, dataView: null } as unknown as GridOption;
402
- });
403
-
404
- afterEach(() => {
405
- component?.destroy();
406
- });
407
-
408
- it('should make sure Angular-Slickgrid is defined', () => {
409
- expect(component).toBeTruthy();
410
- expect(component.elementRef.nativeElement).toBeTruthy();
411
- });
412
-
413
- it('should provide the gridService lazily', () => {
414
- const instance = new AngularSlickgridComponent(
415
- angularUtilServiceStub,
416
- mockAppRef,
417
- mockChangeDetectorRef,
418
- containerService,
419
- mockElementRef,
420
- translate as unknown as TranslateService,
421
- translaterService as unknown as TranslaterService,
422
- {} as GridOption,
423
- {
424
- backendUtilityService: backendUtilityServiceStub,
425
- collectionService: collectionServiceStub,
426
- extensionService: undefined,
427
- extensionUtility: mockExtensionUtility,
428
- eventPubSubService,
429
- filterService: filterServiceStub,
430
- gridEventService: gridEventServiceStub,
431
- gridService: gridServiceStub,
432
- gridStateService: gridStateServiceStub,
433
- headerGroupingService: headerGroupingServiceStub,
434
- resizerService: resizerServiceStub,
435
- paginationService: paginationServiceStub,
436
- sharedService,
437
- sortService: sortServiceStub,
438
- treeDataService: treeDataServiceStub,
439
- }
440
- );
441
-
442
- expect(instance).toBeTruthy();
443
- expect(instance.elementRef.nativeElement).toBeTruthy();
444
- expect((instance.extensionService as any).lazyGridService()).toBeDefined();
445
- });
446
-
447
- it('should load enable mousewheel event scrolling when using a frozen grid', () => {
448
- component.options = gridOptions;
449
- component.options.enableMouseWheelScrollHandler = undefined;
450
- component.options.frozenRow = 3;
451
-
452
- component.ngAfterViewInit();
453
-
454
- expect(component.options.enableMouseWheelScrollHandler).toBe(true);
455
- });
456
-
457
- it('should throw an error when [columns] is undefined', () =>
458
- new Promise((done: any) => {
459
- try {
460
- component.columns = '' as any;
461
- component.options = gridOptions;
462
- component.ngAfterViewInit();
463
- component.dataset = [];
464
- } catch (e: any) {
465
- expect(e.toString()).toContain('Using `<angular-slickgrid>` requires [columns]');
466
- component.destroy();
467
- done();
468
- }
469
- }));
470
-
471
- it('should keep frozen column index reference (via frozenVisibleColumnId) when grid is a frozen grid', () => {
472
- component.columns = columnDefinitions;
473
- component.options = gridOptions;
474
- component.options.frozenColumn = 0;
475
-
476
- component.initialization(slickEventHandler);
477
-
478
- expect(component.eventHandler).toBe(slickEventHandler);
479
- expect(sharedService.frozenVisibleColumnId).toBe('name');
480
- });
481
-
482
- it('should update "visibleColumns" in the Shared Service when "onColumnsReordered" event is triggered', () => {
483
- const sharedVisibleColumnsSpy = vi.spyOn(SharedService.prototype, 'visibleColumns', 'set');
484
- const newVisibleColumns = [
485
- { id: 'lastName', field: 'lastName' },
486
- { id: 'fristName', field: 'fristName' },
487
- ];
488
-
489
- component.options = { enableFiltering: true };
490
- component.initialization(slickEventHandler);
491
- mockGrid.onColumnsReordered.notify({ impactedColumns: newVisibleColumns, grid: mockGrid });
492
-
493
- expect(component.eventHandler).toEqual(slickEventHandler);
494
- expect(sharedService.hasColumnsReordered).toBe(true);
495
- expect(sharedVisibleColumnsSpy).toHaveBeenCalledWith(newVisibleColumns);
496
- });
497
-
498
- it('should change Dark Mode by using "setOptions" when triggered with "onSetOptions" event', () => {
499
- component.options = { darkMode: false };
500
- component.initialization(slickEventHandler);
501
- mockGrid.onSetOptions.notify({ optionsBefore: { darkMode: false }, optionsAfter: { darkMode: true }, grid: mockGrid });
502
-
503
- expect(component.eventHandler).toEqual(slickEventHandler);
504
- expect(divContainer.classList.contains('slick-dark-mode')).toBeTruthy();
505
- });
506
-
507
- it('should change back to Light Mode by using "setOptions" when triggered with "onSetOptions" event', () => {
508
- component.options = { darkMode: true };
509
- component.initialization(slickEventHandler);
510
- mockGrid.onSetOptions.notify({ optionsBefore: { darkMode: true }, optionsAfter: { darkMode: false }, grid: mockGrid });
511
-
512
- expect(component.eventHandler).toEqual(slickEventHandler);
513
- expect(divContainer.classList.contains('slick-dark-mode')).toBeFalsy();
514
- });
515
-
516
- it('should create a grid and expect multiple event published', () => {
517
- const pubSubSpy = vi.spyOn(eventPubSubService, 'publish');
518
-
519
- component.ngAfterViewInit();
520
-
521
- expect(eventPubSubService).toBeTruthy();
522
- expect(pubSubSpy).toHaveBeenNthCalledWith(1, 'onBeforeGridCreate', true);
523
- expect(pubSubSpy).toHaveBeenNthCalledWith(2, 'onDataviewCreated', expect.any(Object));
524
- expect(pubSubSpy).toHaveBeenNthCalledWith(3, 'onGridCreated', expect.any(Object));
525
- expect(pubSubSpy).toHaveBeenNthCalledWith(4, 'onAngularGridCreated', expect.any(Object));
526
-
527
- component.ngOnDestroy();
528
- expect(pubSubSpy).toHaveBeenNthCalledWith(5, 'onBeforeGridDestroy', expect.any(Object));
529
- expect(pubSubSpy).toHaveBeenNthCalledWith(6, 'onAfterGridDestroyed', true);
530
- });
531
-
532
- it('should update column definitions when onPluginColumnsChanged event is triggered with updated columns', () => {
533
- const colsChangeSpy = vi.spyOn(component.columnsChange, 'emit');
534
- const columnsMock = [
535
- { id: 'firstName', field: 'firstName', editor: undefined },
536
- { id: 'lastName', field: 'lastName', editor: undefined },
537
- ];
538
-
539
- component.ngAfterViewInit();
540
- component.initialization(slickEventHandler);
541
- eventPubSubService.publish('onPluginColumnsChanged', {
542
- columns: columnsMock,
543
- pluginName: 'RowMoveManager',
544
- });
545
-
546
- expect(component.columns).toEqual(columnsMock);
547
- expect(colsChangeSpy).toHaveBeenCalledWith(columnsMock);
548
- });
549
-
550
- describe('initialization method', () => {
551
- const customEditableInputFormatter: Formatter = (_row, _cell, value, columnDef) => {
552
- const isEditableLine = !!columnDef.editor;
553
- value = value === null || value === undefined ? '' : value;
554
- return isEditableLine ? `<div class="editing-field">${value}</div>` : value;
555
- };
556
-
557
- afterEach(() => {
558
- vi.clearAllMocks();
559
- });
560
-
561
- it('should initialize the grid with a fixed height when provided in the grid options', () => {
562
- const fixedHeight = 100;
563
- const resizerSpy = vi.spyOn(resizerServiceStub, 'resizeGrid');
564
-
565
- component.options = { ...gridOptions, gridHeight: fixedHeight };
566
- component.ngAfterViewInit();
567
-
568
- expect(resizerSpy).toHaveBeenCalledWith(0, { height: fixedHeight, width: undefined });
569
- });
570
-
571
- it('should initialize the grid with a fixed width when provided in the grid options', () => {
572
- const fixedWidth = 255;
573
- const resizerSpy = vi.spyOn(resizerServiceStub, 'resizeGrid');
574
-
575
- component.options = { ...gridOptions, gridWidth: fixedWidth };
576
- component.ngAfterViewInit();
577
-
578
- expect(resizerSpy).toHaveBeenCalledWith(0, { height: undefined, width: fixedWidth });
579
- });
580
-
581
- it('should initialize the grid with autoResize enabled and without height/width then expect a "gridResize" to be called for auto-resizing', () => {
582
- const resizerSpy = vi.spyOn(resizerServiceStub, 'resizeGrid');
583
-
584
- component.options = { ...gridOptions, enableAutoResize: true };
585
- component.ngAfterViewInit();
586
-
587
- expect(resizerSpy).toHaveBeenCalledWith();
588
- });
589
-
590
- it('should expect a console warning when grid is initialized with a dataset larger than 5K items without pre-parsing enabled', () => {
591
- const consoleWarnSpy = vi.spyOn(console, 'warn').mockReturnValue();
592
- vi.spyOn(mockDataView, 'getItemCount').mockReturnValueOnce(10001);
593
- const mockColumns: Column[] = [
594
- { id: 'firstName', field: 'firstName' },
595
- { id: 'updatedDate', field: 'updatedDate', type: 'dateIso' },
596
- ];
597
- vi.spyOn(mockGrid, 'getColumns').mockReturnValueOnce(mockColumns);
598
-
599
- component.options = { enableAutoResize: true };
600
- component.ngAfterViewInit();
601
-
602
- expect(consoleWarnSpy).toHaveBeenCalledWith(
603
- expect.stringContaining('[Slickgrid-Universal] For getting better perf, we suggest you enable the `preParseDateColumns` grid option')
604
- );
605
- });
606
-
607
- it('should expect a console warning when assigned dataset is larger than 5K items without pre-parsing enabled', () => {
608
- const consoleWarnSpy = vi.spyOn(console, 'warn').mockReturnValue();
609
- vi.spyOn(mockDataView, 'getItemCount').mockReturnValueOnce(0);
610
- const mockColumns: Column[] = [
611
- { id: 'firstName', field: 'firstName' },
612
- { id: 'updatedDate', field: 'updatedDate', type: 'dateIso' },
613
- ];
614
- vi.spyOn(mockGrid, 'getColumns').mockReturnValueOnce(mockColumns);
615
-
616
- component.options = { enableAutoResize: true };
617
- component.ngAfterViewInit();
618
-
619
- // we'll do a fake dataset assignment of 10001 items
620
- vi.spyOn(mockDataView, 'getItemCount').mockReturnValueOnce(10001);
621
- component.dataset = [{ firstName: 'John', updatedDate: '2020-02-01' }];
622
-
623
- expect(consoleWarnSpy).toHaveBeenCalledWith(
624
- expect.stringContaining('[Slickgrid-Universal] For getting better perf, we suggest you enable the `preParseDateColumns` grid option')
625
- );
626
- });
627
-
628
- describe('autoAddCustomEditorFormatter grid option', () => {
629
- it('should initialize the grid and automatically add custom Editor Formatter when provided in the grid options', () => {
630
- component.options = { ...gridOptions, autoAddCustomEditorFormatter: customEditableInputFormatter };
631
- component.ngAfterViewInit();
632
-
633
- expect(component).toBeTruthy();
634
- expect(autoAddEditorFormatterToColumnsWithEditor).toHaveBeenCalledWith(
635
- [{ id: 'name', field: 'name', editor: undefined }],
636
- customEditableInputFormatter
637
- );
638
- });
639
- });
640
-
641
- describe('columns definitions changed', () => {
642
- it('should expect "translateColumnHeaders" being called when "enableTranslate" is set', () => {
643
- const translateSpy = vi.spyOn(extensionServiceStub, 'translateColumnHeaders');
644
- const autosizeSpy = vi.spyOn(mockGrid, 'autosizeColumns');
645
- const updateSpy = vi.spyOn(component, 'updateColumnDefinitionsList');
646
- const mockColDefs = [{ id: 'name', field: 'name', editor: undefined }];
647
-
648
- component.options = { enableTranslate: true, darkMode: true };
649
- component.ngAfterViewInit();
650
- component.initialization(slickEventHandler);
651
- component.columns = mockColDefs;
652
-
653
- expect(component.options.translater).toBeTruthy();
654
- expect(translateSpy).toHaveBeenCalled();
655
- expect(autosizeSpy).toHaveBeenCalled();
656
- expect(updateSpy).toHaveBeenCalledWith(mockColDefs);
657
- });
658
-
659
- it('should expect "renderColumnHeaders" being called when "enableTranslate" is disabled', () => {
660
- const translateSpy = vi.spyOn(extensionServiceStub, 'translateColumnHeaders');
661
- const autosizeSpy = vi.spyOn(mockGrid, 'autosizeColumns');
662
- const updateSpy = vi.spyOn(component, 'updateColumnDefinitionsList');
663
- const renderSpy = vi.spyOn(extensionServiceStub, 'renderColumnHeaders');
664
- const mockColDefs = [{ id: 'name', field: 'name', editor: undefined }];
665
-
666
- component.ngAfterViewInit();
667
- component.columns = mockColDefs;
668
- component.options = { ...gridOptions, enableTranslate: false, autoAddCustomEditorFormatter: customEditableInputFormatter };
669
- component.initialization(slickEventHandler);
670
-
671
- expect(translateSpy).not.toHaveBeenCalled();
672
- expect(autosizeSpy).toHaveBeenCalled();
673
- expect(updateSpy).toHaveBeenCalledWith(mockColDefs);
674
- expect(renderSpy).toHaveBeenCalledWith(mockColDefs, true);
675
- expect(autoAddEditorFormatterToColumnsWithEditor).toHaveBeenCalledWith(
676
- [{ id: 'name', field: 'name', editor: undefined }],
677
- customEditableInputFormatter
678
- );
679
- });
680
- });
681
-
682
- describe('dataset changed', () => {
683
- beforeEach(() => {
684
- vi.clearAllMocks();
685
- sharedService.slickGrid = mockGrid as unknown as SlickGrid;
686
- });
687
-
688
- it('should expect "autosizeColumns" being called when "autoFitColumnsOnFirstLoad" is set we udpated the dataset', () => {
689
- const autosizeSpy = vi.spyOn(mockGrid, 'autosizeColumns');
690
- const refreshSpy = vi.spyOn(component, 'refreshGridData');
691
- const mockData = [
692
- { firstName: 'John', lastName: 'Doe' },
693
- { firstName: 'Jane', lastName: 'Smith' },
694
- ];
695
- vi.spyOn(mockDataView, 'getLength').mockReturnValueOnce(0).mockReturnValueOnce(0).mockReturnValueOnce(mockData.length);
696
-
697
- component.ngAfterViewInit();
698
- component.options = { autoFitColumnsOnFirstLoad: true };
699
- component.setData(mockData, true); // manually force an autoresize
700
-
701
- expect(autosizeSpy).toHaveBeenCalledTimes(2); // 1x by datasetChanged and 1x by bindResizeHook
702
- expect(refreshSpy).toHaveBeenCalledWith(mockData);
703
- });
704
-
705
- it('should expect "autosizeColumns" being called when "autoFitColumnsOnFirstLoad" is set and we are on first page load', () => {
706
- const autosizeSpy = vi.spyOn(mockGrid, 'autosizeColumns');
707
- const refreshSpy = vi.spyOn(component, 'refreshGridData');
708
- const mockData = [
709
- { firstName: 'John', lastName: 'Doe' },
710
- { firstName: 'Jane', lastName: 'Smith' },
711
- ];
712
- vi.spyOn(mockDataView, 'getLength').mockReturnValueOnce(0).mockReturnValueOnce(0).mockReturnValueOnce(mockData.length);
713
-
714
- component.ngAfterViewInit();
715
- component.options = { autoFitColumnsOnFirstLoad: true };
716
- component.dataset = mockData;
717
-
718
- expect(autosizeSpy).toHaveBeenCalledTimes(1);
719
- expect(refreshSpy).toHaveBeenCalledWith(mockData);
720
- });
721
-
722
- it('should expect "autosizeColumns" NOT being called when "autoFitColumnsOnFirstLoad" is not set and we are on first page load', () => {
723
- const autosizeSpy = vi.spyOn(mockGrid, 'autosizeColumns');
724
- const refreshSpy = vi.spyOn(component, 'refreshGridData');
725
- const mockData = [
726
- { firstName: 'John', lastName: 'Doe' },
727
- { firstName: 'Jane', lastName: 'Smith' },
728
- ];
729
- vi.spyOn(mockDataView, 'getLength').mockReturnValueOnce(0).mockReturnValueOnce(0).mockReturnValueOnce(mockData.length);
730
-
731
- component.options = { autoFitColumnsOnFirstLoad: false };
732
- component.ngAfterViewInit();
733
- component.dataset = mockData;
734
-
735
- expect(autosizeSpy).not.toHaveBeenCalled();
736
- expect(refreshSpy).toHaveBeenCalledWith(mockData);
737
- });
738
-
739
- it('should expect "resizeColumnsByCellContent" being called when "enableAutoResizeColumnsByCellContent" is set and we changing column definitions via its SETTER', () => {
740
- const resizeContentSpy = vi.spyOn(resizerServiceStub, 'resizeColumnsByCellContent');
741
- const refreshSpy = vi.spyOn(component, 'refreshGridData');
742
- const mockData = [
743
- { firstName: 'John', lastName: 'Doe' },
744
- { firstName: 'Jane', lastName: 'Smith' },
745
- ];
746
- const mockColDefs = [{ id: 'gender', field: 'gender', editor: { model: Editors.text, collection: ['male', 'female'] } }] as Column[];
747
- vi.spyOn(mockDataView, 'getLength').mockReturnValueOnce(0).mockReturnValueOnce(0).mockReturnValueOnce(mockData.length);
748
-
749
- component.columns = mockColDefs;
750
- component.options = {
751
- autoFitColumnsOnFirstLoad: false,
752
- enableAutoSizeColumns: false,
753
- autosizeColumnsByCellContentOnFirstLoad: true,
754
- enableAutoResizeColumnsByCellContent: true,
755
- };
756
- component.ngAfterViewInit();
757
- component.dataset = mockData;
758
- component.columns = mockColDefs;
759
-
760
- expect(resizeContentSpy).toHaveBeenCalledTimes(1);
761
- expect(refreshSpy).toHaveBeenCalledWith(mockData);
762
- });
763
-
764
- it('should throw an error if we try to enable both auto resize type at same time with "autoFitColumnsOnFirstLoad" and "autosizeColumnsByCellContentOnFirstLoad"', () =>
765
- new Promise((done: any) => {
766
- const mockData = [
767
- { firstName: 'John', lastName: 'Doe' },
768
- { firstName: 'Jane', lastName: 'Smith' },
769
- ];
770
- vi.spyOn(mockDataView, 'getLength').mockReturnValueOnce(0).mockReturnValueOnce(0).mockReturnValueOnce(mockData.length);
771
-
772
- component.options = { autoFitColumnsOnFirstLoad: true, autosizeColumnsByCellContentOnFirstLoad: true };
773
-
774
- try {
775
- component.ngAfterViewInit();
776
- component.dataset = mockData;
777
- } catch (e: any) {
778
- expect(e.toString()).toContain(
779
- '[Angular-Slickgrid] You cannot enable both autosize/fit viewport & resize by content, you must choose which resize technique to use.'
780
- );
781
- component.destroy();
782
- done();
783
- }
784
- }));
785
-
786
- it('should throw an error if we try to enable both auto resize type at same time with "enableAutoSizeColumns" and "enableAutoResizeColumnsByCellContent"', () =>
787
- new Promise((done: any) => {
788
- const mockData = [
789
- { firstName: 'John', lastName: 'Doe' },
790
- { firstName: 'Jane', lastName: 'Smith' },
791
- ];
792
- vi.spyOn(mockDataView, 'getLength').mockReturnValueOnce(0).mockReturnValueOnce(0).mockReturnValueOnce(mockData.length);
793
-
794
- component.options = { enableAutoSizeColumns: true, enableAutoResizeColumnsByCellContent: true };
795
-
796
- try {
797
- component.ngAfterViewInit();
798
- component.dataset = mockData;
799
- } catch (e: any) {
800
- expect(e.toString()).toContain(
801
- '[Angular-Slickgrid] You cannot enable both autosize/fit viewport & resize by content, you must choose which resize technique to use.'
802
- );
803
- component.destroy();
804
- done();
805
- }
806
- }));
807
- });
808
-
809
- describe('options changed', () => {
810
- beforeEach(() => {
811
- vi.clearAllMocks();
812
- sharedService.slickGrid = mockGrid as unknown as SlickGrid;
813
- sharedService.gridOptions = gridOptions;
814
- });
815
-
816
- afterEach(() => {
817
- mockGrid.getOptions = vi.fn();
818
- vi.spyOn(mockGrid, 'getOptions').mockReturnValue(gridOptions);
819
- });
820
-
821
- it('should merge paginationOptions when some already exist', () => {
822
- const mockPagination = { pageSizes: [5, 10] } as Pagination;
823
- const paginationSrvSpy = vi.spyOn(paginationServiceStub, 'updateTotalItems');
824
-
825
- component.paginationOptions = mockPagination;
826
- component.paginationOptions = { pageSize: 5, totalItems: 5 } as any;
827
-
828
- expect(component.paginationOptions).toEqual({ pageSize: 5, pageSizes: [5, 10], totalItems: 5 });
829
- expect(paginationSrvSpy).toHaveBeenCalledWith(0, true);
830
- });
831
-
832
- it('should set brand new paginationOptions when none previously exist', () => {
833
- const mockPagination = { pageSize: 2, pageSizes: [], totalItems: 1 };
834
- const paginationSrvSpy = vi.spyOn(paginationServiceStub, 'updateTotalItems');
835
-
836
- component.paginationOptions = undefined;
837
- component.paginationOptions = mockPagination;
838
-
839
- // expect(component.paginationOptions).toEqual(mockPagination);
840
- expect(paginationSrvSpy).toHaveBeenNthCalledWith(2, 1, true);
841
- });
842
- });
843
-
844
- describe('with editors', () => {
845
- beforeEach(() => {
846
- component.options = gridOptions;
847
- });
848
-
849
- it('should display a console error when any of the column definition ids include a dot notation', () => {
850
- const consoleSpy = vi.spyOn(global.console, 'error').mockReturnValue();
851
- const mockColDefs = [{ id: 'user.gender', field: 'user.gender', editor: { model: Editors.text, collection: ['male', 'female'] } }] as Column[];
852
-
853
- component.columns = mockColDefs;
854
- component.initialization(slickEventHandler);
855
-
856
- expect(consoleSpy).toHaveBeenCalledWith(
857
- '[Angular-Slickgrid] Make sure that none of your Column Definition "id" property includes a dot in its name because that will cause some problems with the Editors. For example if your column definition "field" property is "user.firstName" then use "firstName" as the column "id".'
858
- );
859
- });
860
-
861
- it('should be able to load async editors with an Observable', () =>
862
- new Promise((done: any) => {
863
- const mockCollection = ['male', 'female'];
864
- const mockColDefs = [{ id: 'gender', field: 'gender', editor: { model: Editors.text, collectionAsync: of(mockCollection) } }] as Column[];
865
-
866
- component.ngAfterViewInit();
867
- component.columns = mockColDefs;
868
-
869
- setTimeout(() => {
870
- expect(component.columns[0].editor).toBeTruthy();
871
- expect(component.columns[0].editor!.collection).toEqual(mockCollection);
872
- expect(component.columns[0].editor!.model).toEqual(Editors.text);
873
- done();
874
- });
875
- }));
876
-
877
- it('should be able to load collectionAsync and expect Editor to be destroyed and re-render when receiving new collection from await', () =>
878
- new Promise((done: any) => {
879
- const mockCollection = ['male', 'female'];
880
- const promise = new Promise((resolve) => resolve(mockCollection));
881
- const mockEditor = {
882
- disable: vi.fn(),
883
- destroy: vi.fn(),
884
- renderDomElement: vi.fn(),
885
- } as unknown as Editor;
886
- const mockColDefs = [{ id: 'gender', field: 'gender', editor: { model: Editors.text, collectionAsync: promise } }] as Column[];
887
- vi.spyOn(mockGrid, 'getCellEditor').mockReturnValue(mockEditor);
888
- const disableSpy = vi.spyOn(mockEditor, 'disable');
889
- const destroySpy = vi.spyOn(mockEditor, 'destroy');
890
- const renderSpy = vi.spyOn(mockEditor, 'renderDomElement');
891
-
892
- component.ngAfterViewInit();
893
- component.columns = mockColDefs;
894
-
895
- setTimeout(() => {
896
- expect(component.columns[0].editor).toBeTruthy();
897
- expect(component.columns[0].editor!.collection).toEqual(mockCollection);
898
- expect(component.columns[0].editor!.model).toEqual(Editors.text);
899
- expect(disableSpy).toHaveBeenCalledWith(false);
900
- expect(destroySpy).toHaveBeenCalled();
901
- expect(renderSpy).toHaveBeenCalledWith(mockCollection);
902
- done();
903
- });
904
- }));
905
- });
906
-
907
- describe('use grouping', () => {
908
- it('should load groupItemMetaProvider to the DataView when using "draggableGrouping" feature', () => {
909
- vi.spyOn(extensionServiceStub, 'extensionList', 'get').mockReturnValue({
910
- draggableGrouping: { pluginName: 'DraggableGrouping' },
911
- } as unknown as ExtensionList<any>);
912
-
913
- component.options = { draggableGrouping: {} };
914
- component.initialization(slickEventHandler);
915
-
916
- expect(SlickDataView).toHaveBeenCalledWith(
917
- expect.objectContaining({ inlineFilters: false, groupItemMetadataProvider: expect.anything() }),
918
- eventPubSubService
919
- );
920
- expect(sharedService.groupItemMetadataProvider instanceof SlickGroupItemMetadataProvider).toBeTruthy();
921
- expect(mockGrid.registerPlugin).toHaveBeenCalled();
922
-
923
- component.destroy();
924
- });
925
-
926
- it('should load groupItemMetaProvider to the DataView when using "enableGrouping" feature', () => {
927
- vi.spyOn(extensionServiceStub, 'extensionList', 'get').mockReturnValue({
928
- draggableGrouping: { pluginName: 'DraggableGrouping' },
929
- } as unknown as ExtensionList<any>);
930
-
931
- component.options = { enableGrouping: true, draggableGrouping: {} };
932
- component.initialization(slickEventHandler);
933
-
934
- expect(SlickDataView).toHaveBeenCalledWith(
935
- expect.objectContaining({ inlineFilters: false, groupItemMetadataProvider: expect.anything() }),
936
- eventPubSubService
937
- );
938
- expect(sharedService.groupItemMetadataProvider instanceof SlickGroupItemMetadataProvider).toBeTruthy();
939
- expect(mockGrid.registerPlugin).toHaveBeenCalled();
940
- });
941
- });
942
-
943
- describe('dataView options', () => {
944
- beforeEach(() => {
945
- component.options = gridOptions;
946
- });
947
-
948
- afterEach(() => {
949
- component.destroy();
950
- vi.clearAllMocks();
951
- sharedService.slickGrid = mockGrid as unknown as SlickGrid;
952
- });
953
-
954
- it('should call the onDataviewCreated emitter', () => {
955
- const pubSubSpy = vi.spyOn(eventPubSubService, 'publish');
956
- component.ngAfterViewInit();
957
- expect(pubSubSpy).toHaveBeenNthCalledWith(2, 'onDataviewCreated', expect.any(Object));
958
- });
959
-
960
- it('should call the "executeAfterDataviewCreated" and "loadGridSorters" methods and Sorter Presets are provided in the Grid Options', () => {
961
- const sortSpy = vi.spyOn(sortServiceStub, 'loadGridSorters');
962
-
963
- component.options = { presets: { sorters: [{ columnId: 'field1', direction: 'DESC' }] } } as unknown as GridOption;
964
- component.initialization(slickEventHandler);
965
-
966
- expect(sortSpy).toHaveBeenCalled();
967
- });
968
-
969
- it('should call the DataView "syncGridSelection" method with 2nd argument as True when the "dataView.syncGridSelection" grid option is enabled', () => {
970
- vi.spyOn(mockGrid, 'getSelectionModel').mockReturnValue(true as any);
971
- const syncSpy = vi.spyOn(mockDataView, 'syncGridSelection');
972
-
973
- component.options = { dataView: { syncGridSelection: true }, enableRowSelection: true } as unknown as GridOption;
974
- component.initialization(slickEventHandler);
975
-
976
- expect(syncSpy).toHaveBeenCalledWith(component.slickGrid, true);
977
- });
978
-
979
- it('should call the DataView "syncGridSelection" method with 2nd argument as False when the "dataView.syncGridSelection" grid option is disabled', () => {
980
- vi.spyOn(mockGrid, 'getSelectionModel').mockReturnValue(true as any);
981
- const syncSpy = vi.spyOn(mockDataView, 'syncGridSelection');
982
-
983
- component.options = { dataView: { syncGridSelection: false }, enableRowSelection: true } as unknown as GridOption;
984
- component.initialization(slickEventHandler);
985
-
986
- expect(syncSpy).toHaveBeenCalledWith(component.slickGrid, false);
987
- });
988
-
989
- it('should call the DataView "syncGridSelection" method with 3 arguments when the "dataView" grid option is provided as an object', () => {
990
- vi.spyOn(mockGrid, 'getSelectionModel').mockReturnValue(true as any);
991
- const syncSpy = vi.spyOn(mockDataView, 'syncGridSelection');
992
-
993
- component.options = {
994
- dataView: { syncGridSelection: { preserveHidden: true, preserveHiddenOnSelectionChange: false } },
995
- enableRowSelection: true,
996
- } as unknown as GridOption;
997
- component.initialization(slickEventHandler);
998
-
999
- expect(syncSpy).toHaveBeenCalledWith(component.slickGrid, true, false);
1000
- });
1001
-
1002
- it('should call the DataView "syncGridSelection" method when using BackendServiceApi and "syncGridSelectionWithBackendService" when the "dataView.syncGridSelection" grid option is enabled as well', () => {
1003
- vi.spyOn(mockGrid, 'getSelectionModel').mockReturnValue(true as any);
1004
- const syncSpy = vi.spyOn(mockDataView, 'syncGridSelection');
1005
-
1006
- component.options = {
1007
- backendServiceApi: {
1008
- service: mockGraphqlService,
1009
- process: vi.fn(),
1010
- },
1011
- dataView: { syncGridSelection: true, syncGridSelectionWithBackendService: true },
1012
- enableRowSelection: true,
1013
- } as unknown as GridOption;
1014
- component.initialization(slickEventHandler);
1015
-
1016
- expect(syncSpy).toHaveBeenCalledWith(component.slickGrid, true);
1017
- });
1018
-
1019
- it('should call the DataView "syncGridSelection" method with false as 2nd argument when using BackendServiceApi and "syncGridSelectionWithBackendService" BUT the "dataView.syncGridSelection" grid option is disabled', () => {
1020
- vi.spyOn(mockGrid, 'getSelectionModel').mockReturnValue(true as any);
1021
- const syncSpy = vi.spyOn(mockDataView, 'syncGridSelection');
1022
-
1023
- component.options = {
1024
- backendServiceApi: {
1025
- service: mockGraphqlService,
1026
- process: vi.fn(),
1027
- },
1028
- dataView: { syncGridSelection: false, syncGridSelectionWithBackendService: true },
1029
- enableRowSelection: true,
1030
- } as unknown as GridOption;
1031
- component.initialization(slickEventHandler);
1032
-
1033
- expect(syncSpy).toHaveBeenCalledWith(component.slickGrid, false);
1034
- });
1035
-
1036
- it('should call the DataView "syncGridSelection" method with false as 2nd argument when using BackendServiceApi and "syncGridSelectionWithBackendService" disabled and the "dataView.syncGridSelection" grid option is enabled', () => {
1037
- vi.spyOn(mockGrid, 'getSelectionModel').mockReturnValue(true as any);
1038
- const syncSpy = vi.spyOn(mockDataView, 'syncGridSelection');
1039
-
1040
- component.options = {
1041
- backendServiceApi: {
1042
- service: mockGraphqlService,
1043
- process: vi.fn(),
1044
- },
1045
- dataView: { syncGridSelection: true, syncGridSelectionWithBackendService: false },
1046
- enableRowSelection: true,
1047
- } as unknown as GridOption;
1048
- component.initialization(slickEventHandler);
1049
-
1050
- expect(syncSpy).toHaveBeenCalledWith(component.slickGrid, false);
1051
- });
1052
- });
1053
-
1054
- describe('flag checks', () => {
1055
- beforeEach(() => {
1056
- component.options = gridOptions;
1057
- });
1058
-
1059
- afterEach(() => {
1060
- vi.clearAllMocks();
1061
- component.destroy();
1062
- sharedService.slickGrid = mockGrid as unknown as SlickGrid;
1063
- });
1064
-
1065
- it('should call "showHeaderRow" method with false when its flag is disabled', () => {
1066
- const gridSpy = vi.spyOn(mockGrid, 'setHeaderRowVisibility');
1067
-
1068
- component.options = { showHeaderRow: false } as unknown as GridOption;
1069
- component.initialization(slickEventHandler);
1070
-
1071
- expect(gridSpy).toHaveBeenCalledWith(false);
1072
- });
1073
-
1074
- it('should initialize HeaderGroupingService when "createPreHeaderPanel" grid option is enabled and "enableDraggableGrouping" is disabled', () => {
1075
- const spy = vi.spyOn(headerGroupingServiceStub, 'init');
1076
-
1077
- component.options = { createPreHeaderPanel: true, enableDraggableGrouping: false } as unknown as GridOption;
1078
- component.initialization(slickEventHandler);
1079
-
1080
- expect(spy).toHaveBeenCalledWith(mockGrid, containerService);
1081
- });
1082
-
1083
- it('should not initialize HeaderGroupingService when "createPreHeaderPanel" grid option is enabled and "enableDraggableGrouping" is also enabled', () => {
1084
- const spy = vi.spyOn(headerGroupingServiceStub, 'init');
1085
-
1086
- component.options = { createPreHeaderPanel: true, enableDraggableGrouping: true } as unknown as GridOption;
1087
- component.initialization(slickEventHandler);
1088
-
1089
- expect(spy).not.toHaveBeenCalled();
1090
- });
1091
-
1092
- it('should create the Row Detail View plugin when "enableRowDetailView" is enabled', () => {
1093
- const initSpy = vi.spyOn(mockSlickRowDetailView, 'init');
1094
- const createSpy = vi.spyOn(mockSlickRowDetailView, 'create');
1095
- vi.spyOn(extensionServiceStub, 'extensionList', 'get').mockReturnValue({ rowDetailView: { pluginName: 'RowDetail' } } as unknown as ExtensionList<any>);
1096
-
1097
- component.options = { enableRowDetailView: true } as unknown as GridOption;
1098
- component.initialization(slickEventHandler);
1099
-
1100
- expect(extensionServiceStub.addExtensionToList).toHaveBeenCalledWith('rowDetailView', { name: 'rowDetailView', instance: mockSlickRowDetailView });
1101
- expect(component.registeredResources.length).toBe(3);
1102
- expect(component.extensionService.extensionList.rowDetailView).toBeTruthy();
1103
- expect(createSpy).toHaveBeenCalled();
1104
- expect(initSpy).toHaveBeenCalled();
1105
- });
1106
-
1107
- it('should call "translateColumnHeaders" from ExtensionService when "enableTranslate" is set', () => {
1108
- const spy = vi.spyOn(extensionServiceStub, 'translateColumnHeaders');
1109
-
1110
- component.options = { enableTranslate: true } as unknown as GridOption;
1111
- component.initialization(slickEventHandler);
1112
-
1113
- expect(spy).toHaveBeenCalled();
1114
- });
1115
-
1116
- it('should add RxJS resource to all necessary Services when RxJS external resource is registered', () => {
1117
- const rxjsMock = new RxJsResourceStub();
1118
- const backendUtilitySpy = vi.spyOn(backendUtilityServiceStub, 'addRxJsResource');
1119
- const filterServiceSpy = vi.spyOn(filterServiceStub, 'addRxJsResource');
1120
- const sortServiceSpy = vi.spyOn(sortServiceStub, 'addRxJsResource');
1121
- const paginationServiceSpy = vi.spyOn(paginationServiceStub, 'addRxJsResource');
1122
-
1123
- component.options = { externalResources: [rxjsMock] } as unknown as GridOption;
1124
- component.registerExternalResources([rxjsMock], true);
1125
- component.initialization(slickEventHandler);
1126
-
1127
- expect(backendUtilitySpy).toHaveBeenCalled();
1128
- expect(filterServiceSpy).toHaveBeenCalled();
1129
- expect(sortServiceSpy).toHaveBeenCalled();
1130
- expect(paginationServiceSpy).toHaveBeenCalled();
1131
- expect(component.registeredResources.length).toBe(4); // RxJsResourceStub, GridService, GridStateService, SlickEmptyCompositeEditorComponent
1132
- expect(component.registeredResources[0] instanceof RxJsResourceStub).toBe(true);
1133
- });
1134
-
1135
- it('should destroy component and its DOM element when requested', () => {
1136
- const spy = vi.spyOn(component, 'emptyGridContainerElm');
1137
-
1138
- component.initialization(slickEventHandler);
1139
- component.destroy(true);
1140
-
1141
- expect(spy).toHaveBeenCalledWith();
1142
- });
1143
-
1144
- it('should bind local filter when "enableFiltering" is set', () => {
1145
- const bindLocalSpy = vi.spyOn(filterServiceStub, 'bindLocalOnFilter');
1146
-
1147
- component.options = { enableFiltering: true } as unknown as GridOption;
1148
- component.initialization(slickEventHandler);
1149
-
1150
- expect(bindLocalSpy).toHaveBeenCalledWith(mockGrid);
1151
- });
1152
-
1153
- it('should bind local sort when "enableSorting" is set', () => {
1154
- const bindLocalSpy = vi.spyOn(sortServiceStub, 'bindLocalOnSort');
1155
-
1156
- component.options = { enableSorting: true } as unknown as GridOption;
1157
- component.initialization(slickEventHandler);
1158
-
1159
- expect(bindLocalSpy).toHaveBeenCalledWith(mockGrid);
1160
- });
1161
-
1162
- it('should refresh a local grid and change pagination options pagination when a preset for it is defined in grid options', () =>
1163
- new Promise((done: any) => {
1164
- const expectedPageNumber = 2;
1165
- const expectedTotalItems = 2;
1166
- const refreshSpy = vi.spyOn(component, 'refreshGridData');
1167
-
1168
- const mockData = [
1169
- { firstName: 'John', lastName: 'Doe' },
1170
- { firstName: 'Jane', lastName: 'Smith' },
1171
- ];
1172
- vi.spyOn(mockDataView, 'getItems').mockReturnValueOnce(mockData);
1173
- component.options = {
1174
- enablePagination: true,
1175
- presets: { pagination: { pageSize: 2, pageNumber: expectedPageNumber } },
1176
- };
1177
- component.paginationOptions = undefined;
1178
- component.paginationOptions = { pageSize: 2, pageNumber: 2, pageSizes: [2, 10, 25, 50], totalItems: 100 };
1179
-
1180
- component.dataset = mockData;
1181
- component.ngAfterViewInit();
1182
-
1183
- setTimeout(() => {
1184
- expect(component.options.pagination!.pageSize).toBe(2);
1185
- expect(component.options.pagination!.pageNumber).toBe(expectedPageNumber);
1186
- expect(component.options.pagination!.totalItems).toBe(expectedTotalItems);
1187
- expect(refreshSpy).toHaveBeenCalledWith(mockData);
1188
- done();
1189
- });
1190
- }));
1191
-
1192
- it('should refresh a local grid defined and change pagination options pagination when a preset is defined in grid options and total rows is different when Filters are applied', () =>
1193
- new Promise((done: any) => {
1194
- const expectedPageNumber = 3;
1195
- const expectedTotalItems = 15;
1196
- const refreshSpy = vi.spyOn(component, 'refreshGridData');
1197
- const getPagingSpy = vi.spyOn(mockDataView, 'getPagingInfo').mockReturnValue({ pageNum: 1, totalRows: expectedTotalItems } as any);
1198
-
1199
- const mockData = [
1200
- { firstName: 'John', lastName: 'Doe' },
1201
- { firstName: 'Jane', lastName: 'Smith' },
1202
- ];
1203
- component.options = {
1204
- enablePagination: true,
1205
- enableFiltering: true,
1206
- presets: { pagination: { pageSize: 10, pageNumber: expectedPageNumber } },
1207
- };
1208
- component.paginationOptions = { pageSize: 10, pageNumber: 2, pageSizes: [10, 25, 50], totalItems: 100 };
1209
-
1210
- component.ngAfterViewInit();
1211
- component.dataset = mockData;
1212
-
1213
- setTimeout(() => {
1214
- expect(getPagingSpy).toHaveBeenCalled();
1215
- expect(component.paginationOptions!.pageSize).toBe(10);
1216
- expect(component.paginationOptions!.pageNumber).toBe(expectedPageNumber);
1217
- expect(component.paginationOptions!.totalItems).toBe(expectedTotalItems);
1218
- expect(refreshSpy).toHaveBeenCalledWith(mockData);
1219
- done();
1220
- });
1221
- }));
1222
-
1223
- it('should be able to provide a Custom Pagination Component', () =>
1224
- new Promise((done: any) => {
1225
- const expectedPageNumber = 3;
1226
- const expectedTotalItems = 15;
1227
- const refreshSpy = vi.spyOn(component, 'refreshGridData');
1228
- const getPagingSpy = vi.spyOn(mockDataView, 'getPagingInfo').mockReturnValue({ pageNum: 1, totalRows: expectedTotalItems } as any);
1229
- const pagerInstance = new TestPaginationComponent();
1230
- vi.spyOn(angularUtilServiceStub, 'createAngularComponent').mockReturnValueOnce({
1231
- componentRef: { instance: pagerInstance } as any,
1232
- domElement: document.createElement('div'),
1233
- });
1234
-
1235
- const mockData = [
1236
- { firstName: 'John', lastName: 'Doe' },
1237
- { firstName: 'Jane', lastName: 'Smith' },
1238
- ];
1239
- component.options = {
1240
- enablePagination: true,
1241
- enableFiltering: true,
1242
- customPaginationComponent: TestPaginationComponent,
1243
- presets: { pagination: { pageSize: 10, pageNumber: expectedPageNumber } },
1244
- };
1245
- component.paginationOptions = { pageSize: 10, pageNumber: 2, pageSizes: [10, 25, 50], totalItems: 100 };
1246
-
1247
- component.ngAfterViewInit();
1248
- component.dataset = mockData;
1249
-
1250
- setTimeout(() => {
1251
- expect(getPagingSpy).toHaveBeenCalled();
1252
- expect(component.paginationOptions!.pageSize).toBe(10);
1253
- expect(component.paginationOptions!.pageNumber).toBe(expectedPageNumber);
1254
- expect(component.paginationOptions!.totalItems).toBe(expectedTotalItems);
1255
- expect(pagerInstance.init).toHaveBeenCalled();
1256
- expect(pagerInstance.renderPagination).toHaveBeenCalled();
1257
- expect(refreshSpy).toHaveBeenCalledWith(mockData);
1258
- done();
1259
- });
1260
- }));
1261
- });
1262
-
1263
- describe('Backend Service API', () => {
1264
- beforeEach(() => {
1265
- component.options = {
1266
- backendServiceApi: {
1267
- disableInternalPostProcess: false,
1268
- onInit: vi.fn(),
1269
- service: mockGraphqlService as any,
1270
- preProcess: vi.fn(),
1271
- postProcess: vi.fn(),
1272
- process: vi.fn(),
1273
- },
1274
- };
1275
- });
1276
-
1277
- afterEach(() => {
1278
- vi.clearAllMocks();
1279
- mockGraphqlService.options = undefined;
1280
- });
1281
-
1282
- it('should call the "createBackendApiInternalPostProcessCallback" method when Backend Service API is defined with a Graphql Service', () => {
1283
- const spy = vi.spyOn(component, 'createBackendApiInternalPostProcessCallback');
1284
-
1285
- component.initialization(slickEventHandler);
1286
-
1287
- expect(spy).toHaveBeenCalled();
1288
- expect(component.options.backendServiceApi!.internalPostProcess).toEqual(expect.any(Function));
1289
- });
1290
-
1291
- it('should NOT call the "createBackendApiInternalPostProcessCallback" method when Backend Service API is defined with a Graphql Service with "disableInternalPostProcess"', () => {
1292
- const spy = vi.spyOn(component, 'createBackendApiInternalPostProcessCallback');
1293
-
1294
- component.options.backendServiceApi!.disableInternalPostProcess = true;
1295
- component.initialization(slickEventHandler);
1296
-
1297
- expect(spy).not.toHaveBeenCalled();
1298
- expect(component.options.backendServiceApi!.internalPostProcess).toBeUndefined();
1299
- });
1300
-
1301
- it('should execute the "internalPostProcess" callback method that was created by "createBackendApiInternalPostProcessCallback" with Pagination', () => {
1302
- const getDataNameSpy = vi.spyOn(component.options.backendServiceApi!.service, 'getDatasetName');
1303
- (getDataNameSpy as Mock).mockReturnValue('users');
1304
- const spy = vi.spyOn(component, 'refreshGridData');
1305
-
1306
- component.initialization(slickEventHandler);
1307
- component.options.backendServiceApi!.internalPostProcess!({
1308
- data: { users: { nodes: [{ firstName: 'John' }], totalCount: 2 } },
1309
- } as GraphqlPaginatedResult);
1310
-
1311
- expect(spy).toHaveBeenCalled();
1312
- expect(component.options.backendServiceApi!.internalPostProcess).toEqual(expect.any(Function));
1313
- });
1314
-
1315
- it('should execute the "internalPostProcess" callback and expect totalItems to be updated in the PaginationService when "refreshGridData" is called on the 2nd time', () => {
1316
- const getDataNameSpy = vi.spyOn(component.options.backendServiceApi!.service, 'getDatasetName');
1317
- (getDataNameSpy as Mock).mockReturnValue('users');
1318
- const refreshSpy = vi.spyOn(component, 'refreshGridData');
1319
- const paginationSpy = vi.spyOn(paginationServiceStub, 'totalItems', 'set');
1320
- const mockDataset = [{ firstName: 'John' }, { firstName: 'Jane' }];
1321
-
1322
- component.initialization(slickEventHandler);
1323
- component.options.backendServiceApi!.internalPostProcess!({
1324
- data: { users: { nodes: mockDataset, totalCount: mockDataset.length } },
1325
- } as GraphqlPaginatedResult);
1326
- component.refreshGridData(mockDataset, 1);
1327
- component.refreshGridData(mockDataset, 1);
1328
-
1329
- expect(refreshSpy).toHaveBeenCalledTimes(3);
1330
- expect(paginationSpy).toHaveBeenCalledWith(2);
1331
- expect(component.options.backendServiceApi!.internalPostProcess).toEqual(expect.any(Function));
1332
- });
1333
-
1334
- it('should execute the "internalPostProcess" callback method that was created by "createBackendApiInternalPostProcessCallback" without Pagination (when disabled)', () => {
1335
- component.options.enablePagination = false;
1336
- const getDataNameSpy = vi.spyOn(component.options.backendServiceApi!.service, 'getDatasetName');
1337
- (getDataNameSpy as Mock).mockReturnValue('users');
1338
- const spy = vi.spyOn(component, 'refreshGridData');
1339
-
1340
- component.initialization(slickEventHandler);
1341
- component.options.backendServiceApi!.internalPostProcess!({ data: { users: [{ firstName: 'John' }] } } as unknown as GraphqlPaginatedResult);
1342
-
1343
- expect(spy).toHaveBeenCalled();
1344
- expect(component.options.backendServiceApi!.internalPostProcess).toEqual(expect.any(Function));
1345
- });
1346
-
1347
- it('should execute the "internalPostProcess" callback method but return an empty dataset when dataset name does not match "getDatasetName"', () => {
1348
- component.options.enablePagination = true;
1349
- const getDataNameSpy = vi.spyOn(component.options.backendServiceApi!.service, 'getDatasetName');
1350
- (getDataNameSpy as Mock).mockReturnValue('users');
1351
- const spy = vi.spyOn(component, 'refreshGridData');
1352
-
1353
- component.ngAfterViewInit();
1354
- component.options.backendServiceApi!.internalPostProcess!({
1355
- data: { notUsers: { nodes: [{ firstName: 'John' }], totalCount: 2 } },
1356
- } as GraphqlPaginatedResult);
1357
-
1358
- expect(spy).not.toHaveBeenCalled();
1359
- expect(component.dataset).toEqual([]);
1360
- });
1361
-
1362
- it('should invoke "updateFilters" method with filters returned from "getColumnFilters" of the Filter Service when there is no Presets defined', () => {
1363
- const mockColumnFilter = {
1364
- name: { columnId: 'name', columnDef: { id: 'name', field: 'name', filter: { model: Filters.autocompleter } }, operator: 'EQ', searchTerms: ['john'] },
1365
- };
1366
- vi.spyOn(filterServiceStub, 'getColumnFilters').mockReturnValue(mockColumnFilter as unknown as ColumnFilters);
1367
- const backendSpy = vi.spyOn(mockGraphqlService, 'updateFilters');
1368
-
1369
- component.options.presets = undefined;
1370
- component.initialization(slickEventHandler);
1371
-
1372
- expect(backendSpy).toHaveBeenCalledWith(mockColumnFilter, false);
1373
- });
1374
-
1375
- it('should override frozen grid options when "pinning" is defined in the "presets" property', () => {
1376
- const pinningMock = { frozenBottom: false, frozenColumn: -1, frozenRow: -1 } as CurrentPinning;
1377
-
1378
- component.options.presets = { pinning: pinningMock };
1379
- component.initialization(slickEventHandler);
1380
-
1381
- expect(component.options).toEqual({ ...component.options, ...pinningMock });
1382
- });
1383
-
1384
- it('should call the "updateFilters" method when filters are defined in the "presets" property', () => {
1385
- const spy = vi.spyOn(mockGraphqlService, 'updateFilters');
1386
- const mockFilters = [{ columnId: 'company', searchTerms: ['xyz'], operator: 'IN' }] as CurrentFilter[];
1387
- component.options.presets = { filters: mockFilters };
1388
- component.initialization(slickEventHandler);
1389
-
1390
- expect(spy).toHaveBeenCalledWith(mockFilters, true);
1391
- });
1392
-
1393
- it('should call the "updateSorters" method when sorters are defined in the "presets" property with multi-column sort enabled', () => {
1394
- vi.spyOn(mockGrid, 'getSelectionModel').mockReturnValue(true as any);
1395
- const spy = vi.spyOn(mockGraphqlService, 'updateSorters');
1396
- const mockSorters = [
1397
- { columnId: 'firstName', direction: 'asc' },
1398
- { columnId: 'lastName', direction: 'desc' },
1399
- ] as CurrentSorter[];
1400
- component.options.presets = { sorters: mockSorters };
1401
- component.initialization(slickEventHandler);
1402
-
1403
- expect(spy).toHaveBeenCalledWith(undefined, mockSorters);
1404
- });
1405
-
1406
- it('should call the "updateSorters" method with ONLY 1 column sort when multi-column sort is disabled and user provided multiple sorters in the "presets" property', () => {
1407
- vi.spyOn(mockGrid, 'getSelectionModel').mockReturnValue(true as any);
1408
- const spy = vi.spyOn(mockGraphqlService, 'updateSorters');
1409
- const mockSorters = [
1410
- { columnId: 'firstName', direction: 'asc' },
1411
- { columnId: 'lastName', direction: 'desc' },
1412
- ] as CurrentSorter[];
1413
-
1414
- component.options.multiColumnSort = false;
1415
- component.options.presets = { sorters: mockSorters };
1416
- component.initialization(slickEventHandler);
1417
-
1418
- expect(spy).toHaveBeenCalledWith(undefined, [mockSorters[0]]);
1419
- });
1420
-
1421
- it('should call the "updatePagination" method when filters are defined in the "presets" property', () => {
1422
- const spy = vi.spyOn(mockGraphqlService, 'updatePagination');
1423
-
1424
- component.options.presets = { pagination: { pageNumber: 2, pageSize: 20 } };
1425
- component.initialization(slickEventHandler);
1426
-
1427
- expect(spy).toHaveBeenCalledWith(2, 20);
1428
- });
1429
-
1430
- it('should refresh the grid and change pagination options pagination when a preset for it is defined in grid options', () => {
1431
- const expectedPageNumber = 3;
1432
- const refreshSpy = vi.spyOn(component, 'refreshGridData');
1433
-
1434
- const mockData = [
1435
- { firstName: 'John', lastName: 'Doe' },
1436
- { firstName: 'Jane', lastName: 'Smith' },
1437
- ];
1438
- component.options.enablePagination = true;
1439
- component.options.presets = { pagination: { pageSize: 10, pageNumber: expectedPageNumber } };
1440
- component.paginationOptions = { pageSize: 10, pageNumber: 1, pageSizes: [10, 25, 50], totalItems: 100 };
1441
-
1442
- component.initialization(slickEventHandler);
1443
- component.dataset = mockData;
1444
-
1445
- expect(component.options.pagination!.pageSize).toBe(10);
1446
- expect(component.options.pagination!.pageNumber).toBe(expectedPageNumber);
1447
- expect(refreshSpy).toHaveBeenCalledWith(mockData);
1448
- });
1449
-
1450
- it('should execute the process method on initialization when "executeProcessCommandOnInit" is set as a backend service options with a Promise and Pagination enabled', () =>
1451
- new Promise((done: any) => {
1452
- const now = new Date();
1453
- const query = `query { users (first:20,offset:0) { totalCount, nodes { id,name,gender,company } } }`;
1454
- const processResult = {
1455
- data: { users: { nodes: [] }, pageInfo: { hasNextPage: true }, totalCount: 0 },
1456
- metrics: { startTime: now, endTime: now, executionTime: 0, totalItemCount: 0 },
1457
- };
1458
- const promise = new Promise((resolve) => setTimeout(() => resolve(processResult), 1));
1459
- const processSpy = vi.spyOn(component.options.backendServiceApi as BackendServiceApi, 'process').mockReturnValue(promise);
1460
- vi.spyOn(component.options.backendServiceApi!.service, 'buildQuery').mockReturnValue(query);
1461
- const backendExecuteSpy = vi.spyOn(backendUtilityServiceStub, 'executeBackendProcessesCallback');
1462
-
1463
- component.options.backendServiceApi!.service.options = { executeProcessCommandOnInit: true };
1464
- component.initialization(slickEventHandler);
1465
-
1466
- expect(processSpy).toHaveBeenCalled();
1467
-
1468
- setTimeout(() => {
1469
- expect(backendExecuteSpy).toHaveBeenCalledWith(expect.any(Date), processResult, component.options.backendServiceApi as BackendServiceApi, 0);
1470
- done();
1471
- }, 5);
1472
- }));
1473
-
1474
- it('should execute the process method on initialization when "executeProcessCommandOnInit" is set as a backend service options with an Observable and Pagination enabled', () =>
1475
- new Promise((done: any) => {
1476
- const now = new Date();
1477
- const rxjsMock = new RxJsResourceStub();
1478
- const query = `query { users (first:20,offset:0) { totalCount, nodes { id,name,gender,company } } }`;
1479
- const processResult = {
1480
- data: { users: { nodes: [] }, pageInfo: { hasNextPage: true }, totalCount: 0 },
1481
- metrics: { startTime: now, endTime: now, executionTime: 0, totalItemCount: 0 },
1482
- };
1483
- const processSpy = vi.spyOn((component.options as GridOption).backendServiceApi as BackendServiceApi, 'process').mockReturnValue(of(processResult));
1484
- vi.spyOn((component.options as GridOption).backendServiceApi!.service, 'buildQuery').mockReturnValue(query);
1485
- const backendExecuteSpy = vi.spyOn(backendUtilityServiceStub, 'executeBackendProcessesCallback');
1486
-
1487
- component.options.externalResources = [rxjsMock];
1488
- component.registerExternalResources([rxjsMock], true);
1489
- component.options.backendServiceApi!.service.options = { executeProcessCommandOnInit: true };
1490
- component.initialization(slickEventHandler);
1491
-
1492
- expect(processSpy).toHaveBeenCalled();
1493
-
1494
- setTimeout(() => {
1495
- expect(backendExecuteSpy).toHaveBeenCalledWith(expect.any(Date), processResult, component.options.backendServiceApi as BackendServiceApi, 0);
1496
- done();
1497
- }, 5);
1498
- }));
1499
-
1500
- it('should execute the process method on initialization when "executeProcessCommandOnInit" is set as a backend service options without Pagination (when disabled)', () =>
1501
- new Promise((done: any) => {
1502
- const now = new Date();
1503
- const query = `query { users { id,name,gender,company } }`;
1504
- const processResult = {
1505
- data: { users: [] },
1506
- metrics: { startTime: now, endTime: now, executionTime: 0, totalItemCount: 0 },
1507
- };
1508
- const promise = new Promise((resolve) => setTimeout(() => resolve(processResult), 1));
1509
- const processSpy = vi.spyOn(component.options.backendServiceApi as BackendServiceApi, 'process').mockReturnValue(promise);
1510
- vi.spyOn(component.options.backendServiceApi!.service, 'buildQuery').mockReturnValue(query);
1511
- const backendExecuteSpy = vi.spyOn(backendUtilityServiceStub, 'executeBackendProcessesCallback');
1512
-
1513
- component.options.backendServiceApi!.service.options = { executeProcessCommandOnInit: true };
1514
- component.initialization(slickEventHandler);
1515
-
1516
- expect(processSpy).toHaveBeenCalled();
1517
-
1518
- setTimeout(() => {
1519
- expect(backendExecuteSpy).toHaveBeenCalledWith(expect.any(Date), processResult, component.options.backendServiceApi as BackendServiceApi, 0);
1520
- done();
1521
- }, 5);
1522
- }));
1523
-
1524
- it('should throw an error when the process method on initialization when "executeProcessCommandOnInit" is set as a backend service options', () =>
1525
- new Promise((done: any) => {
1526
- const mockError = { error: '404' };
1527
- const query = `query { users (first:20,offset:0) { totalCount, nodes { id,name,gender,company } } }`;
1528
- const promise = new Promise((_resolve, reject) => setTimeout(() => reject(mockError), 1));
1529
- const processSpy = vi.spyOn(component.options.backendServiceApi as BackendServiceApi, 'process').mockReturnValue(promise);
1530
- vi.spyOn(component.options.backendServiceApi!.service, 'buildQuery').mockReturnValue(query);
1531
-
1532
- component.options.backendServiceApi!.service.options = { executeProcessCommandOnInit: true };
1533
- component.initialization(slickEventHandler);
1534
-
1535
- expect(processSpy).toHaveBeenCalled();
1536
-
1537
- promise.catch((e) => {
1538
- expect(e).toEqual(mockError);
1539
- done();
1540
- });
1541
- }));
1542
- });
1543
-
1544
- describe('commitEdit method', () => {
1545
- beforeEach(() => {
1546
- component.options = {
1547
- backendServiceApi: {
1548
- onInit: vi.fn(),
1549
- service: mockGraphqlService as any,
1550
- preProcess: vi.fn(),
1551
- postProcess: vi.fn(),
1552
- process: vi.fn(),
1553
- },
1554
- };
1555
- });
1556
-
1557
- it('should throw an error when the process method on initialization when "executeProcessCommandOnInit" is set as a backend service options from an Observable', () =>
1558
- new Promise((done: any) => {
1559
- const mockError = { error: '404' };
1560
- const rxjsMock = new RxJsResourceStub();
1561
- const query = `query { users (first:20,offset:0) { totalCount, nodes { id,name,gender,company } } }`;
1562
- const processSpy = vi.spyOn(component.options.backendServiceApi as BackendServiceApi, 'process').mockReturnValue(throwError(mockError));
1563
- vi.spyOn(component.options.backendServiceApi!.service, 'buildQuery').mockReturnValue(query);
1564
- const backendErrorSpy = vi.spyOn(backendUtilityServiceStub, 'onBackendError');
1565
-
1566
- component.options.externalResources = [rxjsMock];
1567
- component.resetExternalResources();
1568
- component.registerExternalResources([rxjsMock], true);
1569
- component.options.backendServiceApi!.service.options = { executeProcessCommandOnInit: true };
1570
- component.initialization(slickEventHandler);
1571
-
1572
- expect(processSpy).toHaveBeenCalled();
1573
-
1574
- setTimeout(() => {
1575
- expect(backendErrorSpy).toHaveBeenCalledWith(mockError, component.options.backendServiceApi);
1576
- done();
1577
- });
1578
- }));
1579
-
1580
- it('should call "onScrollEnd" when defined and call backend util setInfiniteScrollBottomHit(true) when we still have more pages in the dataset', () =>
1581
- new Promise((done: any) => {
1582
- const gotoSpy = vi.spyOn(component.paginationService, 'goToNextPage').mockResolvedValueOnce(true);
1583
- component.options.backendServiceApi!.service.options = { infiniteScroll: true };
1584
- component.initialization(slickEventHandler);
1585
- component.options.backendServiceApi?.onScrollEnd!();
1586
-
1587
- expect(gotoSpy).toHaveBeenCalled();
1588
- expect(component.backendUtilityService.setInfiniteScrollBottomHit).toHaveBeenCalledWith(true);
1589
- component.options.backendServiceApi!.service.options.infiniteScroll = false;
1590
- setTimeout(() => {
1591
- expect(component.backendUtilityService.setInfiniteScrollBottomHit).not.toHaveBeenCalledWith(false);
1592
- done();
1593
- });
1594
- }));
1595
-
1596
- it('should execute original "postProcess" when calling the same method when Infinite Scroll is enabled', () => {
1597
- const orgPostProcess = component.options.backendServiceApi!.postProcess;
1598
- component.options.backendServiceApi!.service.options = { infiniteScroll: true };
1599
- component.initialization(slickEventHandler);
1600
- component.options.backendServiceApi?.postProcess!({ infiniteScrollBottomHit: true, query: '', value: [] });
1601
-
1602
- expect(orgPostProcess).toHaveBeenCalled();
1603
- });
1604
-
1605
- it('should call "onScrollEnd" when defined and call backend util setInfiniteScrollBottomHit(false) when we no longer have more pages', () =>
1606
- new Promise((done: any) => {
1607
- const gotoSpy = vi.spyOn(component.paginationService, 'goToNextPage').mockResolvedValueOnce(false);
1608
- component.options.backendServiceApi!.service.options = { infiniteScroll: true };
1609
- component.initialization(slickEventHandler);
1610
- component.options.backendServiceApi?.onScrollEnd!();
1611
-
1612
- expect(gotoSpy).toHaveBeenCalled();
1613
- expect(component.backendUtilityService.setInfiniteScrollBottomHit).toHaveBeenCalledWith(true);
1614
- component.options.backendServiceApi!.service.options.infiniteScroll = false;
1615
- setTimeout(() => {
1616
- expect(component.backendUtilityService.setInfiniteScrollBottomHit).toHaveBeenCalledWith(false);
1617
- done();
1618
- });
1619
- }));
1620
-
1621
- it('should throw an error if we try to set a "presets.pagination" with Infinite Scroll', () => {
1622
- const consoleSpy = vi.spyOn(console, 'warn').mockReturnValue();
1623
- mockGraphqlService.options = { datasetName: 'users', infiniteScroll: true };
1624
- const backendServiceApi = {
1625
- service: mockGraphqlService,
1626
- process: vi.fn(),
1627
- };
1628
-
1629
- gridOptions = {
1630
- enablePagination: true,
1631
- backendServiceApi,
1632
- presets: { pagination: { pageNumber: 2 } },
1633
- pagination: { pageSizes: [10, 20], pageSize: 10 },
1634
- } as unknown as GridOption;
1635
- component.initialization(slickEventHandler);
1636
- vi.spyOn(component.slickGrid!, 'getOptions').mockReturnValue(gridOptions);
1637
- component.options = gridOptions;
1638
- component.initialization(slickEventHandler);
1639
- component.refreshGridData([]);
1640
-
1641
- expect(consoleSpy).toHaveBeenCalledWith('[Angular-Slickgrid] `presets.pagination` is not supported with Infinite Scroll, reverting to first page.');
1642
- });
1643
-
1644
- it('should execute onScrollEnd callback when SlickGrid onScroll is triggered with a "mousewheel" event', () => {
1645
- vi.spyOn(component.paginationService, 'goToNextPage').mockResolvedValueOnce(false);
1646
- component.options.backendServiceApi!.service.options = { infiniteScroll: true };
1647
- component.initialization(slickEventHandler);
1648
- vi.spyOn(paginationServiceStub, 'totalItems', 'get').mockReturnValue(100);
1649
- const mouseEvent = addVanillaEventPropagation(new Event('scroll'));
1650
- mockGrid.onScroll.notify({ scrollHeight: 10, scrollTop: 10, scrollLeft: 15, grid: mockGrid, triggeredBy: 'mousewheel' }, mouseEvent, mockGrid);
1651
-
1652
- expect(component.backendUtilityService.setInfiniteScrollBottomHit).toHaveBeenCalledWith(true);
1653
- });
1654
-
1655
- it('should execute onScrollEnd callback when SlickGrid onScroll is triggered with a "scroll" event', () => {
1656
- vi.spyOn(component.paginationService, 'goToNextPage').mockResolvedValueOnce(false);
1657
- component.options.backendServiceApi!.service.options = { infiniteScroll: true };
1658
- component.initialization(slickEventHandler);
1659
- vi.spyOn(paginationServiceStub, 'totalItems', 'get').mockReturnValue(100);
1660
- const scrollEvent = addVanillaEventPropagation(new Event('scroll'));
1661
- mockGrid.onScroll.notify({ scrollHeight: 10, scrollTop: 10, scrollLeft: 15, grid: mockGrid, triggeredBy: 'scroll' }, scrollEvent, mockGrid);
1662
-
1663
- expect(component.backendUtilityService.setInfiniteScrollBottomHit).toHaveBeenCalledWith(true);
1664
- });
1665
-
1666
- it('should NOT execute onScrollEnd callback when SlickGrid onScroll is triggered with an event that is NOT "mousewheel" neither "scroll"', () => {
1667
- vi.spyOn(component.paginationService, 'goToNextPage').mockResolvedValueOnce(false);
1668
- component.options.backendServiceApi!.service.options = { infiniteScroll: true };
1669
- component.initialization(slickEventHandler);
1670
- vi.spyOn(paginationServiceStub, 'totalItems', 'get').mockReturnValue(100);
1671
- const clickEvent = addVanillaEventPropagation(new Event('click'));
1672
- mockGrid.onScroll.notify({ scrollHeight: 10, scrollTop: 10, scrollLeft: 15, grid: mockGrid, triggeredBy: 'scroll' }, clickEvent, mockGrid);
1673
-
1674
- expect(component.backendUtilityService.setInfiniteScrollBottomHit).toHaveBeenCalledWith(true);
1675
- });
1676
- });
1677
-
1678
- describe('bindDifferentHooks private method called by "attached"', () => {
1679
- beforeEach(() => {
1680
- component.columns = [{ id: 'firstName', field: 'firstName' }];
1681
- });
1682
-
1683
- afterEach(() => {
1684
- vi.clearAllMocks();
1685
- });
1686
-
1687
- it('should call multiple translate methods when locale changes', () =>
1688
- new Promise((done: any) => {
1689
- const transAllExtSpy = vi.spyOn(extensionServiceStub, 'translateAllExtensions');
1690
- const transGroupingColSpanSpy = vi.spyOn(headerGroupingServiceStub, 'translateHeaderGrouping');
1691
- const setHeaderRowSpy = vi.spyOn(mockGrid, 'setHeaderRowVisibility');
1692
-
1693
- component.options = {
1694
- enableTranslate: true,
1695
- createPreHeaderPanel: false,
1696
- enableDraggableGrouping: false,
1697
- showCustomFooter: true,
1698
- } as unknown as GridOption;
1699
- component.initialization(slickEventHandler);
1700
-
1701
- translate.use('fr');
1702
-
1703
- setTimeout(() => {
1704
- expect(setHeaderRowSpy).not.toHaveBeenCalled();
1705
- expect(transGroupingColSpanSpy).not.toHaveBeenCalled();
1706
- expect(transAllExtSpy).toHaveBeenCalled();
1707
- done();
1708
- });
1709
- }));
1710
-
1711
- it('should call "setHeaderRowVisibility", "translateHeaderGrouping" and other methods when locale changes', () =>
1712
- new Promise((done: any) => {
1713
- component.columns = [{ id: 'firstName', field: 'firstName', filterable: true }];
1714
- const transAllExtSpy = vi.spyOn(extensionServiceStub, 'translateAllExtensions');
1715
- const transGroupingColSpanSpy = vi.spyOn(headerGroupingServiceStub, 'translateHeaderGrouping');
1716
-
1717
- component.options = { enableTranslate: true, createPreHeaderPanel: true, enableDraggableGrouping: false } as unknown as GridOption;
1718
- component.initialization(slickEventHandler);
1719
-
1720
- translate.use('en');
1721
-
1722
- setTimeout(() => {
1723
- expect(transGroupingColSpanSpy).toHaveBeenCalled();
1724
- expect(transAllExtSpy).toHaveBeenCalled();
1725
- done();
1726
- });
1727
- }));
1728
-
1729
- it('should call "translateHeaderGrouping" translate methods when locale changes and Column Grouping PreHeader are enabled', () =>
1730
- new Promise((done: any) => {
1731
- const groupColSpanSpy = vi.spyOn(headerGroupingServiceStub, 'translateHeaderGrouping');
1732
-
1733
- component.options = { enableTranslate: true, createPreHeaderPanel: true, enableDraggableGrouping: false } as unknown as GridOption;
1734
- component.initialization(slickEventHandler);
1735
-
1736
- translate.use('en');
1737
-
1738
- setTimeout(() => {
1739
- expect(groupColSpanSpy).toHaveBeenCalled();
1740
- done();
1741
- });
1742
- }));
1743
-
1744
- it('should reflect columns in the grid', () => {
1745
- const mockColsPresets = [{ columnId: 'firstName', width: 100 }];
1746
- const mockCols = [{ id: 'firstName', field: 'firstName' }];
1747
- const getAssocColSpy = vi.spyOn(gridStateServiceStub, 'getAssociatedGridColumns').mockReturnValue(mockCols);
1748
- const setColSpy = vi.spyOn(mockGrid, 'setColumns');
1749
-
1750
- component.options = { presets: { columns: mockColsPresets } } as unknown as GridOption;
1751
- component.initialization(slickEventHandler);
1752
-
1753
- expect(getAssocColSpy).toHaveBeenCalledWith(mockGrid, mockColsPresets);
1754
- expect(setColSpy).toHaveBeenCalledWith(mockCols);
1755
- });
1756
-
1757
- it('should reflect columns with an extra checkbox selection column in the grid when "enableCheckboxSelector" is set', () => {
1758
- const mockColsPresets = [{ columnId: 'firstName', width: 100 }];
1759
- const mockCol = { id: 'firstName', field: 'firstName' };
1760
- const mockCols = [{ id: '_checkbox_selector', field: '_checkbox_selector', editor: undefined }, mockCol];
1761
- const getAssocColSpy = vi.spyOn(gridStateServiceStub, 'getAssociatedGridColumns').mockReturnValue([mockCol]);
1762
- const setColSpy = vi.spyOn(mockGrid, 'setColumns');
1763
-
1764
- component.columns = mockCols;
1765
- component.options = { ...gridOptions, enableCheckboxSelector: true, presets: { columns: mockColsPresets } } as unknown as GridOption;
1766
- component.initialization(slickEventHandler);
1767
-
1768
- expect(getAssocColSpy).toHaveBeenCalledWith(mockGrid, mockColsPresets);
1769
- expect(setColSpy).toHaveBeenCalledWith(mockCols);
1770
- });
1771
-
1772
- it('should reflect columns with an extra row detail column in the grid when "enableRowDetailView" is set', () => {
1773
- const mockColsPresets = [{ columnId: 'firstName', width: 100 }];
1774
- const mockCol = { id: 'firstName', field: 'firstName' };
1775
- const mockCols = [{ id: '_detail_selector', field: '_detail_selector', editor: undefined }, mockCol];
1776
- const getAssocColSpy = vi.spyOn(gridStateServiceStub, 'getAssociatedGridColumns').mockReturnValue([mockCol]);
1777
- const setColSpy = vi.spyOn(mockGrid, 'setColumns');
1778
-
1779
- component.columns = mockCols;
1780
- component.options = { ...gridOptions, enableRowDetailView: true, presets: { columns: mockColsPresets } } as unknown as GridOption;
1781
- component.initialization(slickEventHandler);
1782
-
1783
- expect(getAssocColSpy).toHaveBeenCalledWith(mockGrid, mockColsPresets);
1784
- expect(setColSpy).toHaveBeenCalledWith(mockCols);
1785
- });
1786
-
1787
- it('should reflect columns with an extra row move column in the grid when "enableRowMoveManager" is set', () => {
1788
- const mockColsPresets = [{ columnId: 'firstName', width: 100 }];
1789
- const mockCol = { id: 'firstName', field: 'firstName' };
1790
- const mockCols = [{ id: '_move', field: '_move', editor: undefined }, mockCol];
1791
- const getAssocColSpy = vi.spyOn(gridStateServiceStub, 'getAssociatedGridColumns').mockReturnValue([mockCol]);
1792
- const setColSpy = vi.spyOn(mockGrid, 'setColumns');
1793
-
1794
- component.columns = mockCols;
1795
- component.options = { ...gridOptions, enableRowMoveManager: true, presets: { columns: mockColsPresets } } as unknown as GridOption;
1796
- component.initialization(slickEventHandler);
1797
-
1798
- expect(getAssocColSpy).toHaveBeenCalledWith(mockGrid, mockColsPresets);
1799
- expect(setColSpy).toHaveBeenCalledWith(mockCols);
1800
- });
1801
-
1802
- it('should reflect 3 dynamic columns (1-RowMove, 2-RowSelection, 3-RowDetail) when all associated extension flags are enabled', () => {
1803
- const mockColsPresets = [{ columnId: 'firstName', width: 100 }];
1804
- const mockCol = { id: 'firstName', field: 'firstName' };
1805
- const mockCols = [
1806
- { id: '_move', field: '_move', editor: undefined },
1807
- { id: '_checkbox_selector', field: '_checkbox_selector', editor: undefined },
1808
- { id: '_detail_selector', field: '_detail_selector', editor: undefined },
1809
- mockCol,
1810
- ];
1811
- const getAssocColSpy = vi.spyOn(gridStateServiceStub, 'getAssociatedGridColumns').mockReturnValue([mockCol]);
1812
- const setColSpy = vi.spyOn(mockGrid, 'setColumns');
1813
-
1814
- component.columns = mockCols;
1815
- component.options = {
1816
- ...gridOptions,
1817
- enableCheckboxSelector: true,
1818
- enableRowDetailView: true,
1819
- enableRowMoveManager: true,
1820
- presets: { columns: mockColsPresets },
1821
- } as unknown as GridOption;
1822
- component.initialization(slickEventHandler);
1823
-
1824
- expect(getAssocColSpy).toHaveBeenCalledWith(mockGrid, mockColsPresets);
1825
- expect(setColSpy).toHaveBeenCalledWith(mockCols);
1826
- });
1827
-
1828
- it('should execute backend service "init" method when set', () => {
1829
- const mockPagination = { pageNumber: 1, pageSizes: [10, 25, 50], pageSize: 10, totalItems: 100 };
1830
- const mockGraphqlOptions = { datasetName: 'users', extraQueryArguments: [{ field: 'userId', value: 123 }] } as GraphqlServiceOption;
1831
- const bindBackendSpy = vi.spyOn(sortServiceStub, 'bindBackendOnSort');
1832
- const mockGraphqlService2 = { ...mockGraphqlService, init: vi.fn() } as unknown as GraphqlService;
1833
- const initSpy = vi.spyOn(mockGraphqlService2, 'init');
1834
-
1835
- component.options = {
1836
- backendServiceApi: {
1837
- service: mockGraphqlService2,
1838
- options: mockGraphqlOptions,
1839
- preProcess: () => vi.fn(),
1840
- process: () => new Promise((resolve) => resolve({ data: { users: { nodes: [], totalCount: 100 } } })),
1841
- } as GraphqlServiceApi,
1842
- pagination: mockPagination,
1843
- } as unknown as GridOption;
1844
- component.initialization(slickEventHandler);
1845
-
1846
- expect(bindBackendSpy).toHaveBeenCalledWith(mockGrid);
1847
- expect(initSpy).toHaveBeenCalledWith(mockGraphqlOptions, mockPagination, mockGrid, sharedService);
1848
- });
1849
-
1850
- it('should call bind backend sorting when "enableSorting" is set', () => {
1851
- const bindBackendSpy = vi.spyOn(sortServiceStub, 'bindBackendOnSort');
1852
-
1853
- component.options = {
1854
- enableSorting: true,
1855
- backendServiceApi: {
1856
- service: mockGraphqlService,
1857
- preProcess: () => vi.fn(),
1858
- process: () => new Promise((resolve) => resolve('process resolved')),
1859
- },
1860
- } as unknown as GridOption;
1861
- component.initialization(slickEventHandler);
1862
-
1863
- expect(bindBackendSpy).toHaveBeenCalledWith(mockGrid);
1864
- });
1865
-
1866
- it('should call bind local sorting when "enableSorting" is set and "useLocalSorting" is set as well', () => {
1867
- const bindLocalSpy = vi.spyOn(sortServiceStub, 'bindLocalOnSort');
1868
-
1869
- component.options = {
1870
- enableSorting: true,
1871
- backendServiceApi: {
1872
- service: mockGraphqlService,
1873
- useLocalSorting: true,
1874
- preProcess: () => vi.fn(),
1875
- process: () => new Promise((resolve) => resolve('process resolved')),
1876
- },
1877
- } as unknown as GridOption;
1878
- component.initialization(slickEventHandler);
1879
-
1880
- expect(bindLocalSpy).toHaveBeenCalledWith(mockGrid);
1881
- });
1882
-
1883
- it('should call bind backend filtering when "enableFiltering" is set', () => {
1884
- const initSpy = vi.spyOn(filterServiceStub, 'init');
1885
- const bindLocalSpy = vi.spyOn(filterServiceStub, 'bindLocalOnFilter');
1886
- const populateSpy = vi.spyOn(filterServiceStub, 'populateColumnFilterSearchTermPresets');
1887
-
1888
- component.options = { enableFiltering: true } as unknown as GridOption;
1889
- component.initialization(slickEventHandler);
1890
-
1891
- expect(initSpy).toHaveBeenCalledWith(mockGrid);
1892
- expect(bindLocalSpy).toHaveBeenCalledWith(mockGrid);
1893
- expect(populateSpy).not.toHaveBeenCalled();
1894
- });
1895
-
1896
- it('should call bind local filtering when "enableFiltering" is set and "useLocalFiltering" is set as well', () => {
1897
- const bindLocalSpy = vi.spyOn(filterServiceStub, 'bindLocalOnFilter');
1898
-
1899
- component.options = {
1900
- enableFiltering: true,
1901
- backendServiceApi: {
1902
- service: mockGraphqlService,
1903
- useLocalFiltering: true,
1904
- preProcess: () => vi.fn(),
1905
- process: () => new Promise((resolve) => resolve('process resolved')),
1906
- },
1907
- } as unknown as GridOption;
1908
- component.initialization(slickEventHandler);
1909
-
1910
- expect(bindLocalSpy).toHaveBeenCalledWith(mockGrid);
1911
- });
1912
-
1913
- it('should reflect column filters when "enableFiltering" is set', () => {
1914
- const initSpy = vi.spyOn(filterServiceStub, 'init');
1915
- const bindBackendSpy = vi.spyOn(filterServiceStub, 'bindBackendOnFilter');
1916
- const populateSpy = vi.spyOn(filterServiceStub, 'populateColumnFilterSearchTermPresets');
1917
-
1918
- component.options = {
1919
- enableFiltering: true,
1920
- backendServiceApi: {
1921
- service: mockGraphqlService,
1922
- preProcess: () => vi.fn(),
1923
- process: () => new Promise((resolve) => resolve('process resolved')),
1924
- },
1925
- } as unknown as GridOption;
1926
- component.initialization(slickEventHandler);
1927
-
1928
- expect(initSpy).toHaveBeenCalledWith(mockGrid);
1929
- expect(bindBackendSpy).toHaveBeenCalledWith(mockGrid);
1930
- expect(populateSpy).not.toHaveBeenCalled();
1931
- });
1932
-
1933
- it('should reflect column filters and populate filter search terms when "enableFiltering" is set and preset filters are defined', () => {
1934
- const mockPresetFilters = [{ columnId: 'firstName', operator: 'IN', searchTerms: ['John', 'Jane'] }] as CurrentFilter[];
1935
- const initSpy = vi.spyOn(filterServiceStub, 'init');
1936
- const populateSpy = vi.spyOn(filterServiceStub, 'populateColumnFilterSearchTermPresets');
1937
-
1938
- component.options = { enableFiltering: true, presets: { filters: mockPresetFilters } } as unknown as GridOption;
1939
- component.initialization(slickEventHandler);
1940
-
1941
- expect(initSpy).toHaveBeenCalledWith(mockGrid);
1942
- expect(populateSpy).toHaveBeenCalledWith(mockPresetFilters);
1943
- });
1944
-
1945
- it('should update each row and re-render the grid when filtering and DataView "onRowsChanged" event is triggered', () => {
1946
- const renderSpy = vi.spyOn(mockGrid, 'render');
1947
- const updateRowSpy = vi.spyOn(mockGrid, 'updateRow');
1948
- vi.spyOn(mockGrid, 'getRenderedRange').mockReturnValue({ bottom: 10, top: 0, leftPx: 0, rightPx: 890 });
1949
-
1950
- component.options = { enableFiltering: true };
1951
- component.initialization(slickEventHandler);
1952
- mockDataView.onRowsChanged.notify({ rows: [1, 2, 3] } as any);
1953
-
1954
- expect(component.eventHandler).toEqual(slickEventHandler);
1955
- expect(renderSpy).toHaveBeenCalled();
1956
- expect(updateRowSpy).toHaveBeenCalledTimes(3);
1957
- });
1958
-
1959
- it('should call invalidateRows individually when Row Detail is enabled and changed rows is different than the rows count', () => {
1960
- const renderSpy = vi.spyOn(mockGrid, 'render');
1961
- const invalidateRowSpy = vi.spyOn(mockGrid, 'invalidateRows');
1962
- vi.spyOn(mockGrid, 'getRenderedRange').mockReturnValue({ bottom: 10, top: 0, leftPx: 0, rightPx: 890 });
1963
-
1964
- component.options.enableRowDetailView = true;
1965
- component.initialization(slickEventHandler);
1966
- mockDataView.onRowCountChanged.notify({
1967
- current: 2,
1968
- previous: 0,
1969
- dataView: mockDataView,
1970
- changedRows: [1, 2],
1971
- itemCount: 5,
1972
- callingOnRowsChanged: false,
1973
- });
1974
-
1975
- expect(component.eventHandler).toEqual(slickEventHandler);
1976
- expect(invalidateRowSpy).toHaveBeenCalled();
1977
- expect(renderSpy).toHaveBeenCalled();
1978
- });
1979
- });
1980
-
1981
- describe('setHeaderRowVisibility grid method', () => {
1982
- beforeEach(() => {
1983
- vi.clearAllMocks();
1984
- component.options = gridOptions;
1985
- });
1986
-
1987
- it('should show the header row when "showHeaderRow" is called with argument True', () => {
1988
- const setHeaderRowSpy = vi.spyOn(mockGrid, 'setHeaderRowVisibility');
1989
- const setColumnSpy = vi.spyOn(mockGrid, 'setColumns');
1990
-
1991
- component.ngAfterViewInit();
1992
- component.showHeaderRow(true);
1993
-
1994
- expect(setHeaderRowSpy).toHaveBeenCalledWith(true);
1995
- expect(setColumnSpy).toHaveBeenCalledTimes(1);
1996
- });
1997
-
1998
- it('should show the header row when "showHeaderRow" is called with argument False', () => {
1999
- const setHeaderRowSpy = vi.spyOn(mockGrid, 'setHeaderRowVisibility');
2000
- const setColumnSpy = vi.spyOn(mockGrid, 'setColumns');
2001
-
2002
- component.ngAfterViewInit();
2003
- component.showHeaderRow(false);
2004
-
2005
- expect(setHeaderRowSpy).toHaveBeenCalledWith(false);
2006
- expect(setColumnSpy).not.toHaveBeenCalled();
2007
- });
2008
- });
2009
-
2010
- describe('pagination events', () => {
2011
- beforeEach(() => {
2012
- vi.clearAllMocks();
2013
- component.options = gridOptions;
2014
- });
2015
-
2016
- it('should call trigger a gridStage change event when pagination change is triggered', () => {
2017
- const mockPagination = { pageNumber: 2, pageSize: 20 } as Pagination;
2018
- const pluginEaSpy = vi.spyOn(eventPubSubService, 'publish');
2019
- vi.spyOn(gridStateServiceStub, 'getCurrentGridState').mockReturnValue({ columns: [], pagination: mockPagination } as GridState);
2020
-
2021
- component.initialization(slickEventHandler);
2022
- component.paginationChanged(mockPagination);
2023
-
2024
- expect(pluginEaSpy).toHaveBeenCalledWith('onGridStateChanged', {
2025
- change: { newValues: mockPagination, type: 'pagination' },
2026
- gridState: { columns: [], pagination: mockPagination },
2027
- });
2028
- });
2029
-
2030
- it('should call trigger a gridStage change event when "onPaginationChanged" from the Pagination Service is triggered', () => {
2031
- const pubSubSpy = vi.spyOn(eventPubSubService, 'publish');
2032
- const mockPagination = { pageNumber: 2, pageSize: 20 } as CurrentPagination;
2033
- const mockPaginationMetadata = {
2034
- ...mockPagination,
2035
- dataFrom: 5,
2036
- dataTo: 10,
2037
- pageCount: 1,
2038
- pageSizes: [5, 10, 15, 20],
2039
- } as PaginationMetadata;
2040
- vi.spyOn(gridStateServiceStub, 'getCurrentGridState').mockReturnValue({ columns: [], pagination: mockPagination } as GridState);
2041
-
2042
- component.options.enablePagination = true;
2043
- component.initialization(slickEventHandler);
2044
- component.refreshGridData([{ firstName: 'John', lastName: 'Doe' }]);
2045
- eventPubSubService.publish('onPaginationChanged', mockPaginationMetadata);
2046
-
2047
- expect(pubSubSpy).toHaveBeenCalledWith('onGridStateChanged', {
2048
- change: { newValues: mockPagination, type: 'pagination' },
2049
- gridState: { columns: [], pagination: mockPagination },
2050
- });
2051
- });
2052
-
2053
- it('should trigger a gridStage change and reset selected rows when pagination change is triggered and "enableRowSelection" is set', () => {
2054
- const mockPagination = { pageNumber: 2, pageSize: 20 } as Pagination;
2055
- const pluginEaSpy = vi.spyOn(eventPubSubService, 'publish');
2056
- const setRowSpy = vi.spyOn(mockGrid, 'setSelectedRows');
2057
- vi.spyOn(gridStateServiceStub, 'getCurrentGridState').mockReturnValue({ columns: [], pagination: mockPagination } as GridState);
2058
-
2059
- component.options = {
2060
- enableRowSelection: true,
2061
- backendServiceApi: { service: mockGraphqlService as any },
2062
- } as unknown as GridOption;
2063
- component.initialization(slickEventHandler);
2064
- component.paginationChanged(mockPagination);
2065
-
2066
- expect(setRowSpy).toHaveBeenCalledWith([]);
2067
- expect(pluginEaSpy).toHaveBeenCalledWith('onGridStateChanged', {
2068
- change: { newValues: mockPagination, type: 'pagination' },
2069
- gridState: { columns: [], pagination: mockPagination },
2070
- });
2071
- });
2072
-
2073
- it('should call trigger a gridStage change and reset selected rows when pagination change is triggered and "enableCheckboxSelector" is set', () => {
2074
- const mockPagination = { pageNumber: 2, pageSize: 20 } as Pagination;
2075
- const pluginEaSpy = vi.spyOn(eventPubSubService, 'publish');
2076
- const setRowSpy = vi.spyOn(mockGrid, 'setSelectedRows');
2077
- vi.spyOn(gridStateServiceStub, 'getCurrentGridState').mockReturnValue({ columns: [], pagination: mockPagination } as GridState);
2078
-
2079
- component.options = {
2080
- enableCheckboxSelector: true,
2081
- backendServiceApi: { service: mockGraphqlService as any },
2082
- } as unknown as GridOption;
2083
- component.initialization(slickEventHandler);
2084
- component.paginationChanged(mockPagination);
2085
-
2086
- expect(setRowSpy).toHaveBeenCalledWith([]);
2087
- expect(pluginEaSpy).toHaveBeenCalledWith('onGridStateChanged', {
2088
- change: { newValues: mockPagination, type: 'pagination' },
2089
- gridState: { columns: [], pagination: mockPagination },
2090
- });
2091
- });
2092
- });
2093
-
2094
- describe('Empty Warning Message', () => {
2095
- // beforeEach(() => {
2096
- // vi.clearAllMocks();
2097
- // });
2098
-
2099
- it('should display an Empty Warning Message when "enableEmptyDataWarningMessage" is enabled and the dataset is empty', () =>
2100
- new Promise((done: any) => {
2101
- const mockColDefs = [{ id: 'name', field: 'name', editor: undefined }];
2102
- const mockGridOptions = { enableTranslate: true, enableEmptyDataWarningMessage: true };
2103
- vi.spyOn(mockGrid, 'getOptions').mockReturnValue(mockGridOptions);
2104
- vi.spyOn(mockGrid, 'getGridPosition').mockReturnValue({ top: 10, left: 20 } as any);
2105
-
2106
- component.options = mockGridOptions;
2107
- component.initialization(slickEventHandler);
2108
- const slickEmptyWarning = component.registeredResources.find((resource) => resource instanceof SlickEmptyWarningComponent);
2109
- const emptySpy = vi.spyOn(slickEmptyWarning as SlickEmptyWarningComponent, 'showEmptyDataMessage');
2110
- component.columns = mockColDefs;
2111
- component.refreshGridData([]);
2112
- mockDataView.onRowCountChanged.notify({ current: 0, previous: 0, dataView: mockDataView, itemCount: 0, callingOnRowsChanged: false });
2113
-
2114
- setTimeout(() => {
2115
- expect(component.columns).toEqual(mockColDefs);
2116
- expect(component.options.enableEmptyDataWarningMessage).toBe(true);
2117
- expect(slickEmptyWarning).toBeTruthy();
2118
- expect(emptySpy).toHaveBeenCalledTimes(2);
2119
- done();
2120
- });
2121
- }));
2122
- });
2123
-
2124
- describe('resizeColumnsByCellContent method', () => {
2125
- it('should call "resizeColumnsByCellContent" when the DataView "onSetItemsCalled" event is triggered and "enableAutoResizeColumnsByCellContent" is set', () => {
2126
- const resizeContentSpy = vi.spyOn(resizerServiceStub, 'resizeColumnsByCellContent');
2127
- vi.spyOn(mockDataView, 'getLength').mockReturnValue(1);
2128
-
2129
- component.options = {
2130
- enablePagination: false,
2131
- resizeByContentOnlyOnFirstLoad: false,
2132
- showCustomFooter: true,
2133
- autoFitColumnsOnFirstLoad: false,
2134
- enableAutoSizeColumns: false,
2135
- enableAutoResizeColumnsByCellContent: true,
2136
- };
2137
- component.initialization(slickEventHandler);
2138
- mockDataView.onSetItemsCalled.notify({ idProperty: 'id', itemCount: 1 });
2139
-
2140
- expect(resizeContentSpy).toHaveBeenCalledWith(true);
2141
- });
2142
-
2143
- it('should call "resizeColumnsByCellContent" when the DataView "onSetItemsCalled" event is triggered and "enableAutoResizeColumnsByCellContent" and "resizeColumnsByCellContent" are both set', () =>
2144
- new Promise((done: any) => {
2145
- const resizeContentSpy = vi.spyOn(resizerServiceStub, 'resizeColumnsByCellContent');
2146
- vi.spyOn(mockDataView, 'getLength').mockReturnValue(1);
2147
-
2148
- component.options = {
2149
- enablePagination: false,
2150
- resizeByContentOnlyOnFirstLoad: true,
2151
- showCustomFooter: true,
2152
- autoFitColumnsOnFirstLoad: false,
2153
- enableAutoSizeColumns: false,
2154
- enableAutoResizeColumnsByCellContent: true,
2155
- };
2156
- component.initialization(slickEventHandler);
2157
- mockDataView.onSetItemsCalled.notify({ idProperty: 'id', itemCount: 1 });
2158
-
2159
- setTimeout(() => {
2160
- expect(resizeContentSpy).toHaveBeenCalledWith(false);
2161
- done();
2162
- }, 10);
2163
- }));
2164
- });
2165
-
2166
- describe('Custom Footer', () => {
2167
- afterEach(() => {
2168
- vi.clearAllMocks();
2169
- });
2170
-
2171
- it('should have a Custom Footer when "showCustomFooter" is enabled and there are no Pagination used', () =>
2172
- new Promise((done: any) => {
2173
- const mockColDefs = [{ id: 'name', field: 'name', editor: undefined }];
2174
- const mockGridOptions = { enableTranslate: true, showCustomFooter: true, customFooterOptions: { hideRowSelectionCount: false } } as GridOption;
2175
- vi.spyOn(mockGrid, 'getOptions').mockReturnValue(mockGridOptions);
2176
-
2177
- translaterService.use('fr');
2178
- component.options = mockGridOptions;
2179
- component.initialization(slickEventHandler);
2180
- component.columns = mockColDefs;
2181
-
2182
- setTimeout(() => {
2183
- expect(component.columns).toEqual(mockColDefs);
2184
- expect(component.options.showCustomFooter).toBe(true);
2185
- expect(component.options.customFooterOptions).toEqual({
2186
- dateFormat: 'YYYY-MM-DD, hh:mm a',
2187
- hideRowSelectionCount: false,
2188
- hideLastUpdateTimestamp: true,
2189
- hideTotalItemCount: false,
2190
- footerHeight: 25,
2191
- leftContainerClass: 'col-xs-12 col-sm-5',
2192
- metricSeparator: '|',
2193
- metricTexts: {
2194
- items: 'éléments',
2195
- itemsKey: 'ITEMS',
2196
- itemsSelected: 'éléments sélectionnés',
2197
- itemsSelectedKey: 'ITEMS_SELECTED',
2198
- of: 'de',
2199
- ofKey: 'OF',
2200
- },
2201
- rightContainerClass: 'col-xs-6 col-sm-7',
2202
- });
2203
- done();
2204
- });
2205
- }));
2206
-
2207
- it('should have a Custom Footer and custom texts when "showCustomFooter" is enabled with different metricTexts defined', () =>
2208
- new Promise((done: any) => {
2209
- const mockColDefs = [{ id: 'name', field: 'name', editor: undefined }];
2210
-
2211
- component.options = {
2212
- enableTranslate: false,
2213
- showCustomFooter: true,
2214
- customFooterOptions: {
2215
- metricTexts: {
2216
- items: 'some items',
2217
- lastUpdate: 'some last update',
2218
- of: 'some of',
2219
- },
2220
- },
2221
- };
2222
- component.columns = mockColDefs;
2223
- component.initialization(slickEventHandler);
2224
- // component.columnsChanged();
2225
-
2226
- setTimeout(() => {
2227
- expect(component.columns).toEqual(mockColDefs);
2228
- expect(component.options.showCustomFooter).toBe(true);
2229
- expect(component.options.customFooterOptions).toEqual({
2230
- dateFormat: 'YYYY-MM-DD, hh:mm a',
2231
- hideRowSelectionCount: false,
2232
- hideLastUpdateTimestamp: true,
2233
- hideTotalItemCount: false,
2234
- footerHeight: 25,
2235
- leftContainerClass: 'col-xs-12 col-sm-5',
2236
- metricSeparator: '|',
2237
- metricTexts: {
2238
- items: 'some items',
2239
- itemsKey: 'ITEMS',
2240
- itemsSelected: 'items selected',
2241
- itemsSelectedKey: 'ITEMS_SELECTED',
2242
- lastUpdate: 'some last update',
2243
- of: 'some of',
2244
- ofKey: 'OF',
2245
- },
2246
- rightContainerClass: 'col-xs-6 col-sm-7',
2247
- });
2248
- done();
2249
- });
2250
- }));
2251
-
2252
- it('should NOT have a Custom Footer when "showCustomFooter" is enabled WITH Pagination in use', () =>
2253
- new Promise((done: any) => {
2254
- const mockColDefs = [{ id: 'name', field: 'name', editor: undefined }];
2255
-
2256
- component.options = { enablePagination: true, showCustomFooter: true };
2257
- component.columns = mockColDefs;
2258
- component.initialization(slickEventHandler);
2259
- // component.columnsChanged();
2260
-
2261
- setTimeout(() => {
2262
- expect(component.columns).toEqual(mockColDefs);
2263
- expect(component.slickFooter).toBeFalsy();
2264
- done();
2265
- });
2266
- }));
2267
-
2268
- it('should have custom footer with metrics when the DataView "onRowCountChanged" event is triggered', () => {
2269
- const mockData = [
2270
- { firstName: 'John', lastName: 'Doe' },
2271
- { firstName: 'Jane', lastName: 'Smith' },
2272
- ];
2273
- const invalidateSpy = vi.spyOn(mockGrid, 'invalidate');
2274
- const expectation = {
2275
- startTime: expect.any(Date),
2276
- endTime: expect.any(Date),
2277
- itemCount: 2,
2278
- totalItemCount: 2,
2279
- };
2280
- vi.spyOn(mockDataView, 'getItemCount').mockReturnValue(mockData.length);
2281
- vi.spyOn(mockDataView, 'getFilteredItemCount').mockReturnValue(mockData.length);
2282
-
2283
- component.options = { enablePagination: false, showCustomFooter: true };
2284
- component.initialization(slickEventHandler);
2285
- const footerSpy = vi.spyOn(component.slickFooter as SlickFooterComponent, 'metrics', 'set');
2286
- mockDataView.onRowCountChanged.notify({ current: 2, previous: 0, dataView: mockDataView, itemCount: 0, callingOnRowsChanged: false });
2287
-
2288
- expect(invalidateSpy).toHaveBeenCalled();
2289
- expect(component.metrics).toEqual(expectation);
2290
- expect(footerSpy).toHaveBeenCalledWith(expectation);
2291
- });
2292
-
2293
- it('should call a grid resize when the DataView "onRowCountChanged" event is triggered with a low dataset length and autoResize.autoHeight is enabled', () => {
2294
- const mockData = [
2295
- { firstName: 'John', lastName: 'Doe' },
2296
- { firstName: 'Jane', lastName: 'Smith' },
2297
- ];
2298
- const invalidateSpy = vi.spyOn(mockGrid, 'invalidate');
2299
- const expectation = {
2300
- startTime: expect.any(Date),
2301
- endTime: expect.any(Date),
2302
- itemCount: 2,
2303
- totalItemCount: 2,
2304
- };
2305
- vi.spyOn(mockDataView, 'getItemCount').mockReturnValue(mockData.length);
2306
- vi.spyOn(mockDataView, 'getFilteredItemCount').mockReturnValue(mockData.length);
2307
- vi.spyOn(mockDataView, 'getLength').mockReturnValue(mockData.length);
2308
- const resizerSpy = vi.spyOn(resizerServiceStub, 'resizeGrid');
2309
-
2310
- component.options = { enableAutoResize: true, autoResize: { autoHeight: true } };
2311
- component.initialization(slickEventHandler);
2312
- mockDataView.onRowCountChanged.notify({ current: 2, previous: 0, dataView: mockDataView, itemCount: 0, callingOnRowsChanged: false });
2313
-
2314
- expect(invalidateSpy).toHaveBeenCalled();
2315
- expect(component.metrics).toEqual(expectation);
2316
- expect(resizerSpy).toHaveBeenCalled();
2317
- });
2318
-
2319
- it('should have custom footer with metrics when the DataView "onSetItemsCalled" event is triggered', () => {
2320
- const expectation = {
2321
- startTime: expect.any(Date),
2322
- endTime: expect.any(Date),
2323
- itemCount: 0,
2324
- totalItemCount: 0,
2325
- };
2326
- vi.spyOn(mockDataView, 'getFilteredItemCount').mockReturnValue(0);
2327
-
2328
- component.options = { enablePagination: false, showCustomFooter: true };
2329
- component.initialization(slickEventHandler);
2330
- const footerSpy = vi.spyOn(component.slickFooter!, 'metrics', 'set');
2331
- mockDataView.onSetItemsCalled.notify({ idProperty: 'id', itemCount: 0 });
2332
-
2333
- expect(footerSpy).toHaveBeenCalledWith(expectation);
2334
- expect(component.metrics).toEqual(expectation);
2335
- });
2336
- });
2337
-
2338
- describe('loadRowSelectionPresetWhenExists method', () => {
2339
- beforeEach(() => {
2340
- vi.clearAllMocks();
2341
- sharedService.slickGrid = mockGrid as unknown as SlickGrid;
2342
- component.options = gridOptions;
2343
- });
2344
-
2345
- it('should call the "mapIdsToRows" from the DataView then "setSelectedRows" from the Grid when there are row selection presets with "dataContextIds" array set', () =>
2346
- new Promise((done: any) => {
2347
- const selectedGridRows = [2];
2348
- const selectedRowIds = [99];
2349
- const mockData = [
2350
- { firstName: 'John', lastName: 'Doe' },
2351
- { firstName: 'Jane', lastName: 'Smith' },
2352
- ];
2353
- const dataviewSpy = vi.spyOn(mockDataView, 'mapIdsToRows').mockReturnValue(selectedGridRows);
2354
- const selectRowSpy = vi.spyOn(mockGrid, 'setSelectedRows');
2355
- vi.spyOn(mockDataView, 'getLength').mockReturnValue(0);
2356
- vi.spyOn(mockGrid, 'getSelectionModel').mockReturnValue(true as any);
2357
-
2358
- component.options.enableCheckboxSelector = true;
2359
- component.options.presets = { rowSelection: { dataContextIds: selectedRowIds } };
2360
- component.isDatasetInitialized = false;
2361
- component.initialization(slickEventHandler);
2362
- component.dataset = mockData;
2363
-
2364
- setTimeout(() => {
2365
- expect(dataviewSpy).toHaveBeenCalled();
2366
- expect(selectRowSpy).toHaveBeenCalledWith(selectedGridRows);
2367
- done();
2368
- });
2369
- }));
2370
-
2371
- it('should call the "setSelectedRows" from the Grid when there are row selection presets with "dataContextIds" array set', () =>
2372
- new Promise((done: any) => {
2373
- const selectedGridRows = [22];
2374
- const mockData = [
2375
- { firstName: 'John', lastName: 'Doe' },
2376
- { firstName: 'Jane', lastName: 'Smith' },
2377
- ];
2378
- const selectRowSpy = vi.spyOn(mockGrid, 'setSelectedRows');
2379
- vi.spyOn(mockGrid, 'getSelectionModel').mockReturnValue(true as any);
2380
- vi.spyOn(mockDataView, 'getLength').mockReturnValue(mockData.length);
2381
-
2382
- component.options.enableRowSelection = true;
2383
- component.options.presets = { rowSelection: { gridRowIndexes: selectedGridRows } };
2384
- component.dataset = mockData;
2385
- component.isDatasetInitialized = false; // it won't call the preset unless we reset this flag
2386
- component.initialization(slickEventHandler);
2387
-
2388
- setTimeout(() => {
2389
- expect(component.isDatasetInitialized).toBe(true);
2390
- expect(selectRowSpy).toHaveBeenCalledWith(selectedGridRows);
2391
- done();
2392
- });
2393
- }));
2394
-
2395
- it('should call the "setSelectedRows" and "setSelectedIds" when the Grid has Local Pagination and there are row selection presets with "dataContextIds" array set', () => {
2396
- const selectedGridRows = [22];
2397
- const mockData = [
2398
- { firstName: 'John', lastName: 'Doe' },
2399
- { firstName: 'Jane', lastName: 'Smith' },
2400
- ];
2401
- const gridSelectedRowSpy = vi.spyOn(mockGrid, 'setSelectedRows');
2402
- const dvSetSelectedIdSpy = vi.spyOn(mockDataView, 'setSelectedIds');
2403
- vi.spyOn(mockGrid, 'getSelectionModel').mockReturnValue(true as any);
2404
- vi.spyOn(mockDataView, 'getLength').mockReturnValue(mockData.length);
2405
-
2406
- component.options = {
2407
- enableRowSelection: true,
2408
- enablePagination: true,
2409
- backendServiceApi: undefined,
2410
- presets: { rowSelection: { dataContextIds: selectedGridRows } },
2411
- };
2412
- component.dataset = mockData;
2413
- component.isDatasetInitialized = false; // it won't call the preset unless we reset this flag
2414
- component.initialization(slickEventHandler);
2415
-
2416
- expect(component.isDatasetInitialized).toBe(true);
2417
- expect(gridSelectedRowSpy).toHaveBeenCalledWith([2]);
2418
- expect(dvSetSelectedIdSpy).toHaveBeenCalledWith([22], { applyRowSelectionToGrid: true, isRowBeingAdded: true, shouldTriggerEvent: false });
2419
- });
2420
- });
2421
-
2422
- describe('onPaginationVisibilityChanged event', () => {
2423
- beforeEach(() => {
2424
- vi.clearAllMocks();
2425
- sharedService.slickGrid = mockGrid as unknown as SlickGrid;
2426
- component.options = gridOptions;
2427
- });
2428
-
2429
- it('should change "showPagination" flag when "onPaginationVisibilityChanged" from the Pagination Service is triggered', () =>
2430
- new Promise((done: any) => {
2431
- component.options.enablePagination = true;
2432
- component.options.backendServiceApi = undefined;
2433
-
2434
- component.initialization(slickEventHandler);
2435
- component.refreshGridData([{ firstName: 'John', lastName: 'Doe' }]);
2436
- eventPubSubService.publish('onPaginationVisibilityChanged', { visible: false });
2437
-
2438
- setTimeout(() => {
2439
- expect(component.showPagination).toBeFalsy();
2440
- done();
2441
- });
2442
- }));
2443
-
2444
- it('should call the backend service API to refresh the dataset', () =>
2445
- new Promise((done: any) => {
2446
- const backendRefreshSpy = vi.spyOn(backendUtilityServiceStub, 'refreshBackendDataset');
2447
- component.options.enablePagination = true;
2448
- component.options.backendServiceApi = {
2449
- service: mockGraphqlService as unknown as BackendService,
2450
- process: vi.fn(),
2451
- };
2452
-
2453
- component.initialization(slickEventHandler);
2454
- component.refreshGridData([{ firstName: 'John', lastName: 'Doe' }]);
2455
- eventPubSubService.publish('onPaginationVisibilityChanged', { visible: false });
2456
-
2457
- setTimeout(() => {
2458
- expect(backendRefreshSpy).toHaveBeenCalled();
2459
- expect(component.showPagination).toBeFalsy();
2460
- done();
2461
- });
2462
- }));
2463
- });
2464
-
2465
- describe('Tree Data View', () => {
2466
- afterEach(() => {
2467
- component.destroy();
2468
- vi.clearAllMocks();
2469
- });
2470
-
2471
- it('should change flat dataset and expect "convertFlatParentChildToTreeDatasetAndSort" being called with other methods', () => {
2472
- const mockFlatDataset = [
2473
- { id: 0, file: 'documents' },
2474
- { id: 1, file: 'vacation.txt', parentId: 0 },
2475
- ];
2476
- const mockHierarchical = [{ id: 0, file: 'documents', files: [{ id: 1, file: 'vacation.txt' }] }];
2477
- const hierarchicalSpy = vi.spyOn(SharedService.prototype, 'hierarchicalDataset', 'set');
2478
- const treeConvertAndSortSpy = vi
2479
- .spyOn(treeDataServiceStub, 'convertFlatParentChildToTreeDatasetAndSort')
2480
- .mockReturnValue({ hierarchical: mockHierarchical as any[], flat: mockFlatDataset as any[] });
2481
- const refreshTreeSpy = vi.spyOn(filterServiceStub, 'refreshTreeDataFilters');
2482
-
2483
- component.options = {
2484
- enableTreeData: true,
2485
- treeDataOptions: {
2486
- columnId: 'file',
2487
- parentPropName: 'parentId',
2488
- childrenPropName: 'files',
2489
- initialSort: { columndId: 'file', direction: 'ASC' },
2490
- },
2491
- } as unknown as GridOption;
2492
- component.initialization(slickEventHandler);
2493
- component.dataset = mockFlatDataset;
2494
- component.dataset = mockFlatDataset;
2495
-
2496
- expect(hierarchicalSpy).toHaveBeenCalledWith(mockHierarchical);
2497
- expect(refreshTreeSpy).toHaveBeenCalled();
2498
- expect(treeConvertAndSortSpy).toHaveBeenCalled();
2499
- });
2500
-
2501
- it('should change flat dataset and expect "convertFlatParentChildToTreeDatasetAndSort" being called even without an initial sort defined', () => {
2502
- const mockFlatDataset = [
2503
- { id: 0, file: 'documents' },
2504
- { id: 1, file: 'vacation.txt', parentId: 0 },
2505
- ];
2506
- const mockHierarchical = [{ id: 0, file: 'documents', files: [{ id: 1, file: 'vacation.txt' }] }];
2507
- const hierarchicalSpy = vi.spyOn(SharedService.prototype, 'hierarchicalDataset', 'set');
2508
- const treeConvertAndSortSpy = vi
2509
- .spyOn(treeDataServiceStub, 'convertFlatParentChildToTreeDatasetAndSort')
2510
- .mockReturnValue({ hierarchical: mockHierarchical as any[], flat: mockFlatDataset as any[] });
2511
- const refreshTreeSpy = vi.spyOn(filterServiceStub, 'refreshTreeDataFilters');
2512
-
2513
- component.options = {
2514
- enableTreeData: true,
2515
- treeDataOptions: {
2516
- columnId: 'file',
2517
- parentPropName: 'parentId',
2518
- childrenPropName: 'files',
2519
- },
2520
- } as unknown as GridOption;
2521
- component.initialization(slickEventHandler);
2522
- component.dataset = mockFlatDataset;
2523
- component.dataset = mockFlatDataset;
2524
-
2525
- expect(hierarchicalSpy).toHaveBeenCalledWith(mockHierarchical);
2526
- expect(refreshTreeSpy).toHaveBeenCalled();
2527
- expect(treeConvertAndSortSpy).toHaveBeenCalled();
2528
- });
2529
-
2530
- it('should change hierarchical dataset and expect processTreeDataInitialSort being called with other methods', () =>
2531
- new Promise((done: any) => {
2532
- const mockHierarchical = [{ file: 'documents', files: [{ file: 'vacation.txt' }] }];
2533
- const hierarchicalSpy = vi.spyOn(SharedService.prototype, 'hierarchicalDataset', 'set');
2534
- const clearFilterSpy = vi.spyOn(filterServiceStub, 'clearFilters');
2535
- const refreshFilterSpy = vi.spyOn(filterServiceStub, 'refreshTreeDataFilters');
2536
- const setItemsSpy = vi.spyOn(mockDataView, 'setItems');
2537
- const processSpy = vi.spyOn(sortServiceStub, 'processTreeDataInitialSort');
2538
-
2539
- component.options = { enableTreeData: true, treeDataOptions: { columnId: 'file' } } as unknown as GridOption;
2540
- component.initialization(slickEventHandler);
2541
- component.datasetHierarchical = mockHierarchical;
2542
-
2543
- expect(hierarchicalSpy).toHaveBeenCalledWith(mockHierarchical);
2544
- expect(clearFilterSpy).toHaveBeenCalled();
2545
- expect(processSpy).toHaveBeenCalled();
2546
- expect(setItemsSpy).toHaveBeenCalledWith([], 'id');
2547
- setTimeout(() => {
2548
- expect(refreshFilterSpy).toHaveBeenCalled();
2549
- done();
2550
- });
2551
- }));
2552
-
2553
- it('should preset hierarchical dataset before the initialization and expect sortHierarchicalDataset to be called', () => {
2554
- const mockFlatDataset = [
2555
- { id: 0, file: 'documents' },
2556
- { id: 1, file: 'vacation.txt', parentId: 0 },
2557
- ];
2558
- const mockHierarchical = [{ id: 0, file: 'documents', files: [{ id: 1, file: 'vacation.txt' }] }];
2559
- const hierarchicalSpy = vi.spyOn(SharedService.prototype, 'hierarchicalDataset', 'set');
2560
- const clearFilterSpy = vi.spyOn(filterServiceStub, 'clearFilters');
2561
- const setItemsSpy = vi.spyOn(mockDataView, 'setItems');
2562
- const processSpy = vi.spyOn(sortServiceStub, 'processTreeDataInitialSort');
2563
- const sortHierarchicalSpy = vi
2564
- .spyOn(treeDataServiceStub, 'sortHierarchicalDataset')
2565
- .mockReturnValue({ hierarchical: mockHierarchical as any[], flat: mockFlatDataset as any[] });
2566
-
2567
- component.destroy();
2568
- component.options = {
2569
- enableTreeData: true,
2570
- treeDataOptions: { columnId: 'file', initialSort: { columndId: 'file', direction: 'ASC' } },
2571
- } as unknown as GridOption;
2572
- component.datasetHierarchical = mockHierarchical;
2573
- component.isDatasetHierarchicalInitialized = true;
2574
- component.initialization(slickEventHandler);
2575
-
2576
- expect(hierarchicalSpy).toHaveBeenCalledWith(mockHierarchical);
2577
- expect(clearFilterSpy).toHaveBeenCalled();
2578
- expect(processSpy).not.toHaveBeenCalled();
2579
- expect(setItemsSpy).toHaveBeenCalledWith(mockFlatDataset, 'id');
2580
- expect(sortHierarchicalSpy).toHaveBeenCalledWith(mockHierarchical);
2581
- });
2582
-
2583
- it('should expect "refreshTreeDataFilters" method to be called when our flat dataset was already set and it just got changed a 2nd time', () => {
2584
- const mockFlatDataset = [
2585
- { id: 0, file: 'documents' },
2586
- { id: 1, file: 'vacation.txt', parentId: 0 },
2587
- ];
2588
- const mockHierarchical = [{ id: 0, file: 'documents', files: [{ id: 1, file: 'vacation.txt' }] }];
2589
- const hierarchicalSpy = vi.spyOn(SharedService.prototype, 'hierarchicalDataset', 'set');
2590
- vi.spyOn(treeDataServiceStub, 'convertFlatParentChildToTreeDatasetAndSort').mockReturnValue({
2591
- hierarchical: mockHierarchical as any[],
2592
- flat: mockFlatDataset as any[],
2593
- });
2594
- const refreshTreeSpy = vi.spyOn(filterServiceStub, 'refreshTreeDataFilters');
2595
-
2596
- component.dataset = [{ id: 0, file: 'documents' }];
2597
- component.options = {
2598
- enableTreeData: true,
2599
- treeDataOptions: { columnId: 'file', parentPropName: 'parentId', childrenPropName: 'files', initialSort: { columndId: 'file', direction: 'ASC' } },
2600
- } as unknown as GridOption;
2601
- component.initialization(slickEventHandler);
2602
- component.dataset = mockFlatDataset;
2603
- component.dataset = mockFlatDataset;
2604
-
2605
- expect(hierarchicalSpy).toHaveBeenCalledWith(mockHierarchical);
2606
- expect(refreshTreeSpy).toHaveBeenCalled();
2607
- });
2608
-
2609
- it('should also expect "refreshTreeDataFilters" method to be called even when the dataset length is the same but still has different properties (e.g. different filename)', () => {
2610
- const mockFlatDataset = [
2611
- { id: 0, file: 'documents' },
2612
- { id: 1, file: 'new-vacation.txt', parentId: 0 },
2613
- ];
2614
- const mockHierarchical = [{ id: 0, file: 'documents', files: [{ id: 1, file: 'vacation.txt' }] }];
2615
- const hierarchicalSpy = vi.spyOn(SharedService.prototype, 'hierarchicalDataset', 'set');
2616
- vi.spyOn(treeDataServiceStub, 'convertFlatParentChildToTreeDatasetAndSort').mockReturnValue({
2617
- hierarchical: mockHierarchical as any[],
2618
- flat: mockFlatDataset as any[],
2619
- });
2620
- const refreshTreeSpy = vi.spyOn(filterServiceStub, 'refreshTreeDataFilters');
2621
-
2622
- component.dataset = [
2623
- { id: 0, file: 'documents' },
2624
- { id: 1, file: 'old-vacation.txt', parentId: 0 },
2625
- ];
2626
- component.options = {
2627
- enableTreeData: true,
2628
- treeDataOptions: { columnId: 'file', parentPropName: 'parentId', childrenPropName: 'files', initialSort: { columndId: 'file', direction: 'ASC' } },
2629
- } as unknown as GridOption;
2630
- component.initialization(slickEventHandler);
2631
- component.dataset = mockFlatDataset;
2632
-
2633
- expect(hierarchicalSpy).toHaveBeenCalledWith(mockHierarchical);
2634
- expect(refreshTreeSpy).toHaveBeenCalled();
2635
- });
2636
- });
2637
- });
2638
- });