dyo-tools 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/.c8rc.json +4 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.json +47 -0
  4. package/Makefile +34 -0
  5. package/README.md +0 -7
  6. package/babel.config.js +1 -0
  7. package/cucumber-report.html +48 -0
  8. package/dist/constants.d.ts +6 -0
  9. package/dist/constants.js +63 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/core/DTAction.d.ts +10 -0
  12. package/dist/core/DTAction.js +24 -0
  13. package/dist/core/DTAction.js.map +1 -0
  14. package/dist/core/DTBunch.d.ts +12 -17
  15. package/dist/core/DTBunch.js +39 -115
  16. package/dist/core/DTBunch.js.map +1 -1
  17. package/dist/core/DTComponent.d.ts +13 -5
  18. package/dist/core/DTComponent.js +39 -1
  19. package/dist/core/DTComponent.js.map +1 -1
  20. package/dist/core/DTComponentPhysical.d.ts +12 -0
  21. package/dist/core/DTComponentPhysical.js +22 -0
  22. package/dist/core/DTComponentPhysical.js.map +1 -0
  23. package/dist/core/DTComponentWithMeta.d.ts +2 -2
  24. package/dist/core/DTComponentWithMeta.js.map +1 -1
  25. package/dist/core/DTElement.d.ts +7 -7
  26. package/dist/core/DTElement.js +12 -11
  27. package/dist/core/DTElement.js.map +1 -1
  28. package/dist/core/DTManager.d.ts +33 -0
  29. package/dist/core/DTManager.js +190 -0
  30. package/dist/core/DTManager.js.map +1 -0
  31. package/dist/core/DTMaster.d.ts +24 -0
  32. package/dist/core/DTMaster.js +133 -0
  33. package/dist/core/DTMaster.js.map +1 -0
  34. package/dist/core/DTModule.d.ts +14 -0
  35. package/dist/core/DTModule.js +39 -0
  36. package/dist/core/DTModule.js.map +1 -0
  37. package/dist/index.d.ts +7 -1
  38. package/dist/index.js +15 -3
  39. package/dist/index.js.map +1 -1
  40. package/dist/libs/DYOFinder.d.ts +10 -0
  41. package/dist/libs/DYOFinder.js +96 -0
  42. package/dist/libs/DYOFinder.js.map +1 -0
  43. package/dist/libs/player/DTPlayer.element.d.ts +5 -0
  44. package/dist/libs/player/DTPlayer.element.js +11 -0
  45. package/dist/libs/player/DTPlayer.element.js.map +1 -0
  46. package/dist/libs/player/DTPlayer.manager.d.ts +11 -0
  47. package/dist/libs/player/DTPlayer.manager.js +42 -0
  48. package/dist/libs/player/DTPlayer.manager.js.map +1 -0
  49. package/dist/tsconfig.tsbuildinfo +1 -1321
  50. package/dist/types/core.d.ts +103 -0
  51. package/dist/types/core.js +15 -0
  52. package/dist/types/core.js.map +1 -0
  53. package/dist/types/index.d.ts +2 -58
  54. package/dist/types/index.js +16 -12
  55. package/dist/types/index.js.map +1 -1
  56. package/dist/types/player.d.ts +5 -0
  57. package/dist/types/player.js +3 -0
  58. package/dist/types/player.js.map +1 -0
  59. package/docs/.nojekyll +1 -0
  60. package/docs/assets/highlight.css +29 -0
  61. package/docs/assets/main.js +59 -0
  62. package/docs/assets/navigation.js +1 -0
  63. package/docs/assets/search.js +1 -0
  64. package/docs/assets/style.css +1414 -0
  65. package/docs/classes/core_DTAction.DYOToolsAction.html +89 -0
  66. package/docs/classes/core_DTBunch.DYOToolsBunch.html +254 -0
  67. package/docs/classes/core_DTComponent.DYOToolsComponent.html +76 -0
  68. package/docs/classes/core_DTComponentPhysical.DYOToolsComponentPhysical.html +110 -0
  69. package/docs/classes/core_DTComponentWithMeta.DYOToolsComponentWithMeta.html +96 -0
  70. package/docs/classes/core_DTElement.DYOToolsElement.html +135 -0
  71. package/docs/classes/core_DTError.DYOToolsError.html +37 -0
  72. package/docs/classes/core_DTManager.DYOToolsManager.html +237 -0
  73. package/docs/classes/core_DTMaster.DYOToolsMaster.html +150 -0
  74. package/docs/classes/core_DTModule.DYOToolsModule.html +92 -0
  75. package/docs/classes/libs_DYOFinder.DYOFinder.html +34 -0
  76. package/docs/classes/libs_player_DTPlayer_element.DYOToolsPlayer.html +134 -0
  77. package/docs/classes/libs_player_DTPlayer_manager.DYOToolsPlayerManager.html +243 -0
  78. package/docs/enums/types_core.FilterOperatorType.html +10 -0
  79. package/docs/hierarchy.html +1 -0
  80. package/docs/index.html +1 -0
  81. package/docs/interfaces/types_core.DTBunchFilters.html +6 -0
  82. package/docs/interfaces/types_core.DTBunchOptions.html +19 -0
  83. package/docs/interfaces/types_core.DTBunchToObject.html +7 -0
  84. package/docs/interfaces/types_core.DTComponentOptions.html +5 -0
  85. package/docs/interfaces/types_core.DTComponentToObject.html +4 -0
  86. package/docs/interfaces/types_core.DTElementToObject.html +7 -0
  87. package/docs/interfaces/types_core.DTManagerFilters.html +6 -0
  88. package/docs/interfaces/types_core.DTManagerOptions.html +8 -0
  89. package/docs/interfaces/types_core.DTManagerToObject.html +5 -0
  90. package/docs/interfaces/types_core.DTMasterToObject.html +8 -0
  91. package/docs/interfaces/types_core.DTModuleToObject.html +6 -0
  92. package/docs/interfaces/types_core.DYOFinderConfigurationPropDefault.html +4 -0
  93. package/docs/interfaces/types_core.DYOFinderConfigurationPropObjectSearch.html +4 -0
  94. package/docs/interfaces/types_core.DYOFinderFilterOperatorAdvanced.html +5 -0
  95. package/docs/interfaces/types_core.DYOFinderFilterOperatorBase.html +5 -0
  96. package/docs/interfaces/types_player.DTPlayerManagerSimpleConfiguration.html +3 -0
  97. package/docs/modules/constants.html +6 -0
  98. package/docs/modules/core_DTAction.html +2 -0
  99. package/docs/modules/core_DTBunch.html +2 -0
  100. package/docs/modules/core_DTComponent.html +2 -0
  101. package/docs/modules/core_DTComponentPhysical.html +2 -0
  102. package/docs/modules/core_DTComponentWithMeta.html +2 -0
  103. package/docs/modules/core_DTElement.html +2 -0
  104. package/docs/modules/core_DTError.html +2 -0
  105. package/docs/modules/core_DTManager.html +2 -0
  106. package/docs/modules/core_DTMaster.html +2 -0
  107. package/docs/modules/core_DTModule.html +2 -0
  108. package/docs/modules/libs_DYOFinder.html +2 -0
  109. package/docs/modules/libs_player_DTPlayer_element.html +2 -0
  110. package/docs/modules/libs_player_DTPlayer_manager.html +2 -0
  111. package/docs/modules/types.html +29 -0
  112. package/docs/modules/types_core.html +28 -0
  113. package/docs/modules/types_player.html +2 -0
  114. package/docs/types/types_core.DTAcceptedMetaData.html +2 -0
  115. package/docs/types/types_core.DTManagerItemType.html +1 -0
  116. package/docs/types/types_core.DTManagerItemsType.html +2 -0
  117. package/docs/types/types_core.DYOFinderComponentType.html +1 -0
  118. package/docs/types/types_core.DYOFinderConfiguration.html +2 -0
  119. package/docs/types/types_core.DYOFinderConfigurationProp.html +1 -0
  120. package/docs/types/types_core.DYOFinderFilterOperator.html +1 -0
  121. package/docs/types/types_core.DYOFinderFilterOperatorArgument.html +1 -0
  122. package/docs/types/types_core.DYOFinderFilters.html +1 -0
  123. package/docs/types/types_core.StandardPrimitiveType.html +2 -0
  124. package/docs/types/types_core.StandardPrimitiveTypeWithArray.html +1 -0
  125. package/docs/variables/constants.bunchDefaultOptions.html +2 -0
  126. package/docs/variables/constants.componentBunchDefaultFinderConfiguration.html +1 -0
  127. package/docs/variables/constants.componentManagerDefaultFinderConfiguration.html +1 -0
  128. package/docs/variables/constants.componentPhysicalDefaultFinderConfiguration.html +1 -0
  129. package/docs/variables/constants.managerDefaultOptions.html +2 -0
  130. package/jest.config.js +6 -0
  131. package/package.json +32 -23
  132. package/src/constants.ts +85 -0
  133. package/src/core/DTAction.ts +52 -0
  134. package/src/core/DTBunch.ts +467 -0
  135. package/src/core/DTComponent.ts +225 -0
  136. package/src/core/DTComponentPhysical.ts +53 -0
  137. package/src/core/DTComponentWithMeta.ts +65 -0
  138. package/src/core/DTElement.ts +102 -0
  139. package/src/core/DTError.ts +78 -0
  140. package/src/core/DTManager.ts +465 -0
  141. package/src/core/DTMaster.ts +318 -0
  142. package/src/core/DTModule.ts +90 -0
  143. package/src/index.ts +17 -0
  144. package/src/libs/DYOFinder.ts +175 -0
  145. package/src/libs/player/DTPlayer.element.ts +9 -0
  146. package/src/libs/player/DTPlayer.manager.ts +84 -0
  147. package/src/types/core.ts +169 -0
  148. package/src/types/index.ts +2 -0
  149. package/src/types/player.ts +6 -0
  150. package/test/core/DTAction.double.ts +78 -0
  151. package/test/core/DTAction.spec.ts +76 -0
  152. package/test/core/DTBunch.double.ts +261 -0
  153. package/test/core/DTBunch.spec.ts +897 -0
  154. package/test/core/DTComponent.double.ts +164 -0
  155. package/test/core/DTComponent.spec.ts +295 -0
  156. package/test/core/DTComponentPhysical.double.ts +76 -0
  157. package/test/core/DTComponentPhysical.spec.ts +78 -0
  158. package/test/core/DTComponentWithMeta.double.ts +115 -0
  159. package/test/core/DTComponentWithMeta.spec.ts +124 -0
  160. package/test/core/DTElement.double.ts +163 -0
  161. package/test/core/DTElement.spec.ts +146 -0
  162. package/test/core/DTError.double.ts +92 -0
  163. package/test/core/DTError.spec.ts +89 -0
  164. package/test/core/DTManager.double.ts +216 -0
  165. package/test/core/DTManager.spec.ts +965 -0
  166. package/test/core/DTMaster.double.ts +141 -0
  167. package/test/core/DTMaster.spec.ts +584 -0
  168. package/test/core/DTModule.double.ts +80 -0
  169. package/test/core/DTModule.spec.ts +138 -0
  170. package/test/core/copy.spec.ts +243 -0
  171. package/test/libs/DYOFinder.double.ts +152 -0
  172. package/test/libs/DYOFinder.spec.ts +194 -0
  173. package/test/libs/player/DTPlayer.element.double.ts +55 -0
  174. package/test/libs/player/DTPlayer.element.spec.ts +28 -0
  175. package/test/libs/player/DTPlayer.manager.double.ts +92 -0
  176. package/test/libs/player/DTPlayer.manager.spec.ts +178 -0
  177. package/tsconfig.dev.json +22 -0
  178. package/tsconfig.json +21 -0
  179. package/dist/core/DTPlayer.d.ts +0 -8
  180. package/dist/core/DTPlayer.js +0 -30
  181. package/dist/core/DTPlayer.js.map +0 -1
  182. package/dist/utils/filters.d.ts +0 -6
  183. package/dist/utils/filters.js +0 -39
  184. package/dist/utils/filters.js.map +0 -1
