dyo-tools 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.c8rc.json +4 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +47 -0
- package/LICENSE +21 -0
- package/Makefile +34 -0
- package/README.md +0 -7
- package/babel.config.js +1 -0
- package/cucumber-report.html +48 -0
- package/cucumber.js +9 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +63 -0
- package/dist/constants.js.map +1 -0
- package/dist/core/DTBunch.d.ts +11 -15
- package/dist/core/DTBunch.js +27 -106
- package/dist/core/DTBunch.js.map +1 -1
- package/dist/core/DTComponent.d.ts +13 -5
- package/dist/core/DTComponent.js +39 -1
- package/dist/core/DTComponent.js.map +1 -1
- package/dist/core/DTComponentPhysical.d.ts +10 -0
- package/dist/core/DTComponentPhysical.js +16 -0
- package/dist/core/DTComponentPhysical.js.map +1 -0
- package/dist/core/DTComponentWithMeta.d.ts +2 -2
- package/dist/core/DTComponentWithMeta.js.map +1 -1
- package/dist/core/DTElement.d.ts +2 -7
- package/dist/core/DTElement.js +3 -12
- package/dist/core/DTElement.js.map +1 -1
- package/dist/core/DTManager.d.ts +31 -0
- package/dist/core/DTManager.js +180 -0
- package/dist/core/DTManager.js.map +1 -0
- package/dist/core/DTPlayer.js +1 -1
- package/dist/core/DTPlayer.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/libs/DYOFinder.d.ts +10 -0
- package/dist/libs/DYOFinder.js +96 -0
- package/dist/libs/DYOFinder.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1321
- package/dist/types/index.d.ts +64 -24
- package/dist/types/index.js.map +1 -1
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +29 -0
- package/docs/assets/main.js +58 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1367 -0
- package/docs/index.html +46 -0
- package/e2e/0.2.0/epic1.feature +29 -0
- package/e2e/0.2.0/epic2.feature +22 -0
- package/e2e/0.2.0/epic3.feature +25 -0
- package/e2e/0.2.0/resources/dominion.js +195 -0
- package/e2e/0.2.0/resources/utils.js +27 -0
- package/e2e/0.2.0/support/steps.js +108 -0
- package/e2e/future/epic4.feature +39 -0
- package/e2e/future/resources/dominion.js +238 -0
- package/e2e/future/resources/utils.js +27 -0
- package/jest.config.js +6 -0
- package/package.json +33 -23
- package/src/constants.ts +85 -0
- package/src/core/DTBunch.ts +461 -0
- package/src/core/DTComponent.ts +225 -0
- package/src/core/DTComponentPhysical.ts +39 -0
- package/src/core/DTComponentWithMeta.ts +65 -0
- package/src/core/DTElement.ts +69 -0
- package/src/core/DTError.ts +78 -0
- package/src/core/DTManager.ts +446 -0
- package/src/core/DTPlayer.ts +57 -0
- package/src/index.ts +9 -0
- package/src/libs/DYOFinder.ts +175 -0
- package/src/types/index.ts +162 -0
- package/test/core/DTBunch.double.ts +253 -0
- package/test/core/DTBunch.spec.ts +895 -0
- package/test/core/DTComponent.double.ts +164 -0
- package/test/core/DTComponent.spec.ts +295 -0
- package/test/core/DTComponentPhysical.double.ts +76 -0
- package/test/core/DTComponentPhysical.spec.ts +64 -0
- package/test/core/DTComponentWithMeta.double.ts +115 -0
- package/test/core/DTComponentWithMeta.spec.ts +124 -0
- package/test/core/DTElement.double.ts +147 -0
- package/test/core/DTElement.spec.ts +102 -0
- package/test/core/DTError.double.ts +92 -0
- package/test/core/DTError.spec.ts +89 -0
- package/test/core/DTManager.double.ts +192 -0
- package/test/core/DTManager.spec.ts +902 -0
- package/test/core/DTPlayer.double.ts +64 -0
- package/test/core/DTPlayer.spec.ts +80 -0
- package/test/core/copy.spec.ts +227 -0
- package/test/libs/DYOFinder.double.ts +152 -0
- package/test/libs/DYOFinder.spec.ts +194 -0
- package/tsconfig.dev.json +22 -0
- package/tsconfig.json +21 -0
- package/dist/utils/filters.d.ts +0 -6
- package/dist/utils/filters.js +0 -39
- package/dist/utils/filters.js.map +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {DTPlayer} from '../../src';
|
|
2
|
+
import {IMetaDataTest} from './DTComponentWithMeta.double';
|
|
3
|
+
|
|
4
|
+
/******************** STUB PROPERTIES CONSTANTS
|
|
5
|
+
* Fixed properties to use with double classes, avoid auto generated and easy checking on test
|
|
6
|
+
* *****/
|
|
7
|
+
export const IDTest = 'DTPlayer-id-1234567';
|
|
8
|
+
export const KeyTest = 'DTPlayer-key-1234567';
|
|
9
|
+
export const toStringTest = 'DTPlayer Stub toString';
|
|
10
|
+
|
|
11
|
+
/******************** HELPER TEST CLASS
|
|
12
|
+
* Helper test class, inherits the main component
|
|
13
|
+
* Providing methods to property access and other facilities, in order to avoid using class methods
|
|
14
|
+
* *****/
|
|
15
|
+
export class DTPlayerTest extends DTPlayer<IMetaDataTest> {
|
|
16
|
+
th_get_id(): string {
|
|
17
|
+
return this._id;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
th_set_id(id: string): void {
|
|
21
|
+
this._id = id;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
th_get_key(): string {
|
|
25
|
+
return this._key;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
th_set_key(key: string): void {
|
|
29
|
+
this._key = key;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
th_get_componentType(): string {
|
|
33
|
+
return this._componentType;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
th_set_meta(meta: IMetaDataTest): void {
|
|
37
|
+
this._meta = meta;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/******************** STUB CLASS
|
|
42
|
+
* Stub class, for using in other component
|
|
43
|
+
* *****/
|
|
44
|
+
export class DTPlayerStub extends DTPlayer<{}> {
|
|
45
|
+
constructor() {
|
|
46
|
+
super();
|
|
47
|
+
this._id = IDTest;
|
|
48
|
+
this._key = KeyTest;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getKey(): string {
|
|
52
|
+
return KeyTest;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getId(): string {
|
|
56
|
+
return IDTest;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
toString(): string {
|
|
60
|
+
return toStringTest;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {beforeEach, describe, expect, jest, test} from '@jest/globals';
|
|
2
|
+
import {DTPlayerTest, IDTest, KeyTest} from './DTPlayer.double';
|
|
3
|
+
import {mockOverriddenMethods, PlayerMetaData} from './DTComponentWithMeta.double';
|
|
4
|
+
import {DTComponentWithMeta, DTPlayer} from "../../src";
|
|
5
|
+
|
|
6
|
+
/******************** MOCK DEPENDENCIES
|
|
7
|
+
* All Dependencies used by the component are mocked with Jest
|
|
8
|
+
* *****/
|
|
9
|
+
jest.mock('../../src/core/DTComponent');
|
|
10
|
+
jest.mock('../../src/core/DTComponentWithMeta');
|
|
11
|
+
mockOverriddenMethods(DTComponentWithMeta);
|
|
12
|
+
|
|
13
|
+
/************************* TESTS SUITES *******************************/
|
|
14
|
+
describe('class DYOToolsPlayer', () => {
|
|
15
|
+
let playerTest: DTPlayerTest;
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
playerTest = new DTPlayerTest();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
jest.resetAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('inheritance', () => {
|
|
26
|
+
test('check good inheritance for class', () => {
|
|
27
|
+
expect(DTPlayer.prototype instanceof DTComponentWithMeta).toBeTruthy();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('_componentType', () => {
|
|
32
|
+
test('componentType must be "player"', () => {
|
|
33
|
+
expect(playerTest.th_get_componentType()).toBe('player');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('copy()', () => {
|
|
38
|
+
// @see copy.spec.ts for unit tests about copy method
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('toObject()', () => {
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
playerTest.th_set_id(IDTest);
|
|
44
|
+
playerTest.th_set_key(KeyTest);
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('toObject output standard', () => {
|
|
48
|
+
const toObjectPlayer = playerTest.toObject();
|
|
49
|
+
|
|
50
|
+
expect(Object.keys(toObjectPlayer)).toStrictEqual(['id', 'key', 'type']);
|
|
51
|
+
expect(toObjectPlayer.id).toBe(IDTest);
|
|
52
|
+
expect(toObjectPlayer.key).toBe(KeyTest);
|
|
53
|
+
expect(toObjectPlayer.type).toBe('player');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('toObject output standard with meta', () => {
|
|
57
|
+
jest.spyOn(playerTest, 'getManyMeta').mockImplementation(function () {
|
|
58
|
+
return this._meta;
|
|
59
|
+
});
|
|
60
|
+
playerTest.th_set_meta(PlayerMetaData);
|
|
61
|
+
|
|
62
|
+
const toObjectPlayer = playerTest.toObject();
|
|
63
|
+
|
|
64
|
+
expect(Object.keys(toObjectPlayer)).toStrictEqual(['id', 'key', 'type', 'meta']);
|
|
65
|
+
expect(toObjectPlayer.meta).toStrictEqual(PlayerMetaData);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('toString()', () => {
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
playerTest.th_set_key(KeyTest);
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('string output standard', () => {
|
|
75
|
+
const toStringElement = playerTest.toString();
|
|
76
|
+
|
|
77
|
+
expect(toStringElement).toBe(`Component ${KeyTest} - Type: Player`);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describe, expect, jest, test,
|
|
3
|
+
} from '@jest/globals';
|
|
4
|
+
import { DTBunch, DTElement, DTPlayer } from '../../src';
|
|
5
|
+
import { DTComponentStub } from './DTComponent.double';
|
|
6
|
+
import { DTPlayerStub } from './DTPlayer.double';
|
|
7
|
+
import {
|
|
8
|
+
BunchMetaData, HaileiMetaData, IMetaDataTest, PlayerMetaData,
|
|
9
|
+
} from './DTComponentWithMeta.double';
|
|
10
|
+
import { defaultOptions, KeyTest } from './DTBunch.double';
|
|
11
|
+
import { DTErrorStub } from './DTError.double';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Special test suite for copy overridden method
|
|
15
|
+
* Unfortunately copy is very hard to mock correctly in Javascript, due to constructor mocks
|
|
16
|
+
* These test doesn't handle the DOC
|
|
17
|
+
* Mock for :
|
|
18
|
+
* - DTBunch
|
|
19
|
+
* - DTElement
|
|
20
|
+
* - DTPlayer
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
describe('Inherited method copy', () => {
|
|
24
|
+
describe('DTBunch copy()', () => {
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
jest.resetAllMocks();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('copy a bunch - simple case with id and key', () => {
|
|
30
|
+
const bunch = new DTBunch(KeyTest);
|
|
31
|
+
const bunchCopy = bunch.copy();
|
|
32
|
+
|
|
33
|
+
expect(bunch.getId() === bunchCopy.getId()).toBeFalsy();
|
|
34
|
+
expect(bunch.getKey() === bunchCopy.getKey()).toBeTruthy();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('copy a bunch - not copy owner and context', () => {
|
|
38
|
+
const bunch = new DTBunch(KeyTest);
|
|
39
|
+
jest.spyOn(bunch, 'setContext').mockImplementation(function (context) {
|
|
40
|
+
this._context = context;
|
|
41
|
+
});
|
|
42
|
+
jest.spyOn(bunch, 'setOwner').mockImplementation(function (owner) {
|
|
43
|
+
this._owner = owner;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
bunch.setContext(new DTComponentStub());
|
|
47
|
+
bunch.setOwner(new DTPlayerStub());
|
|
48
|
+
|
|
49
|
+
const bunchCopy = bunch.copy();
|
|
50
|
+
jest.spyOn(bunchCopy, 'getContext').mockImplementation(function () {
|
|
51
|
+
return this._context;
|
|
52
|
+
});
|
|
53
|
+
jest.spyOn(bunchCopy, 'getOwner').mockImplementation(function () {
|
|
54
|
+
return this._owner;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(bunchCopy.getContext()).toBeUndefined();
|
|
58
|
+
expect(bunchCopy.getOwner()).toBeUndefined();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('copy a bunch - copy meta-data and globalOptions', () => {
|
|
62
|
+
const copiedOptions = {
|
|
63
|
+
inheritOwner: true,
|
|
64
|
+
replaceIndex: true,
|
|
65
|
+
virtualContext: true,
|
|
66
|
+
};
|
|
67
|
+
const bunch = new DTBunch('', [], copiedOptions);
|
|
68
|
+
jest.spyOn(bunch, 'getManyMeta').mockImplementation(() => BunchMetaData);
|
|
69
|
+
|
|
70
|
+
const bunchCopy = bunch.copy();
|
|
71
|
+
|
|
72
|
+
expect(bunchCopy.getManyMeta()).toStrictEqual(BunchMetaData);
|
|
73
|
+
expect(bunchCopy.getOptions()).toStrictEqual({
|
|
74
|
+
...defaultOptions,
|
|
75
|
+
...copiedOptions,
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('copy a bunch - empty errors', () => {
|
|
80
|
+
const bunch = new DTBunch(KeyTest, [], { errors: true });
|
|
81
|
+
bunch.triggerError(new DTErrorStub());
|
|
82
|
+
bunch.triggerError(new DTErrorStub());
|
|
83
|
+
|
|
84
|
+
const bunchCopy = bunch.copy();
|
|
85
|
+
|
|
86
|
+
expect(bunchCopy.getErrors().length).toBe(0);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('copy a bunch with items - default case', () => {
|
|
90
|
+
const items: Array<DTElement<IMetaDataTest>> = [
|
|
91
|
+
new DTElement(),
|
|
92
|
+
new DTElement(),
|
|
93
|
+
new DTElement(),
|
|
94
|
+
];
|
|
95
|
+
jest.spyOn(items[0], 'copy');
|
|
96
|
+
jest.spyOn(items[1], 'copy');
|
|
97
|
+
jest.spyOn(items[2], 'copy');
|
|
98
|
+
const bunch = new DTBunch<DTElement<IMetaDataTest>, IMetaDataTest>(KeyTest, items);
|
|
99
|
+
|
|
100
|
+
const bunchCopy = bunch.copy();
|
|
101
|
+
|
|
102
|
+
expect(bunchCopy.getAll().length).toBe(3);
|
|
103
|
+
expect((items[0].copy as any).mock.calls.length).toBe(1);
|
|
104
|
+
expect((items[1].copy as any).mock.calls.length).toBe(1);
|
|
105
|
+
expect((items[2].copy as any).mock.calls.length).toBe(1);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('copy a bunch with items - virtual context case', () => {
|
|
109
|
+
const items: Array<DTElement<IMetaDataTest>> = [
|
|
110
|
+
new DTElement(),
|
|
111
|
+
new DTElement(),
|
|
112
|
+
new DTElement(),
|
|
113
|
+
];
|
|
114
|
+
jest.spyOn(items[0], 'copy');
|
|
115
|
+
jest.spyOn(items[1], 'copy');
|
|
116
|
+
jest.spyOn(items[2], 'copy');
|
|
117
|
+
const bunch = new DTBunch<DTElement<IMetaDataTest>, IMetaDataTest>(KeyTest, items, { virtualContext: true });
|
|
118
|
+
|
|
119
|
+
const bunchCopy = bunch.copy();
|
|
120
|
+
|
|
121
|
+
expect(bunchCopy.getAll().length).toBe(3);
|
|
122
|
+
expect((items[0].copy as any).mock.calls.length).toBe(0);
|
|
123
|
+
expect((items[1].copy as any).mock.calls.length).toBe(0);
|
|
124
|
+
expect((items[2].copy as any).mock.calls.length).toBe(0);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe('DTElement copy()', () => {
|
|
129
|
+
afterEach(() => {
|
|
130
|
+
jest.resetAllMocks();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('copy an element - simple case with id and key', () => {
|
|
134
|
+
const element = new DTElement(KeyTest);
|
|
135
|
+
const elementCopy = element.copy();
|
|
136
|
+
|
|
137
|
+
expect(element.getId() === elementCopy.getId()).toBeFalsy();
|
|
138
|
+
expect(element.getKey() === elementCopy.getKey()).toBeTruthy();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('copy an element - not copy context', () => {
|
|
142
|
+
const element = new DTElement(KeyTest);
|
|
143
|
+
jest.spyOn(element, 'setContext').mockImplementation(function (context) {
|
|
144
|
+
this._context = context;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
element.setContext(new DTComponentStub());
|
|
148
|
+
|
|
149
|
+
const elementCopy = element.copy();
|
|
150
|
+
jest.spyOn(elementCopy, 'getContext').mockImplementation(function () {
|
|
151
|
+
return this._context;
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
expect(elementCopy.getContext()).toBeUndefined();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('copy an element - copy meta-data and options', () => {
|
|
158
|
+
const element = new DTElement(KeyTest, { errors: true });
|
|
159
|
+
jest.spyOn(element, 'getManyMeta').mockImplementation(() => HaileiMetaData);
|
|
160
|
+
|
|
161
|
+
const elementCopy = element.copy();
|
|
162
|
+
|
|
163
|
+
expect(elementCopy.getManyMeta()).toStrictEqual(HaileiMetaData);
|
|
164
|
+
expect(elementCopy.getOptions()).toStrictEqual({ errors: true });
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('copy an element - empty errors', () => {
|
|
168
|
+
const element = new DTElement(KeyTest, { errors: true });
|
|
169
|
+
element.triggerError(new DTErrorStub());
|
|
170
|
+
element.triggerError(new DTErrorStub());
|
|
171
|
+
|
|
172
|
+
const elementCopy = element.copy();
|
|
173
|
+
|
|
174
|
+
expect(elementCopy.getErrors().length).toBe(0);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('DTPlayer copy()', () => {
|
|
179
|
+
afterEach(() => {
|
|
180
|
+
jest.resetAllMocks();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('copy a player - simple case with id and key', () => {
|
|
184
|
+
const player = new DTPlayer(KeyTest);
|
|
185
|
+
const playerCopy = player.copy();
|
|
186
|
+
|
|
187
|
+
expect(player.getId() === playerCopy.getId()).toBeFalsy();
|
|
188
|
+
expect(player.getKey() === playerCopy.getKey()).toBeTruthy();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('copy a player - not copy context', () => {
|
|
192
|
+
const player = new DTPlayer(KeyTest);
|
|
193
|
+
jest.spyOn(player, 'setContext').mockImplementation(function (context) {
|
|
194
|
+
this._context = context;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
player.setContext(new DTComponentStub());
|
|
198
|
+
|
|
199
|
+
const playerCopy = player.copy();
|
|
200
|
+
jest.spyOn(playerCopy, 'getContext').mockImplementation(function () {
|
|
201
|
+
return this._context;
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
expect(playerCopy.getContext()).toBeUndefined();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test('copy a player - copy meta-data and options', () => {
|
|
208
|
+
const player = new DTPlayer(KeyTest, { errors: true });
|
|
209
|
+
jest.spyOn(player, 'getManyMeta').mockImplementation(() => PlayerMetaData);
|
|
210
|
+
|
|
211
|
+
const playerCopy = player.copy();
|
|
212
|
+
|
|
213
|
+
expect(playerCopy.getManyMeta()).toStrictEqual(PlayerMetaData);
|
|
214
|
+
expect(playerCopy.getOptions()).toStrictEqual({ errors: true });
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('copy a player - empty errors', () => {
|
|
218
|
+
const player = new DTPlayer(KeyTest, { errors: true });
|
|
219
|
+
player.triggerError(new DTErrorStub());
|
|
220
|
+
player.triggerError(new DTErrorStub());
|
|
221
|
+
|
|
222
|
+
const playerCopy = player.copy();
|
|
223
|
+
|
|
224
|
+
expect(playerCopy.getErrors().length).toBe(0);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { DYOFinderConfiguration, FilterOperatorType } from '../../src/types';
|
|
2
|
+
import DYOFinder from '../../src/libs/DYOFinder';
|
|
3
|
+
import { DTBunchStub } from '../core/DTBunch.double';
|
|
4
|
+
import { DTElementStubExtended } from '../core/DTElement.double';
|
|
5
|
+
|
|
6
|
+
/** ****************** STUB PROPERTIES CONSTANTS
|
|
7
|
+
* Fixed properties to use with double classes, avoid auto generated and easy checking on test
|
|
8
|
+
* **** */
|
|
9
|
+
const baseOperators = [
|
|
10
|
+
FilterOperatorType.EQ,
|
|
11
|
+
FilterOperatorType.IN,
|
|
12
|
+
FilterOperatorType.NIN,
|
|
13
|
+
FilterOperatorType.NE,
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export const DefaultConfiguration: DYOFinderConfiguration = {
|
|
17
|
+
propString: {
|
|
18
|
+
operators: baseOperators,
|
|
19
|
+
getValue: (item: any) => item.getPropString(),
|
|
20
|
+
objectSearch: false,
|
|
21
|
+
},
|
|
22
|
+
propArray: {
|
|
23
|
+
operators: [...baseOperators, FilterOperatorType.CONTAINS, FilterOperatorType.NCONTAINS],
|
|
24
|
+
getValue: (item: any) => item.getPropArray(),
|
|
25
|
+
objectSearch: false,
|
|
26
|
+
},
|
|
27
|
+
propNumber: {
|
|
28
|
+
operators: [...baseOperators, FilterOperatorType.LTE, FilterOperatorType.GTE],
|
|
29
|
+
getValue: (item: any) => item.getPropNumber(),
|
|
30
|
+
objectSearch: false,
|
|
31
|
+
},
|
|
32
|
+
propBoolean: {
|
|
33
|
+
operators: baseOperators,
|
|
34
|
+
getValue: (item: any) => item.getPropBoolean(),
|
|
35
|
+
objectSearch: false,
|
|
36
|
+
},
|
|
37
|
+
propObject: {
|
|
38
|
+
operators: baseOperators,
|
|
39
|
+
getValue: (item: any) => item.getPropObject(),
|
|
40
|
+
objectSearch: false,
|
|
41
|
+
},
|
|
42
|
+
propMeta: {
|
|
43
|
+
operators: baseOperators,
|
|
44
|
+
getValue: (item: any) => item.getPropMeta(),
|
|
45
|
+
objectSearch: true,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** ****************** HELPER TEST CLASS
|
|
50
|
+
* Helper test class, inherits the main component
|
|
51
|
+
* Providing methods to property access and other facilities, in order to avoid using class methods
|
|
52
|
+
* **** */
|
|
53
|
+
export default class DYOFinderTest extends DYOFinder {
|
|
54
|
+
th_get_component(): any {
|
|
55
|
+
return this._component;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
th_get_configuration(): DYOFinderConfiguration {
|
|
59
|
+
return this._configuration;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
th_set_configuration(configuration: DYOFinderConfiguration): void {
|
|
63
|
+
this._configuration = {
|
|
64
|
+
...this._configuration,
|
|
65
|
+
...configuration,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** ****************** STUB CLASS
|
|
71
|
+
* Stub class, for using in other component
|
|
72
|
+
* **** */
|
|
73
|
+
|
|
74
|
+
/** ****************** HELPER METHODS
|
|
75
|
+
* Additional helper methods to use with testing
|
|
76
|
+
* **** */
|
|
77
|
+
export function generateComponent(): DTBunchStub {
|
|
78
|
+
const elementFindStubData = [
|
|
79
|
+
{
|
|
80
|
+
propString: 'item_prime',
|
|
81
|
+
propArray: ['tag1', 'tag2'],
|
|
82
|
+
propNumber: 17,
|
|
83
|
+
propBoolean: true,
|
|
84
|
+
propObject: {
|
|
85
|
+
data: 'value',
|
|
86
|
+
},
|
|
87
|
+
propMeta: {
|
|
88
|
+
meta1: 'value1',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
propString: 'item_prime',
|
|
93
|
+
propArray: ['tag1', 'tag2', 'tag3'],
|
|
94
|
+
propNumber: 19,
|
|
95
|
+
propBoolean: false,
|
|
96
|
+
propObject: {
|
|
97
|
+
data: 'value',
|
|
98
|
+
},
|
|
99
|
+
propMeta: {
|
|
100
|
+
meta1: 'value1',
|
|
101
|
+
meta2: 'value2',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
propString: 'item_second',
|
|
106
|
+
propArray: ['tag1', 'tag3'],
|
|
107
|
+
propNumber: 23,
|
|
108
|
+
propBoolean: true,
|
|
109
|
+
propObject: {
|
|
110
|
+
data: 'value',
|
|
111
|
+
},
|
|
112
|
+
propMeta: {
|
|
113
|
+
meta1: 'value2',
|
|
114
|
+
meta2: 'value2',
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
propString: 'item_third',
|
|
119
|
+
propNumber: 17,
|
|
120
|
+
propBoolean: false,
|
|
121
|
+
propObject: null,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
propString: 'item_second',
|
|
125
|
+
propArray: [],
|
|
126
|
+
propNumber: 31,
|
|
127
|
+
propBoolean: true,
|
|
128
|
+
propObject: null,
|
|
129
|
+
propMeta: {
|
|
130
|
+
meta3: 'value3',
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
const items = [];
|
|
136
|
+
let itemIndex = 0;
|
|
137
|
+
for (const data of elementFindStubData) {
|
|
138
|
+
const elementStub = new DTElementStubExtended();
|
|
139
|
+
elementStub.parentIndex = itemIndex;
|
|
140
|
+
elementStub.setPropString(data.propString);
|
|
141
|
+
elementStub.setPropArray(data.propArray);
|
|
142
|
+
elementStub.setPropNumber(data.propNumber);
|
|
143
|
+
elementStub.setPropBoolean(data.propBoolean);
|
|
144
|
+
elementStub.setPropObject(data.propObject);
|
|
145
|
+
elementStub.setPropMeta(data.propMeta);
|
|
146
|
+
|
|
147
|
+
items.push(elementStub);
|
|
148
|
+
itemIndex += 1;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return new DTBunchStub(items);
|
|
152
|
+
}
|