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.
- package/.c8rc.json +4 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +47 -0
- package/Makefile +34 -0
- package/README.md +0 -7
- package/babel.config.js +1 -0
- package/cucumber-report.html +48 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +63 -0
- package/dist/constants.js.map +1 -0
- package/dist/core/DTAction.d.ts +10 -0
- package/dist/core/DTAction.js +24 -0
- package/dist/core/DTAction.js.map +1 -0
- package/dist/core/DTBunch.d.ts +12 -17
- package/dist/core/DTBunch.js +39 -115
- 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 +12 -0
- package/dist/core/DTComponentPhysical.js +22 -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 +7 -7
- package/dist/core/DTElement.js +12 -11
- package/dist/core/DTElement.js.map +1 -1
- package/dist/core/DTManager.d.ts +33 -0
- package/dist/core/DTManager.js +190 -0
- package/dist/core/DTManager.js.map +1 -0
- package/dist/core/DTMaster.d.ts +24 -0
- package/dist/core/DTMaster.js +133 -0
- package/dist/core/DTMaster.js.map +1 -0
- package/dist/core/DTModule.d.ts +14 -0
- package/dist/core/DTModule.js +39 -0
- package/dist/core/DTModule.js.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +15 -3
- 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/libs/player/DTPlayer.element.d.ts +5 -0
- package/dist/libs/player/DTPlayer.element.js +11 -0
- package/dist/libs/player/DTPlayer.element.js.map +1 -0
- package/dist/libs/player/DTPlayer.manager.d.ts +11 -0
- package/dist/libs/player/DTPlayer.manager.js +42 -0
- package/dist/libs/player/DTPlayer.manager.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1321
- package/dist/types/core.d.ts +103 -0
- package/dist/types/core.js +15 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/index.d.ts +2 -58
- package/dist/types/index.js +16 -12
- package/dist/types/index.js.map +1 -1
- package/dist/types/player.d.ts +5 -0
- package/dist/types/player.js +3 -0
- package/dist/types/player.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +29 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1414 -0
- package/docs/classes/core_DTAction.DYOToolsAction.html +89 -0
- package/docs/classes/core_DTBunch.DYOToolsBunch.html +254 -0
- package/docs/classes/core_DTComponent.DYOToolsComponent.html +76 -0
- package/docs/classes/core_DTComponentPhysical.DYOToolsComponentPhysical.html +110 -0
- package/docs/classes/core_DTComponentWithMeta.DYOToolsComponentWithMeta.html +96 -0
- package/docs/classes/core_DTElement.DYOToolsElement.html +135 -0
- package/docs/classes/core_DTError.DYOToolsError.html +37 -0
- package/docs/classes/core_DTManager.DYOToolsManager.html +237 -0
- package/docs/classes/core_DTMaster.DYOToolsMaster.html +150 -0
- package/docs/classes/core_DTModule.DYOToolsModule.html +92 -0
- package/docs/classes/libs_DYOFinder.DYOFinder.html +34 -0
- package/docs/classes/libs_player_DTPlayer_element.DYOToolsPlayer.html +134 -0
- package/docs/classes/libs_player_DTPlayer_manager.DYOToolsPlayerManager.html +243 -0
- package/docs/enums/types_core.FilterOperatorType.html +10 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +1 -0
- package/docs/interfaces/types_core.DTBunchFilters.html +6 -0
- package/docs/interfaces/types_core.DTBunchOptions.html +19 -0
- package/docs/interfaces/types_core.DTBunchToObject.html +7 -0
- package/docs/interfaces/types_core.DTComponentOptions.html +5 -0
- package/docs/interfaces/types_core.DTComponentToObject.html +4 -0
- package/docs/interfaces/types_core.DTElementToObject.html +7 -0
- package/docs/interfaces/types_core.DTManagerFilters.html +6 -0
- package/docs/interfaces/types_core.DTManagerOptions.html +8 -0
- package/docs/interfaces/types_core.DTManagerToObject.html +5 -0
- package/docs/interfaces/types_core.DTMasterToObject.html +8 -0
- package/docs/interfaces/types_core.DTModuleToObject.html +6 -0
- package/docs/interfaces/types_core.DYOFinderConfigurationPropDefault.html +4 -0
- package/docs/interfaces/types_core.DYOFinderConfigurationPropObjectSearch.html +4 -0
- package/docs/interfaces/types_core.DYOFinderFilterOperatorAdvanced.html +5 -0
- package/docs/interfaces/types_core.DYOFinderFilterOperatorBase.html +5 -0
- package/docs/interfaces/types_player.DTPlayerManagerSimpleConfiguration.html +3 -0
- package/docs/modules/constants.html +6 -0
- package/docs/modules/core_DTAction.html +2 -0
- package/docs/modules/core_DTBunch.html +2 -0
- package/docs/modules/core_DTComponent.html +2 -0
- package/docs/modules/core_DTComponentPhysical.html +2 -0
- package/docs/modules/core_DTComponentWithMeta.html +2 -0
- package/docs/modules/core_DTElement.html +2 -0
- package/docs/modules/core_DTError.html +2 -0
- package/docs/modules/core_DTManager.html +2 -0
- package/docs/modules/core_DTMaster.html +2 -0
- package/docs/modules/core_DTModule.html +2 -0
- package/docs/modules/libs_DYOFinder.html +2 -0
- package/docs/modules/libs_player_DTPlayer_element.html +2 -0
- package/docs/modules/libs_player_DTPlayer_manager.html +2 -0
- package/docs/modules/types.html +29 -0
- package/docs/modules/types_core.html +28 -0
- package/docs/modules/types_player.html +2 -0
- package/docs/types/types_core.DTAcceptedMetaData.html +2 -0
- package/docs/types/types_core.DTManagerItemType.html +1 -0
- package/docs/types/types_core.DTManagerItemsType.html +2 -0
- package/docs/types/types_core.DYOFinderComponentType.html +1 -0
- package/docs/types/types_core.DYOFinderConfiguration.html +2 -0
- package/docs/types/types_core.DYOFinderConfigurationProp.html +1 -0
- package/docs/types/types_core.DYOFinderFilterOperator.html +1 -0
- package/docs/types/types_core.DYOFinderFilterOperatorArgument.html +1 -0
- package/docs/types/types_core.DYOFinderFilters.html +1 -0
- package/docs/types/types_core.StandardPrimitiveType.html +2 -0
- package/docs/types/types_core.StandardPrimitiveTypeWithArray.html +1 -0
- package/docs/variables/constants.bunchDefaultOptions.html +2 -0
- package/docs/variables/constants.componentBunchDefaultFinderConfiguration.html +1 -0
- package/docs/variables/constants.componentManagerDefaultFinderConfiguration.html +1 -0
- package/docs/variables/constants.componentPhysicalDefaultFinderConfiguration.html +1 -0
- package/docs/variables/constants.managerDefaultOptions.html +2 -0
- package/jest.config.js +6 -0
- package/package.json +32 -23
- package/src/constants.ts +85 -0
- package/src/core/DTAction.ts +52 -0
- package/src/core/DTBunch.ts +467 -0
- package/src/core/DTComponent.ts +225 -0
- package/src/core/DTComponentPhysical.ts +53 -0
- package/src/core/DTComponentWithMeta.ts +65 -0
- package/src/core/DTElement.ts +102 -0
- package/src/core/DTError.ts +78 -0
- package/src/core/DTManager.ts +465 -0
- package/src/core/DTMaster.ts +318 -0
- package/src/core/DTModule.ts +90 -0
- package/src/index.ts +17 -0
- package/src/libs/DYOFinder.ts +175 -0
- package/src/libs/player/DTPlayer.element.ts +9 -0
- package/src/libs/player/DTPlayer.manager.ts +84 -0
- package/src/types/core.ts +169 -0
- package/src/types/index.ts +2 -0
- package/src/types/player.ts +6 -0
- package/test/core/DTAction.double.ts +78 -0
- package/test/core/DTAction.spec.ts +76 -0
- package/test/core/DTBunch.double.ts +261 -0
- package/test/core/DTBunch.spec.ts +897 -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 +78 -0
- package/test/core/DTComponentWithMeta.double.ts +115 -0
- package/test/core/DTComponentWithMeta.spec.ts +124 -0
- package/test/core/DTElement.double.ts +163 -0
- package/test/core/DTElement.spec.ts +146 -0
- package/test/core/DTError.double.ts +92 -0
- package/test/core/DTError.spec.ts +89 -0
- package/test/core/DTManager.double.ts +216 -0
- package/test/core/DTManager.spec.ts +965 -0
- package/test/core/DTMaster.double.ts +141 -0
- package/test/core/DTMaster.spec.ts +584 -0
- package/test/core/DTModule.double.ts +80 -0
- package/test/core/DTModule.spec.ts +138 -0
- package/test/core/copy.spec.ts +243 -0
- package/test/libs/DYOFinder.double.ts +152 -0
- package/test/libs/DYOFinder.spec.ts +194 -0
- package/test/libs/player/DTPlayer.element.double.ts +55 -0
- package/test/libs/player/DTPlayer.element.spec.ts +28 -0
- package/test/libs/player/DTPlayer.manager.double.ts +92 -0
- package/test/libs/player/DTPlayer.manager.spec.ts +178 -0
- package/tsconfig.dev.json +22 -0
- package/tsconfig.json +21 -0
- package/dist/core/DTPlayer.d.ts +0 -8
- package/dist/core/DTPlayer.js +0 -30
- package/dist/core/DTPlayer.js.map +0 -1
- 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,138 @@
|
|
|
1
|
+
import {DTComponent, DTModule} from "../../src";
|
|
2
|
+
import {mockOverriddenMethods} from "./DTComponent.double";
|
|
3
|
+
import {afterEach, beforeEach, describe, expect, jest, test} from "@jest/globals";
|
|
4
|
+
import {DTModuleTest, IDTest, KeyTest} from "./DTModule.double";
|
|
5
|
+
import MockedFunction = jest.MockedFunction;
|
|
6
|
+
|
|
7
|
+
/** ****************** MOCK DEPENDENCIES
|
|
8
|
+
* Dependencies used by the component are mocked with Jest
|
|
9
|
+
* **** */
|
|
10
|
+
jest.mock('../../src/core/DTComponent');
|
|
11
|
+
jest.mock('../../src/core/DTError');
|
|
12
|
+
// Add specific mock for inherited methods to have a basic implementation
|
|
13
|
+
mockOverriddenMethods(DTComponent);
|
|
14
|
+
|
|
15
|
+
/** *********************** TESTS SUITES ****************************** */
|
|
16
|
+
describe('class DYOToolsModule', () => {
|
|
17
|
+
let moduleTest: DTModuleTest;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
moduleTest = new DTModuleTest();
|
|
21
|
+
moduleTest.th_set_id(IDTest);
|
|
22
|
+
moduleTest.th_set_key(KeyTest);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
jest.resetAllMocks();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('inheritance', () => {
|
|
30
|
+
test('check good inheritance for class', () => {
|
|
31
|
+
expect(DTModule.prototype instanceof DTComponent).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('_componentType', () => {
|
|
36
|
+
test('componentType must be "action"', () => {
|
|
37
|
+
expect(moduleTest.th_get_componentType()).toBe('module');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('constructor()', () => {
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
jest.resetAllMocks();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('simple creation with key', () => {
|
|
47
|
+
const newModule = new DTModuleTest(KeyTest);
|
|
48
|
+
const parentConstructorMock = (DTComponent.prototype.constructor as MockedFunction<(key: string, options: any) => void>).mock;
|
|
49
|
+
|
|
50
|
+
expect(parentConstructorMock.calls.length).toBe(1);
|
|
51
|
+
expect(parentConstructorMock.calls[0][0]).toBe(KeyTest);
|
|
52
|
+
|
|
53
|
+
expect(newModule.th_get_enabled()).toStrictEqual(true);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('getMaster()', () => {
|
|
58
|
+
test('call get context with master accessor', () => {
|
|
59
|
+
moduleTest.getMaster();
|
|
60
|
+
|
|
61
|
+
expect((moduleTest.getContext as any).mock.calls.length).toBe(1);
|
|
62
|
+
expect((moduleTest.getContext as any).mock.calls[0][0]).toBe('master');
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('isEnabled()', () => {
|
|
67
|
+
test('return true if the module is enabled', () => {
|
|
68
|
+
const enabledModule = moduleTest.isEnabled();
|
|
69
|
+
|
|
70
|
+
expect(enabledModule).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('return false if the module is disabled', () => {
|
|
74
|
+
moduleTest.th_set_enabled(false);
|
|
75
|
+
|
|
76
|
+
const enabledModule = moduleTest.isEnabled();
|
|
77
|
+
|
|
78
|
+
expect(enabledModule).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('enable()', () => {
|
|
83
|
+
test('change enable to true', () => {
|
|
84
|
+
moduleTest.th_set_enabled(false);
|
|
85
|
+
|
|
86
|
+
moduleTest.enable();
|
|
87
|
+
|
|
88
|
+
expect(moduleTest.th_get_enabled()).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('disable()', () => {
|
|
93
|
+
test('change enable to false', () => {
|
|
94
|
+
moduleTest.th_set_enabled(true);
|
|
95
|
+
|
|
96
|
+
moduleTest.disable();
|
|
97
|
+
|
|
98
|
+
expect(moduleTest.th_get_enabled()).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('toString()', () => {
|
|
103
|
+
test('string output standard', () => {
|
|
104
|
+
const toStringAction = moduleTest.toString();
|
|
105
|
+
|
|
106
|
+
expect(toStringAction).toBe(`Component ${KeyTest} - Type: Module`);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('string output standard when disabled', () => {
|
|
110
|
+
moduleTest.th_set_enabled(false);
|
|
111
|
+
|
|
112
|
+
const toStringAction = moduleTest.toString();
|
|
113
|
+
|
|
114
|
+
expect(toStringAction).toBe(`Component ${KeyTest} - Type: Module - Disabled`);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('toObject()', () => {
|
|
119
|
+
test('toObject output standard', () => {
|
|
120
|
+
const toObjectAction: any = moduleTest.toObject();
|
|
121
|
+
|
|
122
|
+
expect(Object.keys(toObjectAction)).toStrictEqual(['id', 'key', 'type', 'enabled']);
|
|
123
|
+
expect(toObjectAction.id).toBe(IDTest);
|
|
124
|
+
expect(toObjectAction.key).toBe(KeyTest);
|
|
125
|
+
expect(toObjectAction.type).toBe('module');
|
|
126
|
+
expect(toObjectAction.enabled).toBe(true);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('toObject output standard when disabled', () => {
|
|
130
|
+
moduleTest.th_set_enabled(false);
|
|
131
|
+
|
|
132
|
+
const toObjectAction: any = moduleTest.toObject();
|
|
133
|
+
|
|
134
|
+
expect(Object.keys(toObjectAction)).toStrictEqual(['id', 'key', 'type', 'enabled']);
|
|
135
|
+
expect(toObjectAction.enabled).toBe(false);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
@@ -0,0 +1,243 @@
|
|
|
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 { 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(OwnerTest);
|
|
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
|
+
virtualContainer: 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, { virtualContainer: 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 - not copy container', () => {
|
|
158
|
+
const element = new DTElement(KeyTest);
|
|
159
|
+
jest.spyOn(element, 'setContainer').mockImplementation(function (container) {
|
|
160
|
+
this._container = container;
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
element.setContext(new DTComponentStub());
|
|
164
|
+
|
|
165
|
+
const elementCopy = element.copy();
|
|
166
|
+
jest.spyOn(elementCopy, 'getContainer').mockImplementation(function () {
|
|
167
|
+
return this._container;
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(elementCopy.getContainer()).toBeUndefined();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('copy an element - copy meta-data and options', () => {
|
|
174
|
+
const element = new DTElement(KeyTest, { errors: true });
|
|
175
|
+
jest.spyOn(element, 'getManyMeta').mockImplementation(() => HaileiMetaData);
|
|
176
|
+
|
|
177
|
+
const elementCopy = element.copy();
|
|
178
|
+
|
|
179
|
+
expect(elementCopy.getManyMeta()).toStrictEqual(HaileiMetaData);
|
|
180
|
+
expect(elementCopy.getOptions()).toStrictEqual({ errors: true });
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('copy an element - empty errors', () => {
|
|
184
|
+
const element = new DTElement(KeyTest, { errors: true });
|
|
185
|
+
element.triggerError(new DTErrorStub());
|
|
186
|
+
element.triggerError(new DTErrorStub());
|
|
187
|
+
|
|
188
|
+
const elementCopy = element.copy();
|
|
189
|
+
|
|
190
|
+
expect(elementCopy.getErrors().length).toBe(0);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe('DTPlayer copy()', () => {
|
|
195
|
+
afterEach(() => {
|
|
196
|
+
jest.resetAllMocks();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('copy a player - simple case with id and key', () => {
|
|
200
|
+
const player = new DTPlayer(KeyTest);
|
|
201
|
+
const playerCopy = player.copy();
|
|
202
|
+
|
|
203
|
+
expect(player.getId() === playerCopy.getId()).toBeFalsy();
|
|
204
|
+
expect(player.getKey() === playerCopy.getKey()).toBeTruthy();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test('copy a player - not copy context', () => {
|
|
208
|
+
const player = new DTPlayer(KeyTest);
|
|
209
|
+
jest.spyOn(player, 'setContext').mockImplementation(function (context) {
|
|
210
|
+
this._context = context;
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
player.setContext(new DTComponentStub());
|
|
214
|
+
|
|
215
|
+
const playerCopy = player.copy();
|
|
216
|
+
jest.spyOn(playerCopy, 'getContext').mockImplementation(function () {
|
|
217
|
+
return this._context;
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
expect(playerCopy.getContext()).toBeUndefined();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('copy a player - copy meta-data and options', () => {
|
|
224
|
+
const player = new DTPlayer(KeyTest, { errors: true });
|
|
225
|
+
jest.spyOn(player, 'getManyMeta').mockImplementation(() => PlayerMetaData);
|
|
226
|
+
|
|
227
|
+
const playerCopy = player.copy();
|
|
228
|
+
|
|
229
|
+
expect(playerCopy.getManyMeta()).toStrictEqual(PlayerMetaData);
|
|
230
|
+
expect(playerCopy.getOptions()).toStrictEqual({ errors: true });
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('copy a player - empty errors', () => {
|
|
234
|
+
const player = new DTPlayer(KeyTest, { errors: true });
|
|
235
|
+
player.triggerError(new DTErrorStub());
|
|
236
|
+
player.triggerError(new DTErrorStub());
|
|
237
|
+
|
|
238
|
+
const playerCopy = player.copy();
|
|
239
|
+
|
|
240
|
+
expect(playerCopy.getErrors().length).toBe(0);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
});
|
|
@@ -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
|
+
}
|