@@ -0,0 +1,194 @@
1
+ import {
2
+ afterEach, beforeEach, describe, expect, jest, test,
3
+ } from '@jest/globals';
4
+ import { DTBunchStub, IDTest } from '../core/DTBunch.double';
5
+ import DYOFinderTest, { DefaultConfiguration, generateComponent } from './DYOFinder.double';
6
+ import { FilterOperatorType } from '../../src/types';
7
+
8
+ /** *********************** TESTS SUITES ****************************** */
9
+ describe('class DYOFinder', () => {
10
+ let bunchStubToFind: DTBunchStub;
11
+ let finder: DYOFinderTest;
12
+
13
+ beforeEach(() => {
14
+ bunchStubToFind = generateComponent();
15
+ finder = new DYOFinderTest(bunchStubToFind, DefaultConfiguration);
16
+ });
17
+
18
+ afterEach(() => {
19
+ jest.resetAllMocks();
20
+ });
21
+
22
+ describe('constructor()', () => {
23
+ test('simple initialisation', () => {
24
+ const newFinder = new DYOFinderTest(bunchStubToFind, DefaultConfiguration);
25
+
26
+ expect(newFinder.th_get_component().getId()).toBe(IDTest);
27
+ expect(newFinder.th_get_configuration()).toStrictEqual(DefaultConfiguration);
28
+ });
29
+ });
30
+
31
+ describe('execute()', () => {
32
+ const finderExecutionTestValue = (results: any): [number, []] => [
33
+ results.length,
34
+ results.map((result) => result.parentIndex),
35
+ ];
36
+
37
+ test('find items - $eq operator case', () => {
38
+ // String prop
39
+ expect(finderExecutionTestValue(finder.execute({ propString: { $eq: 'item_prime' } }))).toStrictEqual([2, [0, 1]]);
40
+ expect(finderExecutionTestValue(finder.execute({ propString: { $eq: 'invalid' } }))).toStrictEqual([0, []]);
41
+ // Number prop
42
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $eq: 17 } }))).toStrictEqual([2, [0, 3]]);
43
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $eq: 24 } }))).toStrictEqual([0, []]);
44
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $eq: '17' } }))).toStrictEqual([0, []]);
45
+ // Array prop
46
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $eq: 'tag1' } }))).toStrictEqual([0, []]);
47
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $eq: undefined } }))).toStrictEqual([1, [3]]);
48
+ // Boolean prop
49
+ expect(finderExecutionTestValue(finder.execute({ propBoolean: { $eq: true } }))).toStrictEqual([3, [0, 2, 4]]);
50
+ expect(finderExecutionTestValue(finder.execute({ propBoolean: { $eq: false } }))).toStrictEqual([2, [1, 3]]);
51
+ expect(finderExecutionTestValue(finder.execute({ propBoolean: { $eq: 'false' } }))).toStrictEqual([0, []]);
52
+ expect(finderExecutionTestValue(finder.execute({ propBoolean: { $eq: null } }))).toStrictEqual([0, []]);
53
+ // Object prop
54
+ expect(finderExecutionTestValue(finder.execute({ propObject: { $eq: 'value' } }))).toStrictEqual([0, []]);
55
+ expect(finderExecutionTestValue(finder.execute({ propObject: { $eq: "{ data: 'value' }" } }))).toStrictEqual([0, []]);
56
+ expect(finderExecutionTestValue(finder.execute({ propObject: { $eq: null } }))).toStrictEqual([2, [3, 4]]);
57
+ });
58
+
59
+ test('find items - $ne operator case', () => {
60
+ // String prop
61
+ expect(finderExecutionTestValue(finder.execute({ propString: { $ne: 'item_prime' } }))).toStrictEqual([3, [2, 3, 4]]);
62
+ expect(finderExecutionTestValue(finder.execute({ propString: { $ne: 'invalid' } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
63
+ // Number prop
64
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $ne: 17 } }))).toStrictEqual([3, [1, 2, 4]]);
65
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $ne: 24 } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
66
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $ne: '17' } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
67
+ // Array prop
68
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $ne: 'tag1' } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
69
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $ne: undefined } }))).toStrictEqual([4, [0, 1, 2, 4]]);
70
+ // Boolean prop
71
+ expect(finderExecutionTestValue(finder.execute({ propBoolean: { $ne: true } }))).toStrictEqual([2, [1, 3]]);
72
+ expect(finderExecutionTestValue(finder.execute({ propBoolean: { $ne: false } }))).toStrictEqual([3, [0, 2, 4]]);
73
+ expect(finderExecutionTestValue(finder.execute({ propBoolean: { $ne: 'false' } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
74
+ expect(finderExecutionTestValue(finder.execute({ propBoolean: { $ne: null } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
75
+ // Object prop
76
+ expect(finderExecutionTestValue(finder.execute({ propObject: { $ne: 'value' } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
77
+ expect(finderExecutionTestValue(finder.execute({ propObject: { $ne: "{ data: 'value' }" } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
78
+ expect(finderExecutionTestValue(finder.execute({ propObject: { $ne: null } }))).toStrictEqual([3, [0, 1, 2]]);
79
+ });
80
+
81
+ test('find items - $in operator case', () => {
82
+ // String prop
83
+ expect(finderExecutionTestValue(finder.execute({ propString: { $in: ['item_prime', 'item_second'] } }))).toStrictEqual([4, [0, 1, 2, 4]]);
84
+ expect(finderExecutionTestValue(finder.execute({ propString: { $in: ['item_third', 'invalid', false] } }))).toStrictEqual([1, [3]]);
85
+ // Number prop
86
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $in: [17, 19] } }))).toStrictEqual([3, [0, 1, 3]]);
87
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $in: ['17', 24, false] } }))).toStrictEqual([0, []]);
88
+ // Array prop
89
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $in: ['tag1'] } }))).toStrictEqual([0, []]);
90
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $in: ['tag1', 'tag2', undefined] } }))).toStrictEqual([1, [3]]);
91
+ // Boolean prop
92
+ expect(finderExecutionTestValue(finder.execute({ propBoolean: { $in: [true, false] } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
93
+ expect(finderExecutionTestValue(finder.execute({ propBoolean: { $in: ['true', 'false', null] } }))).toStrictEqual([0, []]);
94
+ // Object prop
95
+ expect(finderExecutionTestValue(finder.execute({ propObject: { $in: ['value'] } }))).toStrictEqual([0, []]);
96
+ expect(finderExecutionTestValue(finder.execute({ propObject: { $in: null } }))).toStrictEqual([0, []]);
97
+ expect(finderExecutionTestValue(finder.execute({ propObject: { $in: [null] } }))).toStrictEqual([2, [3, 4]]);
98
+ });
99
+
100
+ test('find items - $nin operator case', () => {
101
+ // String prop
102
+ expect(finderExecutionTestValue(finder.execute({ propString: { $nin: ['item_prime', 'item_second'] } }))).toStrictEqual([1, [3]]);
103
+ expect(finderExecutionTestValue(finder.execute({ propString: { $nin: ['item_third', 'invalid', false] } }))).toStrictEqual([4, [0, 1, 2, 4]]);
104
+ // Number prop
105
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $nin: [17, 19] } }))).toStrictEqual([2, [2, 4]]);
106
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $nin: ['17', 24, false] } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
107
+ // Array prop
108
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $nin: ['tag1'] } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
109
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $nin: ['tag1', 'tag2', undefined] } }))).toStrictEqual([4, [0, 1, 2, 4]]);
110
+ // Boolean prop
111
+ expect(finderExecutionTestValue(finder.execute({ propBoolean: { $nin: [true, false] } }))).toStrictEqual([0, []]);
112
+ expect(finderExecutionTestValue(finder.execute({ propBoolean: { $nin: ['true', 'false', null] } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
113
+ // Object prop
114
+ expect(finderExecutionTestValue(finder.execute({ propObject: { $nin: ['value'] } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
115
+ expect(finderExecutionTestValue(finder.execute({ propObject: { $nin: null } }))).toStrictEqual([0, []]);
116
+ expect(finderExecutionTestValue(finder.execute({ propObject: { $nin: [null] } }))).toStrictEqual([3, [0, 1, 2]]);
117
+ });
118
+
119
+ test('find items - $lte operator case', () => {
120
+ // Number prop
121
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $lte: 23 } }))).toStrictEqual([4, [0, 1, 2, 3]]);
122
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $lte: 1000 } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
123
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $lte: null } }))).toStrictEqual([0, []]);
124
+ });
125
+
126
+ test('find items - $gte operator case', () => {
127
+ // Number prop
128
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $gte: 23 } }))).toStrictEqual([2, [2, 4]]);
129
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $gte: -1000 } }))).toStrictEqual([5, [0, 1, 2, 3, 4]]);
130
+ expect(finderExecutionTestValue(finder.execute({ propNumber: { $gte: null } }))).toStrictEqual([0, []]);
131
+ });
132
+
133
+ test('find items - $contains operator case', () => {
134
+ // Array prop
135
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $contains: 'tag1' } }))).toStrictEqual([3, [0, 1, 2]]);
136
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $contains: undefined } }))).toStrictEqual([0, []]);
137
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $contains: 'invalid_tag' } }))).toStrictEqual([0, []]);
138
+ });
139
+
140
+ test('find items - $ncontains operator case', () => {
141
+ // Array prop
142
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $ncontains: 'tag1' } }))).toStrictEqual([1, [4]]);
143
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $ncontains: undefined } }))).toStrictEqual([4, [0, 1, 2, 4]]);
144
+ expect(finderExecutionTestValue(finder.execute({ propArray: { $ncontains: 'invalid_tag' } }))).toStrictEqual([4, [0, 1, 2, 4]]);
145
+ });
146
+
147
+ test('disable filters by configuration', () => {
148
+ finder.th_set_configuration({
149
+ propString: {
150
+ operators: [FilterOperatorType.NE],
151
+ getValue: (item: any) => item.getPropString(),
152
+ objectSearch: false,
153
+ },
154
+ });
155
+
156
+ expect(finderExecutionTestValue(finder.execute({ propString: { $eq: 'item_prime' } }))).toStrictEqual([0, []]);
157
+ expect(finderExecutionTestValue(finder.execute({ propString: { $in: ['item_prime', 'item_second'] } }))).toStrictEqual([0, []]);
158
+ });
159
+
160
+ test('returns no items when no filter passed', () => {
161
+ expect(finderExecutionTestValue(finder.execute({}))).toStrictEqual([0, []]);
162
+ });
163
+
164
+ test('find items with object search property', () => {
165
+ expect(finderExecutionTestValue(finder.execute(
166
+ { propMeta: { meta1: { $eq: 'value1' } } },
167
+ ))).toStrictEqual([2, [0, 1]]);
168
+ expect(finderExecutionTestValue(finder.execute(
169
+ { propMeta: { meta2: { $in: ['value2', 'value1'] } } },
170
+ ))).toStrictEqual([2, [1, 2]]);
171
+ expect(finderExecutionTestValue(finder.execute(
172
+ { propMeta: { meta1: { $ne: 'value1' } } },
173
+ ))).toStrictEqual([2, [2, 4]]);
174
+ expect(finderExecutionTestValue(finder.execute(
175
+ { propMeta: { meta1: { } } },
176
+ ))).toStrictEqual([0, []]);
177
+ });
178
+
179
+ test('find items with complex and multiple filters', () => {
180
+ // Multiple filters
181
+ expect(finderExecutionTestValue(finder.execute(
182
+ { propString: { $eq: 'item_prime' }, propNumber: { $lte: 18 } },
183
+ ))).toStrictEqual([1, [0]]);
184
+ // Multiple operators
185
+ expect(finderExecutionTestValue(finder.execute(
186
+ { propNumber: { $lte: 25, $gte: 15, $ne: 19 } },
187
+ ))).toStrictEqual([3, [0, 2, 3]]);
188
+ // Multiple filters and Object search
189
+ expect(finderExecutionTestValue(finder.execute(
190
+ { propString: { $in: ['item_prime', 'item_third'] }, propArray: { $ne: undefined }, propMeta: { meta2: { $ne: undefined } } },
191
+ ))).toStrictEqual([1, [1]]);
192
+ });
193
+ });
194
+ });
@@ -0,0 +1,55 @@
1
+ import {DTPlayer} from '../../../src';
2
+
3
+ /******************** STUB PROPERTIES CONSTANTS
4
+ * Fixed properties to use with double classes, avoid auto generated and easy checking on test
5
+ * *****/
6
+ export const IDTest = 'DTPlayer-id-1234567';
7
+ export const KeyTest = 'DTPlayer-key-1234567';
8
+
9
+ // Specific elements constants
10
+ export const KeyTest1 = 'DTPlayer-key-1234567-1';
11
+ export const KeyTest2 = 'DTPlayer-key-1234567-2';
12
+
13
+ /******************** HELPER TEST CLASS
14
+ * Helper test class, inherits the main component
15
+ * Providing methods to property access and other facilities, in order to avoid using class methods
16
+ * *****/
17
+ export class DTPlayerTest extends DTPlayer {
18
+ th_get_id(): string {
19
+ return this._id;
20
+ }
21
+
22
+ th_set_id(id: string): void {
23
+ this._id = id;
24
+ }
25
+
26
+ th_get_key(): string {
27
+ return this._key;
28
+ }
29
+
30
+ th_set_key(key: string): void {
31
+ this._key = key;
32
+ }
33
+
34
+ th_get_domain(): string {
35
+ return this._domain;
36
+ }
37
+ }
38
+
39
+ /** ****************** STUB CLASS
40
+ * Stub class, for using in other component
41
+ * **** */
42
+ export class DTPlayerStub extends DTPlayerTest {
43
+ constructor(key: string) {
44
+ super(key);
45
+ this._key = key;
46
+ this._id = IDTest;
47
+ }
48
+
49
+ getId(): string {
50
+ return IDTest;
51
+ }
52
+ }
53
+
54
+
55
+
@@ -0,0 +1,28 @@
1
+ import {afterEach, beforeEach, describe, expect, jest, test,} from '@jest/globals';
2
+ import {DTPlayerTest} from "./DTPlayer.element.double";
3
+ import {DTElement, DTPlayer} from "../../../src";
4
+
5
+ /** *********************** TESTS SUITES ****************************** */
6
+ describe('class DYOToolsPlayerElement', () => {
7
+ let playerTest: DTPlayerTest;
8
+
9
+ beforeEach(() => {
10
+ playerTest = new DTPlayerTest();
11
+ });
12
+
13
+ afterEach(() => {
14
+ jest.resetAllMocks();
15
+ });
16
+
17
+ describe('inheritance', () => {
18
+ test('check good inheritance for class', () => {
19
+ expect(DTPlayer.prototype instanceof DTElement).toBeTruthy();
20
+ });
21
+ });
22
+
23
+ describe('_domain', () => {
24
+ test('domain must be "player"', () => {
25
+ expect(playerTest.th_get_domain()).toBe('player');
26
+ });
27
+ });
28
+ });
@@ -0,0 +1,92 @@
1
+ import {DTPlayer, DTPlayerManager} from '../../../src';
2
+ import {DTAcceptedMetaData, DTManagerItemsType, DTManagerOptions} from "../../../src/types";
3
+ import {DTBunchStubLibrary} from "../../core/DTBunch.double";
4
+ import {DTPlayerStub} from "./DTPlayer.element.double";
5
+
6
+ /******************** STUB PROPERTIES CONSTANTS
7
+ * Fixed properties to use with double classes, avoid auto generated and easy checking on test
8
+ * *****/
9
+ export const IDTest = 'DTPlayerManager-id-1234567';
10
+ export const KeyTest = 'DTPlayerManager-key-1234567';
11
+
12
+ /******************** HELPER TEST CLASS
13
+ * Helper test class, inherits the main component
14
+ * Providing methods to property access and other facilities, in order to avoid using class methods
15
+ * *****/
16
+ export class DTPlayerManagerTest extends DTPlayerManager {
17
+ th_get_id(): string {
18
+ return this._id;
19
+ }
20
+
21
+ th_set_id(id: string): void {
22
+ this._id = id;
23
+ }
24
+
25
+ th_get_key(): string {
26
+ return this._key;
27
+ }
28
+
29
+ th_set_key(key: string): void {
30
+ this._key = key;
31
+ }
32
+
33
+ th_get_domain(): string {
34
+ return this._domain;
35
+ }
36
+
37
+ th_get_items(): any {
38
+ return this._items;
39
+ }
40
+
41
+ th_set_items(items: DTManagerItemsType<DTPlayer<DTAcceptedMetaData>>): void {
42
+ this._items = items;
43
+ }
44
+
45
+ th_get_single_item(id: string): any {
46
+ return this._items[id];
47
+ }
48
+
49
+ th_get_scopes(): any {
50
+ return this._scopes;
51
+ }
52
+
53
+ th_set_scopes(scopes: any): void {
54
+ this._scopes = scopes;
55
+ }
56
+
57
+ th_get_library(): any {
58
+ return this._library;
59
+ }
60
+
61
+ th_set_library(library: any): void {
62
+ this._library = library;
63
+ }
64
+
65
+ th_get_options(): DTManagerOptions {
66
+ return this._options;
67
+ }
68
+ }
69
+
70
+ /** ****************** HELPER METHODS
71
+ * Additional helper methods to use with testing
72
+ * **** */
73
+ export const populateManager = (manager: DTPlayerManagerTest): DTPlayerManagerTest => {
74
+ const mockedElements = [];
75
+
76
+ // Create players Stubs
77
+ let nbPlayers = 3;
78
+ while (nbPlayers > 0) {
79
+ const player = new DTPlayerStub(`player${nbPlayers}`);
80
+ mockedElements.push(player);
81
+
82
+ nbPlayers--;
83
+ }
84
+
85
+ // Library
86
+ manager.th_set_library(new DTBunchStubLibrary(mockedElements));
87
+
88
+ return manager;
89
+ }
90
+
91
+
92
+
@@ -0,0 +1,178 @@
1
+ import {afterEach, beforeEach, describe, expect, jest, test,} from '@jest/globals';
2
+ import {DTManager, DTPlayer, DTPlayerManager} from "../../../src";
3
+ import {DTPlayerManagerTest} from "./DTPlayer.manager.double";
4
+ import {DTPlayerStub, IDTest, KeyTest, KeyTest1, KeyTest2} from "./DTPlayer.element.double";
5
+ import {managerDefaultOptions} from "../../../src/constants";
6
+
7
+ /** ****************** MOCK DEPENDENCIES
8
+ * Dependencies used by the component are mocked with Jest
9
+ * **** */
10
+ jest.mock('../../../src/libs/player/DTPlayer.element');
11
+ jest.mock('../../../src/core/DTBunch');
12
+
13
+ /** *********************** TESTS SUITES ****************************** */
14
+ describe('class DYOToolsPlayerManager', () => {
15
+ let playerManagerTest: DTPlayerManagerTest;
16
+
17
+ beforeEach(() => {
18
+ playerManagerTest = new DTPlayerManagerTest();
19
+ });
20
+
21
+ afterEach(() => {
22
+ jest.resetAllMocks();
23
+ });
24
+
25
+ describe('inheritance', () => {
26
+ test('check good inheritance for class', () => {
27
+ expect(DTPlayerManager.prototype instanceof DTManager).toBeTruthy();
28
+ });
29
+ });
30
+
31
+ describe('_domain', () => {
32
+ test('domain must be "player"', () => {
33
+ expect(playerManagerTest.th_get_domain()).toBe('player');
34
+ });
35
+ });
36
+
37
+ describe('constructor()', () => {
38
+ beforeEach(() => {
39
+ (DTPlayer.prototype.getKey as any).mockImplementation(function() {
40
+ return this._key;
41
+ })
42
+ });
43
+
44
+ test('creation simple empty manager', () => {
45
+ const newPlayerManager = new DTPlayerManagerTest();
46
+
47
+ expect(newPlayerManager.th_get_key()).toBe('player');
48
+ expect(newPlayerManager.th_get_items()).toStrictEqual({});
49
+ expect(newPlayerManager.th_get_scopes()).toStrictEqual(['default', 'virtual']);
50
+ expect(newPlayerManager.th_get_library()).toBeDefined();
51
+ });
52
+
53
+ test('creation with simple configuration - player number', () => {
54
+ const configuration = {
55
+ players: 3
56
+ }
57
+ const newPlayerManager = new DTPlayerManagerTest(configuration);
58
+
59
+ expect(newPlayerManager.th_get_items()).toStrictEqual({});
60
+
61
+ // Check creation of 3 DTPlayer
62
+ let calls = 3;
63
+ expect((DTPlayer.prototype.constructor as any).mock.calls.length).toBe(calls);
64
+ while (calls > 0) {
65
+ expect((DTPlayer.prototype.constructor as any).mock.calls[calls - 1][0]).toBe(`player${calls}`);
66
+ calls--;
67
+ }
68
+
69
+ // Check adding 3 DTPlayer to library
70
+ expect((newPlayerManager.th_get_library().add as any).mock.calls.length).toBe(3);
71
+ });
72
+
73
+ test('creation with simple configuration - player array', () => {
74
+ const configuration = {
75
+ players: [
76
+ new DTPlayerStub(KeyTest),
77
+ new DTPlayerStub(KeyTest1),
78
+ new DTPlayerStub(KeyTest2),
79
+ ]
80
+ }
81
+ const newPlayerManager = new DTPlayerManagerTest(configuration);
82
+
83
+ expect(newPlayerManager.th_get_items()).toStrictEqual({});
84
+ expect((newPlayerManager.th_get_library().addMany as any).mock.calls.length).toBe(1);
85
+ expect((newPlayerManager.th_get_library().addMany as any).mock.calls[0][0].length).toBe(3);
86
+ expect((newPlayerManager.th_get_library().addMany as any).mock.calls[0][0][0].th_get_key()).toBe(KeyTest);
87
+ expect((newPlayerManager.th_get_library().addMany as any).mock.calls[0][0][1].th_get_key()).toBe(KeyTest1);
88
+ expect((newPlayerManager.th_get_library().addMany as any).mock.calls[0][0][2].th_get_key()).toBe(KeyTest2);
89
+ });
90
+
91
+ test('creation with simple configuration - invalid player number', () => {
92
+ const configuration = {
93
+ players: -3
94
+ }
95
+ const newPlayerManager = new DTPlayerManagerTest(configuration);
96
+
97
+ expect(newPlayerManager.th_get_items()).toStrictEqual({});
98
+
99
+ // No creation and adding
100
+ expect((DTPlayer.prototype.constructor as any).mock.calls.length).toBe(0);
101
+ expect((newPlayerManager.th_get_library().add as any).mock.calls.length).toBe(0);
102
+ });
103
+
104
+ test('creation with simple configuration - errors manager option', () => {
105
+ const configuration = {
106
+ errors: true
107
+ };
108
+ const newPlayerManager = new DTPlayerManagerTest(configuration);
109
+
110
+ expect(newPlayerManager.th_get_options()).toStrictEqual({
111
+ ...managerDefaultOptions,
112
+ errors: true
113
+ });
114
+ });
115
+ });
116
+
117
+ describe('getPlayer()', () => {
118
+ beforeEach(() => {
119
+ jest.spyOn(playerManagerTest, 'getLibrary').mockReturnValue(playerManagerTest.th_get_library());
120
+ });
121
+
122
+ test('alias - call get() of library', () => {
123
+ const library = playerManagerTest.th_get_library();
124
+
125
+ playerManagerTest.getPlayer(IDTest);
126
+
127
+ expect((library.get).mock.calls.length).toBe(1);
128
+ expect((library.get).mock.calls[0][0]).toBe(IDTest);
129
+ });
130
+ });
131
+
132
+ describe('addPlayer()', () => {
133
+ beforeEach(() => {
134
+ jest.spyOn(playerManagerTest, 'getLibrary').mockReturnValue(playerManagerTest.th_get_library());
135
+ });
136
+
137
+ test('alias - call add() of library', () => {
138
+ const library = playerManagerTest.th_get_library();
139
+ const playerToAdd = new DTPlayerStub(KeyTest);
140
+
141
+ playerManagerTest.addPlayer(playerToAdd);
142
+
143
+ expect((library.add).mock.calls.length).toBe(1);
144
+ expect((library.add).mock.calls[0][0]).toStrictEqual(playerToAdd);
145
+ });
146
+ });
147
+
148
+ describe('removePlayer()', () => {
149
+ beforeEach(() => {
150
+ jest.spyOn(playerManagerTest, 'getLibrary').mockReturnValue(playerManagerTest.th_get_library());
151
+ });
152
+
153
+ test('alias - call remove() of library', () => {
154
+ const library = playerManagerTest.th_get_library();
155
+
156
+ playerManagerTest.removePlayer(IDTest);
157
+
158
+ expect((library.remove).mock.calls.length).toBe(1);
159
+ expect((library.remove).mock.calls[0][0]).toBe(IDTest);
160
+ });
161
+ });
162
+
163
+ describe('findPlayers()', () => {
164
+ beforeEach(() => {
165
+ jest.spyOn(playerManagerTest, 'getLibrary').mockReturnValue(playerManagerTest.th_get_library());
166
+ });
167
+
168
+ test('alias - call find() of library', () => {
169
+ const library = playerManagerTest.th_get_library();
170
+ const testFilters = { id: { $eq: IDTest }, key: { $ne: KeyTest } };
171
+
172
+ playerManagerTest.findPlayers(testFilters);
173
+
174
+ expect((library.find).mock.calls.length).toBe(1);
175
+ expect((library.find).mock.calls[0][0]).toStrictEqual(testFilters);
176
+ });
177
+ });
178
+ });
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "declaration": true,
5
+ "removeComments": true,
6
+ "emitDecoratorMetadata": true,
7
+ "experimentalDecorators": true,
8
+ "allowSyntheticDefaultImports": true,
9
+ "target": "es2015",
10
+ "sourceMap": true,
11
+ "outDir": "./dist",
12
+ "baseUrl": "./",
13
+ "incremental": true
14
+ },
15
+ "include": [
16
+ "src/**/*.ts",
17
+ "test/**/*.ts"
18
+ ],
19
+ "exclude": [
20
+ "node_modules"
21
+ ]
22
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "declaration": true,
5
+ "removeComments": true,
6
+ "emitDecoratorMetadata": true,
7
+ "experimentalDecorators": true,
8
+ "allowSyntheticDefaultImports": true,
9
+ "target": "es2015",
10
+ "sourceMap": true,
11
+ "outDir": "./dist",
12
+ "baseUrl": "./",
13
+ "incremental": true
14
+ },
15
+ "include": [
16
+ "src/**/*.ts"
17
+ ],
18
+ "exclude": [
19
+ "node_modules"
20
+ ]
21
+ }
@@ -1,8 +0,0 @@
1
- import DYOToolsComponentWithMeta from './DTComponentWithMeta';
2
- import { DTAcceptedMetaData, DTPlayerToObject } from '../types';
3
- export default class DYOToolsPlayer<IComponentMeta extends DTAcceptedMetaData> extends DYOToolsComponentWithMeta<IComponentMeta> {
4
- protected _componentType: string;
5
- copy(): DYOToolsPlayer<IComponentMeta>;
6
- toObject(): DTPlayerToObject<IComponentMeta>;
7
- toString(): string;
8
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const DTComponentWithMeta_1 = require("./DTComponentWithMeta");
4
- class DYOToolsPlayer extends DTComponentWithMeta_1.default {
5
- constructor() {
6
- super(...arguments);
7
- this._componentType = 'player';
8
- }
9
- copy() {
10
- const copyElement = new DYOToolsPlayer(this._key);
11
- copyElement.setManyMeta(Object.assign({}, this.getManyMeta()));
12
- return copyElement;
13
- }
14
- toObject() {
15
- const objectPlayer = {
16
- id: this._id,
17
- key: this._key,
18
- type: this._componentType,
19
- };
20
- if (this._meta && Object.keys(this._meta).length > 0) {
21
- objectPlayer.meta = Object.assign({}, this.getManyMeta());
22
- }
23
- return objectPlayer;
24
- }
25
- toString() {
26
- return `Component ${this._key} - Type: Player`;
27
- }
28
- }
29
- exports.default = DYOToolsPlayer;
30
- //# sourceMappingURL=DTPlayer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DTPlayer.js","sourceRoot":"","sources":["../../src/core/DTPlayer.ts"],"names":[],"mappings":";;AAAA,+DAA8D;AAG9D,MAAqB,cAA0D,SAAQ,6BAAyC;IAAhI;;QAIY,mBAAc,GAAG,QAAQ,CAAC;IAiDtC,CAAC;IAxCC,IAAI;QACF,MAAM,WAAW,GAAG,IAAI,cAAc,CAAiB,IAAI,CAAC,IAAI,CAAC,CAAC;QAClE,WAAW,CAAC,WAAW,mBAAM,IAAI,CAAC,WAAW,EAAE,EAAG,CAAC;QAEnD,OAAO,WAAW,CAAC;IACrB,CAAC;IAaD,QAAQ;QACN,MAAM,YAAY,GAAqC;YACrD,EAAE,EAAE,IAAI,CAAC,GAAG;YACZ,GAAG,EAAE,IAAI,CAAC,IAAI;YACd,IAAI,EAAE,IAAI,CAAC,cAAc;SAC1B,CAAC;QAEF,IAAI,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACpD,YAAY,CAAC,IAAI,qBAAQ,IAAI,CAAC,WAAW,EAAE,CAAE,CAAC;SAC/C;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAOD,QAAQ;QACN,OAAO,aAAa,IAAI,CAAC,IAAI,iBAAiB,CAAC;IACjD,CAAC;CACF;AArDD,iCAqDC"}
@@ -1,6 +0,0 @@
1
- import { FilterOperatorType, StandardPrimitiveType } from '../types';
2
- export declare function validFiltersForItem(itemProp: StandardPrimitiveType, filter: StandardPrimitiveType, operator: FilterOperatorType.EQ): boolean;
3
- export declare function validFiltersForItem(itemProp: StandardPrimitiveType, filter: StandardPrimitiveType[], operator: FilterOperatorType.IN | FilterOperatorType.NIN): boolean;
4
- export declare function validFiltersForItem(itemProp: StandardPrimitiveType, filter: StandardPrimitiveType, operator: FilterOperatorType.NE): boolean;
5
- export declare function validFiltersForItem(itemProp: number, filter: number, operator: FilterOperatorType.LTE | FilterOperatorType.GTE): boolean;
6
- export declare function validFiltersForItem(itemProp: StandardPrimitiveType[], filter: StandardPrimitiveType, operator: FilterOperatorType.CONTAINS | FilterOperatorType.NCONTAINS): boolean;