dyo-tools 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{dist/index.d.ts → index.d.ts} +1 -0
- package/{dist/index.d.ts.map → index.d.ts.map} +1 -1
- package/{dist/index.js → index.js} +1 -0
- package/package.json +6 -56
- package/.c8rc.json +0 -4
- package/.eslintignore +0 -2
- package/.eslintrc.json +0 -47
- package/Makefile +0 -34
- package/README.md +0 -0
- package/babel.config.js +0 -1
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -29
- package/docs/assets/main.js +0 -59
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1414
- package/docs/index.html +0 -1
- package/integration/data/components/DTHero.ts +0 -42
- package/integration/data/components/DTHeroManager.ts +0 -11
- package/integration/data/components/DTHeroPlayZone.ts +0 -6
- package/integration/data/components/DTHeroPlayerHand.ts +0 -11
- package/integration/data/components/index.ts +0 -5
- package/integration/data/in/heroIn.helper.ts +0 -8
- package/integration/data/in/playerIn.helper.ts +0 -13
- package/integration/data/out/heroOut.helper.ts +0 -48
- package/integration/endings/synchronisation.ending.ts +0 -25
- package/integration/scenes/drawCard.scene.ts +0 -31
- package/integration/scenes/empty.scene.ts +0 -6
- package/integration/scenes/playCard.scene.ts +0 -23
- package/integration/scenes/playerLeave.scene.ts +0 -33
- package/integration/stages/baseDix.stage.ts +0 -137
- package/integration/stages/syncDix.stage.ts +0 -36
- package/integration/tests/scenario1.spec.ts +0 -55
- package/integration/types/index.ts +0 -24
- package/jest-integration.config.ts +0 -25
- package/jest.config.ts +0 -26
- package/src/constants.ts +0 -87
- package/src/core/DTAction.ts +0 -54
- package/src/core/DTBunch.ts +0 -531
- package/src/core/DTComponent.ts +0 -258
- package/src/core/DTComponentPhysical.ts +0 -88
- package/src/core/DTComponentWithMeta.ts +0 -98
- package/src/core/DTElement.ts +0 -111
- package/src/core/DTError.ts +0 -78
- package/src/core/DTManager.ts +0 -555
- package/src/core/DTMaster.ts +0 -366
- package/src/core/DTModule.ts +0 -96
- package/src/index.ts +0 -17
- package/src/libs/DYOFinder.ts +0 -175
- package/src/libs/dix/DIXModule.module.ts +0 -98
- package/src/libs/player/DTPlayer.element.ts +0 -9
- package/src/libs/player/DTPlayer.manager.ts +0 -70
- package/src/types/core.ts +0 -204
- package/src/types/index.ts +0 -2
- package/src/types/player.ts +0 -5
- package/test/core/DTAction.double.ts +0 -62
- package/test/core/DTAction.spec.ts +0 -68
- package/test/core/DTBunch.double.ts +0 -175
- package/test/core/DTBunch.spec.ts +0 -822
- package/test/core/DTComponent.double.ts +0 -179
- package/test/core/DTComponent.spec.ts +0 -297
- package/test/core/DTComponentPhysical.double.ts +0 -62
- package/test/core/DTComponentPhysical.spec.ts +0 -81
- package/test/core/DTComponentWithMeta.double.ts +0 -122
- package/test/core/DTComponentWithMeta.spec.ts +0 -129
- package/test/core/DTElement.double.ts +0 -142
- package/test/core/DTElement.spec.ts +0 -123
- package/test/core/DTError.double.ts +0 -57
- package/test/core/DTError.spec.ts +0 -78
- package/test/core/DTManager.double.ts +0 -149
- package/test/core/DTManager.spec.ts +0 -874
- package/test/core/DTMaster.double.ts +0 -117
- package/test/core/DTMaster.spec.ts +0 -537
- package/test/core/DTModule.double.ts +0 -67
- package/test/core/DTModule.spec.ts +0 -124
- package/test/core/copy.spec.ts +0 -222
- package/test/libs/DYOFinder.double.ts +0 -152
- package/test/libs/DYOFinder.spec.ts +0 -194
- package/test/libs/player/DTPlayer.element.double.ts +0 -55
- package/test/libs/player/DTPlayer.element.spec.ts +0 -28
- package/test/libs/player/DTPlayer.manager.double.ts +0 -92
- package/test/libs/player/DTPlayer.manager.spec.ts +0 -178
- package/tsconfig.dev.json +0 -19
- package/tsconfig.json +0 -18
- /package/{dist/constants.d.ts → constants.d.ts} +0 -0
- /package/{dist/constants.d.ts.map → constants.d.ts.map} +0 -0
- /package/{dist/constants.js → constants.js} +0 -0
- /package/{dist/constants.js.map → constants.js.map} +0 -0
- /package/{dist/core → core}/DTAction.d.ts +0 -0
- /package/{dist/core → core}/DTAction.d.ts.map +0 -0
- /package/{dist/core → core}/DTAction.js +0 -0
- /package/{dist/core → core}/DTAction.js.map +0 -0
- /package/{dist/core → core}/DTBunch.d.ts +0 -0
- /package/{dist/core → core}/DTBunch.d.ts.map +0 -0
- /package/{dist/core → core}/DTBunch.js +0 -0
- /package/{dist/core → core}/DTBunch.js.map +0 -0
- /package/{dist/core → core}/DTComponent.d.ts +0 -0
- /package/{dist/core → core}/DTComponent.d.ts.map +0 -0
- /package/{dist/core → core}/DTComponent.js +0 -0
- /package/{dist/core → core}/DTComponent.js.map +0 -0
- /package/{dist/core → core}/DTComponentPhysical.d.ts +0 -0
- /package/{dist/core → core}/DTComponentPhysical.d.ts.map +0 -0
- /package/{dist/core → core}/DTComponentPhysical.js +0 -0
- /package/{dist/core → core}/DTComponentPhysical.js.map +0 -0
- /package/{dist/core → core}/DTComponentWithMeta.d.ts +0 -0
- /package/{dist/core → core}/DTComponentWithMeta.d.ts.map +0 -0
- /package/{dist/core → core}/DTComponentWithMeta.js +0 -0
- /package/{dist/core → core}/DTComponentWithMeta.js.map +0 -0
- /package/{dist/core → core}/DTElement.d.ts +0 -0
- /package/{dist/core → core}/DTElement.d.ts.map +0 -0
- /package/{dist/core → core}/DTElement.js +0 -0
- /package/{dist/core → core}/DTElement.js.map +0 -0
- /package/{dist/core → core}/DTError.d.ts +0 -0
- /package/{dist/core → core}/DTError.d.ts.map +0 -0
- /package/{dist/core → core}/DTError.js +0 -0
- /package/{dist/core → core}/DTError.js.map +0 -0
- /package/{dist/core → core}/DTManager.d.ts +0 -0
- /package/{dist/core → core}/DTManager.d.ts.map +0 -0
- /package/{dist/core → core}/DTManager.js +0 -0
- /package/{dist/core → core}/DTManager.js.map +0 -0
- /package/{dist/core → core}/DTMaster.d.ts +0 -0
- /package/{dist/core → core}/DTMaster.d.ts.map +0 -0
- /package/{dist/core → core}/DTMaster.js +0 -0
- /package/{dist/core → core}/DTMaster.js.map +0 -0
- /package/{dist/core → core}/DTModule.d.ts +0 -0
- /package/{dist/core → core}/DTModule.d.ts.map +0 -0
- /package/{dist/core → core}/DTModule.js +0 -0
- /package/{dist/core → core}/DTModule.js.map +0 -0
- /package/{dist/index.js.map → index.js.map} +0 -0
- /package/{dist/libs → libs}/DYOFinder.d.ts +0 -0
- /package/{dist/libs → libs}/DYOFinder.d.ts.map +0 -0
- /package/{dist/libs → libs}/DYOFinder.js +0 -0
- /package/{dist/libs → libs}/DYOFinder.js.map +0 -0
- /package/{dist/libs → libs}/dix/DIXModule.module.d.ts +0 -0
- /package/{dist/libs → libs}/dix/DIXModule.module.d.ts.map +0 -0
- /package/{dist/libs → libs}/dix/DIXModule.module.js +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.element.d.ts +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.element.d.ts.map +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.element.js +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.element.js.map +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.manager.d.ts +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.manager.d.ts.map +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.manager.js +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.manager.js.map +0 -0
- /package/{dist/tsconfig.dev.tsbuildinfo → tsconfig.dev.tsbuildinfo} +0 -0
- /package/{dist/tsconfig.tsbuildinfo → tsconfig.tsbuildinfo} +0 -0
- /package/{dist/types → types}/core.d.ts +0 -0
- /package/{dist/types → types}/core.d.ts.map +0 -0
- /package/{dist/types → types}/core.js +0 -0
- /package/{dist/types → types}/core.js.map +0 -0
- /package/{dist/types → types}/index.d.ts +0 -0
- /package/{dist/types → types}/index.d.ts.map +0 -0
- /package/{dist/types → types}/index.js +0 -0
- /package/{dist/types → types}/index.js.map +0 -0
- /package/{dist/types → types}/player.d.ts +0 -0
- /package/{dist/types → types}/player.d.ts.map +0 -0
- /package/{dist/types → types}/player.js +0 -0
- /package/{dist/types → types}/player.js.map +0 -0
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {DTAction, DTModule} from "../../src";
|
|
2
|
-
import {HaileiToObjectTest} from "./DTElement.double";
|
|
3
|
-
import {bunch1IdTest} from "./DTBunch.double";
|
|
4
|
-
import {DTModuleToObject} from "../../src/types";
|
|
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 = 'DTModule-id-1234567';
|
|
10
|
-
export const KeyTest = 'DTModule-key-1234567';
|
|
11
|
-
|
|
12
|
-
// Specific Module constants
|
|
13
|
-
export const module1IDTest = `${IDTest}_1`;
|
|
14
|
-
export const module1KeyTest = `${KeyTest}_1`;
|
|
15
|
-
|
|
16
|
-
export const module1ToObject: DTModuleToObject = {
|
|
17
|
-
id: module1IDTest,
|
|
18
|
-
key: module1KeyTest,
|
|
19
|
-
type: 'module',
|
|
20
|
-
enabled: true
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/** ****************** HELPER TEST CLASS
|
|
24
|
-
* Helper test class, inherits the main component
|
|
25
|
-
* Providing methods to property access and other facilities, in order to avoid using class methods
|
|
26
|
-
* **** */
|
|
27
|
-
export class DTModuleTest extends DTModule {
|
|
28
|
-
|
|
29
|
-
constructor(
|
|
30
|
-
id: string = IDTest,
|
|
31
|
-
key: string = KeyTest,
|
|
32
|
-
enabled: boolean = true,
|
|
33
|
-
) {
|
|
34
|
-
super(key);
|
|
35
|
-
this._id = id;
|
|
36
|
-
this._enabled = enabled
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
_getEnabled(): boolean {
|
|
40
|
-
return this._enabled;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
/** ****************** STUB CLASS
|
|
46
|
-
* Stub class, for using in other component
|
|
47
|
-
* **** */
|
|
48
|
-
export class DTModuleStub extends DTModuleTest {
|
|
49
|
-
constructor() {
|
|
50
|
-
super();
|
|
51
|
-
this._id = IDTest;
|
|
52
|
-
this._key = KeyTest;
|
|
53
|
-
this._errors = [];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
_setId(id: string) {
|
|
57
|
-
this._id = id;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
_setKey(key: string) {
|
|
61
|
-
this._key = key;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** ****************** HELPER METHODS
|
|
66
|
-
* Additional helper methods to use with testing
|
|
67
|
-
* **** */
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import {DTComponent, DTModule} from "../../src";
|
|
2
|
-
import {afterEach, beforeEach, describe, expect, jest, test} from "@jest/globals";
|
|
3
|
-
import {DTModuleTest, IDTest, KeyTest} from "./DTModule.double";
|
|
4
|
-
|
|
5
|
-
/** *********************** TESTS SUITES ****************************** */
|
|
6
|
-
describe('class DTModule', () => {
|
|
7
|
-
let moduleTest: DTModuleTest;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
moduleTest = new DTModuleTest();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
afterEach(() => {
|
|
14
|
-
jest.resetAllMocks();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('inheritance', () => {
|
|
18
|
-
test('check good inheritance for class', () => {
|
|
19
|
-
expect(DTModule.prototype instanceof DTComponent).toBeTruthy();
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('_componentType', () => {
|
|
24
|
-
test('componentType must be "action"', () => {
|
|
25
|
-
expect(moduleTest.getComponentType()).toBe('module');
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('constructor()', () => {
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
jest.resetAllMocks();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('simple creation with key', () => {
|
|
35
|
-
const newModule = new DTModuleTest(KeyTest);
|
|
36
|
-
|
|
37
|
-
expect(newModule._getEnabled()).toStrictEqual(true);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('getMaster()', () => {
|
|
42
|
-
test('call get context with master accessor', () => {
|
|
43
|
-
const getContextSpy = jest.spyOn(moduleTest, 'getContext');
|
|
44
|
-
|
|
45
|
-
moduleTest.getMaster();
|
|
46
|
-
|
|
47
|
-
expect(getContextSpy.mock.calls.length).toBe(1);
|
|
48
|
-
expect(getContextSpy.mock.calls[0][0]).toBe('master');
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('isEnabled()', () => {
|
|
53
|
-
test('return true if the module is enabled', () => {
|
|
54
|
-
const enabledModule = moduleTest.isEnabled();
|
|
55
|
-
|
|
56
|
-
expect(enabledModule).toBe(true);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('return false if the module is disabled', () => {
|
|
60
|
-
moduleTest = new DTModuleTest(IDTest, KeyTest, false);
|
|
61
|
-
|
|
62
|
-
const enabledModule = moduleTest.isEnabled();
|
|
63
|
-
|
|
64
|
-
expect(enabledModule).toBe(false);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('enable()', () => {
|
|
69
|
-
test('change enable to true', () => {
|
|
70
|
-
moduleTest = new DTModuleTest(IDTest, KeyTest, false);
|
|
71
|
-
|
|
72
|
-
moduleTest.enable();
|
|
73
|
-
|
|
74
|
-
expect(moduleTest._getEnabled()).toBe(true);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe('disable()', () => {
|
|
79
|
-
test('change enable to false', () => {
|
|
80
|
-
moduleTest = new DTModuleTest(IDTest, KeyTest, true);
|
|
81
|
-
|
|
82
|
-
moduleTest.disable();
|
|
83
|
-
|
|
84
|
-
expect(moduleTest._getEnabled()).toBe(false);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('toString()', () => {
|
|
89
|
-
test('string output standard', () => {
|
|
90
|
-
const toStringAction = moduleTest.toString();
|
|
91
|
-
|
|
92
|
-
expect(toStringAction).toBe(`Component ${KeyTest} - Type: Module`);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('string output standard when disabled', () => {
|
|
96
|
-
moduleTest = new DTModuleTest(IDTest, KeyTest, false);
|
|
97
|
-
|
|
98
|
-
const toStringAction = moduleTest.toString();
|
|
99
|
-
|
|
100
|
-
expect(toStringAction).toBe(`Component ${KeyTest} - Type: Module - Disabled`);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe('toObject()', () => {
|
|
105
|
-
test('toObject output standard', () => {
|
|
106
|
-
const toObjectAction: any = moduleTest.toObject();
|
|
107
|
-
|
|
108
|
-
expect(Object.keys(toObjectAction)).toStrictEqual(['id', 'key', 'type', 'enabled']);
|
|
109
|
-
expect(toObjectAction.id).toBe(IDTest);
|
|
110
|
-
expect(toObjectAction.key).toBe(KeyTest);
|
|
111
|
-
expect(toObjectAction.type).toBe('module');
|
|
112
|
-
expect(toObjectAction.enabled).toBe(true);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test('toObject output standard when disabled', () => {
|
|
116
|
-
moduleTest = new DTModuleTest(IDTest, KeyTest, false);
|
|
117
|
-
|
|
118
|
-
const toObjectAction: any = moduleTest.toObject();
|
|
119
|
-
|
|
120
|
-
expect(Object.keys(toObjectAction)).toStrictEqual(['id', 'key', 'type', 'enabled']);
|
|
121
|
-
expect(toObjectAction.enabled).toBe(false);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
});
|
package/test/core/copy.spec.ts
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
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 {OwnerTest} from './DTComponentPhysical.double';
|
|
7
|
-
import {
|
|
8
|
-
BunchMetaData, HaileiMetaData, IMetaDataTest, PlayerMetaData,
|
|
9
|
-
} from './DTComponentWithMeta.double';
|
|
10
|
-
import { KeyTest } from './DTBunch.double';
|
|
11
|
-
import { DTErrorStub } from './DTError.double';
|
|
12
|
-
import {bunchDefaultOptions} from "../../src/constants";
|
|
13
|
-
|
|
14
|
-
describe('Inherited method copy', () => {
|
|
15
|
-
describe('DTBunch copy()', () => {
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
jest.resetAllMocks();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('copy a bunch - simple case with id and key', () => {
|
|
21
|
-
const bunch = new DTBunch(KeyTest);
|
|
22
|
-
const bunchCopy = bunch.copy();
|
|
23
|
-
|
|
24
|
-
expect(bunch.getId() === bunchCopy.getId()).toBeFalsy();
|
|
25
|
-
expect(bunch.getKey() === bunchCopy.getKey()).toBeTruthy();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('copy a bunch - not copy owner and context', () => {
|
|
29
|
-
const bunch = new DTBunch(KeyTest);
|
|
30
|
-
jest.spyOn(bunch, 'setContext').mockImplementation(function (context) {
|
|
31
|
-
this._context = context;
|
|
32
|
-
});
|
|
33
|
-
jest.spyOn(bunch, 'setOwner').mockImplementation(function (owner) {
|
|
34
|
-
this._owner = owner;
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
bunch.setContext(new DTComponentStub());
|
|
38
|
-
bunch.setOwner(OwnerTest);
|
|
39
|
-
|
|
40
|
-
const bunchCopy = bunch.copy();
|
|
41
|
-
jest.spyOn(bunchCopy, 'getContext').mockImplementation(function () {
|
|
42
|
-
return this._context;
|
|
43
|
-
});
|
|
44
|
-
jest.spyOn(bunchCopy, 'getOwner').mockImplementation(function () {
|
|
45
|
-
return this._owner;
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
expect(bunchCopy.getContext()).toBeUndefined();
|
|
49
|
-
expect(bunchCopy.getOwner()).toBeUndefined();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('copy a bunch - copy meta-data and globalOptions', () => {
|
|
53
|
-
const copiedOptions = {
|
|
54
|
-
inheritOwner: true,
|
|
55
|
-
replaceIndex: true,
|
|
56
|
-
virtualContainer: true,
|
|
57
|
-
};
|
|
58
|
-
const bunch = new DTBunch('', [], copiedOptions);
|
|
59
|
-
jest.spyOn(bunch, 'getManyMeta').mockImplementation(() => BunchMetaData);
|
|
60
|
-
|
|
61
|
-
const bunchCopy = bunch.copy();
|
|
62
|
-
|
|
63
|
-
expect(bunchCopy.getManyMeta()).toStrictEqual(BunchMetaData);
|
|
64
|
-
expect(bunchCopy.getOptions()).toStrictEqual({
|
|
65
|
-
...bunchDefaultOptions,
|
|
66
|
-
...copiedOptions,
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('copy a bunch - empty errors', () => {
|
|
71
|
-
const bunch = new DTBunch(KeyTest, [], { errors: true });
|
|
72
|
-
bunch.triggerError(new DTErrorStub());
|
|
73
|
-
bunch.triggerError(new DTErrorStub());
|
|
74
|
-
|
|
75
|
-
const bunchCopy = bunch.copy();
|
|
76
|
-
|
|
77
|
-
expect(bunchCopy.getErrors().length).toBe(0);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('copy a bunch with items - default case', () => {
|
|
81
|
-
const items: Array<DTElement<IMetaDataTest>> = [
|
|
82
|
-
new DTElement(),
|
|
83
|
-
new DTElement(),
|
|
84
|
-
new DTElement(),
|
|
85
|
-
];
|
|
86
|
-
jest.spyOn(items[0], 'copy');
|
|
87
|
-
jest.spyOn(items[1], 'copy');
|
|
88
|
-
jest.spyOn(items[2], 'copy');
|
|
89
|
-
const bunch = new DTBunch<DTElement<IMetaDataTest>, IMetaDataTest>(KeyTest, items);
|
|
90
|
-
|
|
91
|
-
const bunchCopy = bunch.copy();
|
|
92
|
-
|
|
93
|
-
expect(bunchCopy.getAll().length).toBe(3);
|
|
94
|
-
expect((items[0].copy as any).mock.calls.length).toBe(1);
|
|
95
|
-
expect((items[1].copy as any).mock.calls.length).toBe(1);
|
|
96
|
-
expect((items[2].copy as any).mock.calls.length).toBe(1);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('copy a bunch with items - virtual context case', () => {
|
|
100
|
-
const items: Array<DTElement<IMetaDataTest>> = [
|
|
101
|
-
new DTElement(),
|
|
102
|
-
new DTElement(),
|
|
103
|
-
new DTElement(),
|
|
104
|
-
];
|
|
105
|
-
jest.spyOn(items[0], 'copy');
|
|
106
|
-
jest.spyOn(items[1], 'copy');
|
|
107
|
-
jest.spyOn(items[2], 'copy');
|
|
108
|
-
const bunch = new DTBunch<DTElement<IMetaDataTest>, IMetaDataTest>(KeyTest, items, { virtualContainer: true });
|
|
109
|
-
|
|
110
|
-
const bunchCopy = bunch.copy();
|
|
111
|
-
|
|
112
|
-
expect(bunchCopy.getAll().length).toBe(3);
|
|
113
|
-
expect((items[0].copy as any).mock.calls.length).toBe(0);
|
|
114
|
-
expect((items[1].copy as any).mock.calls.length).toBe(0);
|
|
115
|
-
expect((items[2].copy as any).mock.calls.length).toBe(0);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe('DTElement copy()', () => {
|
|
120
|
-
afterEach(() => {
|
|
121
|
-
jest.resetAllMocks();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test('copy an element - simple case with id and key', () => {
|
|
125
|
-
const element = new DTElement(KeyTest);
|
|
126
|
-
const elementCopy = element.copy();
|
|
127
|
-
|
|
128
|
-
expect(element.getId() === elementCopy.getId()).toBeFalsy();
|
|
129
|
-
expect(element.getKey() === elementCopy.getKey()).toBeTruthy();
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test('copy an element - not copy context', () => {
|
|
133
|
-
const element = new DTElement(KeyTest);
|
|
134
|
-
jest.spyOn(element, 'setContext').mockImplementation(function (context) {
|
|
135
|
-
this._context = context;
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
element.setContext(new DTComponentStub());
|
|
139
|
-
|
|
140
|
-
const elementCopy = element.copy();
|
|
141
|
-
jest.spyOn(elementCopy, 'getContext').mockImplementation(function () {
|
|
142
|
-
return this._context;
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
expect(elementCopy.getContext()).toBeUndefined();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
test('copy an element - not copy container', () => {
|
|
149
|
-
const element = new DTElement(KeyTest);
|
|
150
|
-
|
|
151
|
-
element.setContext(new DTComponentStub());
|
|
152
|
-
|
|
153
|
-
const elementCopy = element.copy();
|
|
154
|
-
|
|
155
|
-
expect(elementCopy.getContainer()).toBeUndefined();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test('copy an element - copy meta-data and options', () => {
|
|
159
|
-
const element = new DTElement(KeyTest, { errors: true, syncId: "123" });
|
|
160
|
-
element.setManyMeta(HaileiMetaData);
|
|
161
|
-
|
|
162
|
-
const elementCopy = element.copy();
|
|
163
|
-
|
|
164
|
-
expect(elementCopy.getManyMeta()).toStrictEqual(HaileiMetaData);
|
|
165
|
-
expect(elementCopy.getOptions()).toStrictEqual({ errors: true, syncId: "123" });
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
test('copy an element - empty errors', () => {
|
|
169
|
-
const element = new DTElement(KeyTest, { errors: true });
|
|
170
|
-
element.triggerError(new DTErrorStub());
|
|
171
|
-
element.triggerError(new DTErrorStub());
|
|
172
|
-
|
|
173
|
-
const elementCopy = element.copy();
|
|
174
|
-
|
|
175
|
-
expect(elementCopy.getErrors().length).toBe(0);
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
describe('DTPlayer copy()', () => {
|
|
180
|
-
afterEach(() => {
|
|
181
|
-
jest.resetAllMocks();
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
test('copy a player - simple case with id and key', () => {
|
|
185
|
-
const player = new DTPlayer(KeyTest);
|
|
186
|
-
const playerCopy = player.copy();
|
|
187
|
-
|
|
188
|
-
expect(player.getId() === playerCopy.getId()).toBeFalsy();
|
|
189
|
-
expect(player.getKey() === playerCopy.getKey()).toBeTruthy();
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
test('copy a player - not copy context', () => {
|
|
193
|
-
const player = new DTPlayer(KeyTest);
|
|
194
|
-
|
|
195
|
-
player.setContext(new DTComponentStub());
|
|
196
|
-
|
|
197
|
-
const playerCopy = player.copy();
|
|
198
|
-
|
|
199
|
-
expect(playerCopy.getContext()).toBeUndefined();
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
test('copy a player - copy meta-data and options', () => {
|
|
203
|
-
const player = new DTPlayer(KeyTest, { errors: true, syncId: "123" });
|
|
204
|
-
player.setManyMeta(PlayerMetaData);
|
|
205
|
-
|
|
206
|
-
const playerCopy = player.copy();
|
|
207
|
-
|
|
208
|
-
expect(playerCopy.getManyMeta()).toStrictEqual(PlayerMetaData);
|
|
209
|
-
expect(playerCopy.getOptions()).toStrictEqual({ errors: true, syncId: "123" });
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
test('copy a player - empty errors', () => {
|
|
213
|
-
const player = new DTPlayer(KeyTest, { errors: true });
|
|
214
|
-
player.triggerError(new DTErrorStub());
|
|
215
|
-
player.triggerError(new DTErrorStub());
|
|
216
|
-
|
|
217
|
-
const playerCopy = player.copy();
|
|
218
|
-
|
|
219
|
-
expect(playerCopy.getErrors().length).toBe(0);
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
});
|
|
@@ -1,152 +0,0 @@
|
|
|
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
|
-
}
|