@sankhyalabs/core 5.20.0-dev.7 → 5.20.0-dev.70
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/.docs/classes/Change.md +11 -11
- package/.docs/classes/ColumnFilterManager.md +145 -0
- package/.docs/classes/DataUnit.md +405 -137
- package/.docs/classes/DataUnitInMemoryLoader.md +303 -0
- package/.docs/classes/DataUnitLoaderUtils.md +151 -0
- package/.docs/classes/DateUtils.md +8 -8
- package/.docs/classes/FieldComparator.md +2 -2
- package/.docs/classes/IDBRepository.md +22 -0
- package/.docs/classes/LockManager.md +249 -0
- package/.docs/classes/MaskFormatter.md +66 -14
- package/.docs/classes/ObjectUtils.md +141 -0
- package/.docs/classes/OverflowWatcher.md +533 -0
- package/.docs/classes/SelectionInfo.md +25 -11
- package/.docs/classes/ServiceCanceledException.md +193 -0
- package/.docs/classes/ServiceUtils.md +67 -0
- package/.docs/classes/SilentException.md +193 -0
- package/.docs/classes/UserAgentUtils.md +15 -1
- package/.docs/enumerations/Action.md +41 -21
- package/.docs/enumerations/ChangeOperation.md +4 -4
- package/.docs/enumerations/LockManagerOperation.md +33 -0
- package/.docs/enumerations/OverflowDirection.md +29 -0
- package/.docs/enumerations/RECORD_DATE_FORMAT.md +27 -0
- package/.docs/enumerations/SelectionMode.md +2 -2
- package/.docs/enumerations/StorageType.md +37 -0
- package/.docs/globals.md +24 -0
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/DataUnitInMemoryLoaderConfig.md +37 -0
- package/.docs/interfaces/IRepository.md +18 -0
- package/.docs/interfaces/LoadDataRequest.md +1 -1
- package/.docs/interfaces/OverFlowWatcherParams.md +67 -0
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/PaginationInfo.md +25 -0
- package/.docs/interfaces/PaginationInfoBuilderParams.md +37 -0
- package/.docs/interfaces/QuickFilter.md +3 -3
- package/.docs/interfaces/Record.md +4 -4
- package/.docs/interfaces/SavedRecord.md +5 -5
- package/.docs/interfaces/WaitingChange.md +3 -3
- package/.docs/namespaces/MaskFormatter/type-aliases/MaskCharacter.md +1 -1
- package/.docs/namespaces/MaskFormatter/variables/MaskCharacter.md +1 -1
- package/.docs/type-aliases/DataUnitEventOptions.md +17 -0
- package/.docs/type-aliases/OnOverflowCallBack.md +25 -0
- package/.docs/variables/OVERFLOWED_CLASS_NAME.md +13 -0
- package/bun.lockb +0 -0
- package/dist/dataunit/DataUnit.d.ts +82 -12
- package/dist/dataunit/DataUnit.js +209 -67
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/DataUnitHelper.js +6 -5
- package/dist/dataunit/DataUnitHelper.js.map +1 -1
- package/dist/dataunit/formatting/PrettyFormatter.js +14 -6
- package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.d.ts +9 -0
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js +6 -0
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js.map +1 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.d.ts +25 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.js +131 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.js.map +1 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.d.ts +20 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js +62 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js.map +1 -0
- package/dist/dataunit/loading/LoadDataRequest.d.ts +1 -1
- package/dist/dataunit/loading/PaginationInfo.d.ts +8 -0
- package/dist/dataunit/metadata/DataType.js +3 -0
- package/dist/dataunit/metadata/DataType.js.map +1 -1
- package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
- package/dist/dataunit/sorting/FieldComparator.js +4 -9
- package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
- package/dist/dataunit/state/action/DataUnitAction.d.ts +2 -0
- package/dist/dataunit/state/action/DataUnitAction.js +2 -0
- package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
- package/dist/dataunit/state/slice/InvalidFieldsSlice.js +2 -0
- package/dist/dataunit/state/slice/InvalidFieldsSlice.js.map +1 -1
- package/dist/dataunit/state/slice/LoadingControlSlice.js +16 -0
- package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
- package/dist/dataunit/state/slice/RecordsSlice.js +1 -1
- package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -1
- package/dist/dataunit/state/slice/SelectionSlice.js +4 -4
- package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
- package/dist/exceptions/ServiceCanceledException.d.ts +14 -0
- package/dist/exceptions/ServiceCanceledException.js +13 -0
- package/dist/exceptions/ServiceCanceledException.js.map +1 -0
- package/dist/exceptions/SilentException.d.ts +14 -0
- package/dist/exceptions/SilentException.js +13 -0
- package/dist/exceptions/SilentException.js.map +1 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/repository/IRepository.d.ts +6 -0
- package/dist/repository/indexeddb/IDBRepository.d.ts +1 -0
- package/dist/repository/indexeddb/IDBRepository.js +3 -0
- package/dist/repository/indexeddb/IDBRepository.js.map +1 -1
- package/dist/utils/CacheManager/index.d.ts +52 -0
- package/dist/utils/CacheManager/index.js +101 -0
- package/dist/utils/CacheManager/index.js.map +1 -0
- package/dist/utils/CacheManager/interfaces/index.d.ts +5 -0
- package/dist/utils/CacheManager/interfaces/index.js +7 -0
- package/dist/utils/CacheManager/interfaces/index.js.map +1 -0
- package/dist/utils/ColumnFilterManager.d.ts +19 -0
- package/dist/utils/ColumnFilterManager.js +73 -0
- package/dist/utils/ColumnFilterManager.js.map +1 -0
- package/dist/utils/DateUtils.js +3 -0
- package/dist/utils/DateUtils.js.map +1 -1
- package/dist/utils/ElementUtils.d.ts +2 -0
- package/dist/utils/ElementUtils.js +9 -0
- package/dist/utils/ElementUtils.js.map +1 -0
- package/dist/utils/LockManager.d.ts +58 -0
- package/dist/utils/LockManager.js +191 -0
- package/dist/utils/LockManager.js.map +1 -0
- package/dist/utils/MaskFormatter.d.ts +16 -1
- package/dist/utils/MaskFormatter.js +82 -2
- package/dist/utils/MaskFormatter.js.map +1 -1
- package/dist/utils/ObjectUtils.d.ts +38 -0
- package/dist/utils/ObjectUtils.js +51 -0
- package/dist/utils/ObjectUtils.js.map +1 -1
- package/dist/utils/OnboardingUtils.js +1 -1
- package/dist/utils/OnboardingUtils.js.map +1 -1
- package/dist/utils/OverflowWatcher/index.d.ts +59 -0
- package/dist/utils/OverflowWatcher/index.js +188 -0
- package/dist/utils/OverflowWatcher/index.js.map +1 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.d.ts +6 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.js +2 -0
- package/dist/utils/OverflowWatcher/types/overflow-callback.js.map +1 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.d.ts +7 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.js +9 -0
- package/dist/utils/OverflowWatcher/types/overflow-direction.js.map +1 -0
- package/dist/utils/ServiceUtils.d.ts +24 -0
- package/dist/utils/ServiceUtils.js +40 -0
- package/dist/utils/ServiceUtils.js.map +1 -0
- package/dist/utils/SortingUtils.d.ts +9 -0
- package/dist/utils/SortingUtils.js +24 -0
- package/dist/utils/SortingUtils.js.map +1 -0
- package/dist/utils/UserAgentUtils/index.d.ts +1 -0
- package/dist/utils/UserAgentUtils/index.js +5 -0
- package/dist/utils/UserAgentUtils/index.js.map +1 -1
- package/jest.config.ts +2 -0
- package/package.json +2 -1
- package/reports/test-report.xml +215 -0
- package/setupTests.js +7 -0
- package/sonar-project.properties +6 -3
- package/src/dataunit/DataUnit.ts +250 -82
- package/src/dataunit/DataUnitHelper.ts +6 -5
- package/src/dataunit/formatting/PrettyFormatter.ts +15 -6
- package/src/dataunit/loader/DataUnitInMemoryLoaderConfig.ts +10 -0
- package/src/dataunit/loader/dataUnitInMemoryLoader.ts +176 -0
- package/src/dataunit/loader/utils/dataUnitLoaderUtils.ts +86 -0
- package/src/dataunit/loading/LoadDataRequest.ts +1 -1
- package/src/dataunit/loading/PaginationInfo.ts +10 -0
- package/src/dataunit/metadata/DataType.ts +3 -0
- package/src/dataunit/sorting/FieldComparator.ts +18 -32
- package/src/dataunit/state/action/DataUnitAction.ts +2 -0
- package/src/dataunit/state/slice/InvalidFieldsSlice.ts +2 -0
- package/src/dataunit/state/slice/LoadingControlSlice.ts +42 -0
- package/src/dataunit/state/slice/RecordsSlice.ts +1 -1
- package/src/dataunit/state/slice/SelectionSlice.ts +4 -4
- package/src/dataunit/state/slice/test/RecordsSlice.spec.ts +45 -0
- package/src/dataunit/test/DataUnit.spec.ts +44 -0
- package/src/exceptions/ServiceCanceledException.ts +25 -0
- package/src/exceptions/SilentException.ts +25 -0
- package/src/index.ts +29 -1
- package/src/repository/IRepository.ts +7 -0
- package/src/repository/indexeddb/IDBRepository.ts +4 -0
- package/src/utils/CacheManager/index.ts +103 -0
- package/src/utils/CacheManager/interfaces/index.ts +5 -0
- package/src/utils/ColumnFilterManager.ts +104 -0
- package/src/utils/DateUtils.ts +3 -0
- package/src/utils/ElementUtils.ts +10 -0
- package/src/utils/LockManager.ts +213 -0
- package/src/utils/MaskFormatter.ts +93 -2
- package/src/utils/ObjectUtils.ts +56 -0
- package/src/utils/OnboardingUtils.ts +1 -1
- package/src/utils/OverflowWatcher/index.ts +243 -0
- package/src/utils/OverflowWatcher/types/overflow-callback.ts +6 -0
- package/src/utils/OverflowWatcher/types/overflow-direction.ts +7 -0
- package/src/utils/ServiceUtils.ts +36 -0
- package/src/utils/SortingUtils.ts +30 -0
- package/src/utils/UserAgentUtils/index.ts +6 -1
- package/src/utils/test/objectUtils.spec.ts +109 -0
- package/test/dataunit/formatting/PrettyFormatter.spec.ts +177 -0
- package/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts +221 -0
- package/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts +158 -0
- package/test/util/ColumnFilterManager.spec.ts +133 -0
- package/test/util/ElementUtils.spec.ts +34 -0
- package/test/util/OverflowWatcher.spec.ts +152 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { getFormattedValue } from '../../../src/dataunit/formatting/PrettyFormatter';
|
|
2
|
+
import { DataType, FieldDescriptor, UserInterface } from '../../../src';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* É preciso importart o utilitário DateUtils para que seus métodos
|
|
6
|
+
* estáticos sejam executados no ambiente de testes
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { DateUtils } from '../../../src';
|
|
10
|
+
|
|
11
|
+
describe('getFormattedValue', () => {
|
|
12
|
+
it('should return empty string when value is null', () => {
|
|
13
|
+
const value = null;
|
|
14
|
+
const descriptor = getFileFieldDescriptor();
|
|
15
|
+
expect(getFormattedValue(value, descriptor)).toBe('');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should return empty string when value is not an array', () => {
|
|
19
|
+
const value = 'not an array';
|
|
20
|
+
const descriptor = getFileFieldDescriptor();
|
|
21
|
+
expect(getFormattedValue(value, descriptor)).toBe('');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should return empty string when value is an empty array', () => {
|
|
25
|
+
const value: any[] = [];
|
|
26
|
+
const descriptor = getFileFieldDescriptor();
|
|
27
|
+
expect(getFormattedValue(value, descriptor)).toBe('0 arquivos');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should return file name when value is an array with one file object', () => {
|
|
31
|
+
const value = [{ name: 'file1.txt' }];
|
|
32
|
+
const descriptor = getFileFieldDescriptor();
|
|
33
|
+
expect(getFormattedValue(value, descriptor)).toBe('file1.txt');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should return file count when value is an array with multiple file objects', () => {
|
|
37
|
+
const value = [{ name: 'file1.txt' }, { name: 'file2.txt' }];
|
|
38
|
+
const descriptor = getFileFieldDescriptor();
|
|
39
|
+
expect(getFormattedValue(value, descriptor)).toBe('2 arquivos');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should return empty string for undefined file', () => {
|
|
43
|
+
const value = undefined;
|
|
44
|
+
const descriptor = { userInterface: UserInterface.FILE } as FieldDescriptor;
|
|
45
|
+
expect(getFormattedValue(value, descriptor)).toBe('');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should handle OBJECT type with value field', () => {
|
|
49
|
+
const value = { value: 'code', label: 'label' };
|
|
50
|
+
const descriptor = { dataType: DataType.OBJECT, userInterface: UserInterface.SEARCH } as FieldDescriptor;
|
|
51
|
+
expect(getFormattedValue(value, descriptor)).toBe('code - label');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should return empty string when value is undefined', () => {
|
|
55
|
+
const value = undefined;
|
|
56
|
+
const descriptor = getObjectFieldDescriptor();
|
|
57
|
+
expect(getFormattedValue(value, descriptor)).toBe('');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should return value as string when value is not an object', () => {
|
|
61
|
+
const value = 12345;
|
|
62
|
+
const descriptor = getObjectFieldDescriptor();
|
|
63
|
+
expect(getFormattedValue(value, descriptor)).toBe('12345');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should return value.toString() when value is an object without value property', () => {
|
|
67
|
+
const value = { someProperty: 'someValue' };
|
|
68
|
+
const descriptor = getObjectFieldDescriptor();
|
|
69
|
+
expect(getFormattedValue(value, descriptor)).toBe(value.toString());
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should handle BOOLEAN type', () => {
|
|
73
|
+
expect(getFormattedValue(true, { dataType: DataType.BOOLEAN } as FieldDescriptor)).toBe('Sim');
|
|
74
|
+
expect(getFormattedValue(false, { dataType: DataType.BOOLEAN } as FieldDescriptor)).toBe('Não');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should format numbers correctly', () => {
|
|
78
|
+
const value = 1234.567;
|
|
79
|
+
const descriptor = {
|
|
80
|
+
dataType: DataType.NUMBER,
|
|
81
|
+
properties: { precision: 2, prettyPrecision: 2 },
|
|
82
|
+
} as FieldDescriptor;
|
|
83
|
+
expect(getFormattedValue(value, descriptor)).toBe('1.234,57');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should format dates correctly', () => {
|
|
87
|
+
const value = new Date('2023-07-01T14:30:00');
|
|
88
|
+
const descriptor = { userInterface: UserInterface.DATE } as FieldDescriptor;
|
|
89
|
+
expect(getFormattedValue(value, descriptor)).toBe('01/07/2023');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should format times correctly', () => {
|
|
93
|
+
const value = new Date('2023-07-01T14:30:00');
|
|
94
|
+
const descriptor = { userInterface: UserInterface.TIME } as FieldDescriptor;
|
|
95
|
+
expect(getFormattedValue(value, descriptor)).toBe('14:30');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should format datetime correctly', () => {
|
|
99
|
+
const value = new Date('2023-07-01T14:30:00');
|
|
100
|
+
const descriptor = { userInterface: UserInterface.DATETIME } as FieldDescriptor;
|
|
101
|
+
expect(getFormattedValue(value, descriptor)).toBe('01/07/2023 14:30');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should call toString with correct parameters', () => {
|
|
105
|
+
const value = 123;
|
|
106
|
+
const descriptor = { dataType: DataType.NUMBER } as FieldDescriptor;
|
|
107
|
+
expect(getFormattedValue(value, descriptor)).toBe('123,00');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should handle undefined descriptor gracefully', () => {
|
|
111
|
+
const value = 123;
|
|
112
|
+
expect(getFormattedValue(value)).toBe('123');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should format value correctly with OPTIONSELECTOR and matching option', () => {
|
|
116
|
+
const value = 'option1';
|
|
117
|
+
const descriptor = buildOptionSelectorFieldDescriptor();
|
|
118
|
+
expect(getFormattedValue(value, descriptor)).toBe('option1');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should return value with OPTIONSELECTOR and no matching option', () => {
|
|
122
|
+
const value = 'option2';
|
|
123
|
+
const descriptor = buildOptionSelectorFieldDescriptor();
|
|
124
|
+
expect(getFormattedValue(value, descriptor)).toBe('option2');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should format value correctly with OPTIONSELECTOR and value as object', () => {
|
|
128
|
+
const value = { value: 'option1' };
|
|
129
|
+
const descriptor = buildOptionSelectorFieldDescriptor();
|
|
130
|
+
expect(getFormattedValue(value, descriptor)).toBe('option1');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('should return empty string with OPTIONSELECTOR and value as null', () => {
|
|
134
|
+
const value = null;
|
|
135
|
+
const descriptor = buildOptionSelectorFieldDescriptor();
|
|
136
|
+
expect(getFormattedValue(value, descriptor)).toBe('');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should format value correctly with OPTIONSELECTOR and options as JSON string', () => {
|
|
140
|
+
const value = 'option1';
|
|
141
|
+
const descriptor: FieldDescriptor = {
|
|
142
|
+
userInterface: UserInterface.OPTIONSELECTOR,
|
|
143
|
+
properties: { options: JSON.stringify([{ label: 'Option 1', value: 'option1' }]) },
|
|
144
|
+
} as FieldDescriptor;
|
|
145
|
+
expect(getFormattedValue(value, descriptor)).toBe('option1');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('should return value with OPTIONSELECTOR and options as empty array', () => {
|
|
149
|
+
const value = 'option1';
|
|
150
|
+
const descriptor: FieldDescriptor = {
|
|
151
|
+
userInterface: UserInterface.OPTIONSELECTOR,
|
|
152
|
+
properties: { options: [] },
|
|
153
|
+
} as FieldDescriptor;
|
|
154
|
+
expect(getFormattedValue(value, descriptor)).toBe('option1');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('should format masked values correctly', () => {
|
|
158
|
+
const value = '12345678901';
|
|
159
|
+
const descriptor = { properties: { mask: 'cpf' } } as FieldDescriptor;
|
|
160
|
+
expect(getFormattedValue(value, descriptor)).toBe('123.456.789-01');
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
function buildOptionSelectorFieldDescriptor(): FieldDescriptor {
|
|
165
|
+
return {
|
|
166
|
+
userInterface: UserInterface.OPTIONSELECTOR,
|
|
167
|
+
properties: { options: [{ label: 'Option 1', value: 'option1' }] },
|
|
168
|
+
} as FieldDescriptor;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function getFileFieldDescriptor(): FieldDescriptor{
|
|
172
|
+
return { userInterface: UserInterface.FILE } as FieldDescriptor;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function getObjectFieldDescriptor(): FieldDescriptor{
|
|
176
|
+
return { dataType: DataType.OBJECT } as FieldDescriptor;
|
|
177
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { DataUnitInMemoryLoader } from '../../../src/dataunit/loader/dataUnitInMemoryLoader.js';
|
|
2
|
+
import {
|
|
3
|
+
DataUnitInMemoryLoaderConfig,
|
|
4
|
+
RECORD_DATE_FORMAT,
|
|
5
|
+
} from '../../../src/dataunit/loader/DataUnitInMemoryLoaderConfig.js';
|
|
6
|
+
import { FieldDescriptor, UnitMetadata } from '../../../src/dataunit/metadata/UnitMetadata.js';
|
|
7
|
+
import { DataType } from '../../../src/dataunit/metadata/DataType.js';
|
|
8
|
+
import DateUtils from '../../../src/utils/DateUtils.js';
|
|
9
|
+
import DataUnit, { Record } from '../../../src/dataunit/DataUnit.js';
|
|
10
|
+
|
|
11
|
+
describe('DataUnitInMemoryLoader - loadData', () => {
|
|
12
|
+
const dataUnitMetetadata: UnitMetadata = {
|
|
13
|
+
name: 'test',
|
|
14
|
+
label: 'test',
|
|
15
|
+
fields: [],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
it('should be called load data when auto load is true', async () => {
|
|
19
|
+
const config: DataUnitInMemoryLoaderConfig = {
|
|
20
|
+
autoLoad: true,
|
|
21
|
+
};
|
|
22
|
+
const inMemoryLoader = new DataUnitInMemoryLoader(dataUnitMetetadata, [], config);
|
|
23
|
+
const loadData = jest.spyOn(inMemoryLoader.dataUnit, 'loadData');
|
|
24
|
+
await inMemoryLoader.dataUnit.loadMetadata();
|
|
25
|
+
expect(loadData).toHaveBeenCalled();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should be called load data when auto load is undefined', async () => {
|
|
29
|
+
const config: DataUnitInMemoryLoaderConfig = {
|
|
30
|
+
autoLoad: undefined,
|
|
31
|
+
};
|
|
32
|
+
const inMemoryLoader = new DataUnitInMemoryLoader(dataUnitMetetadata, [], config);
|
|
33
|
+
const loadData = jest.spyOn(inMemoryLoader.dataUnit, 'loadData');
|
|
34
|
+
await inMemoryLoader.dataUnit.loadMetadata();
|
|
35
|
+
expect(loadData).toHaveBeenCalled();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should not be called load data when auto load is false', async () => {
|
|
39
|
+
const config: DataUnitInMemoryLoaderConfig = {
|
|
40
|
+
autoLoad: false,
|
|
41
|
+
};
|
|
42
|
+
const inMemoryLoader = new DataUnitInMemoryLoader(dataUnitMetetadata, [], config);
|
|
43
|
+
const loadData = jest.spyOn(inMemoryLoader.dataUnit, 'loadData');
|
|
44
|
+
await inMemoryLoader.dataUnit.loadMetadata();
|
|
45
|
+
expect(loadData).not.toHaveBeenCalled();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should be called load data when config is undefined', async () => {
|
|
49
|
+
const inMemoryLoader = new DataUnitInMemoryLoader(dataUnitMetetadata, []);
|
|
50
|
+
const loadData = jest.spyOn(inMemoryLoader.dataUnit, 'loadData');
|
|
51
|
+
await inMemoryLoader.dataUnit.loadMetadata();
|
|
52
|
+
expect(loadData).toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('DataUnitInMemoryLoader - getConvertedValue', () => {
|
|
57
|
+
let descriptor: FieldDescriptor;
|
|
58
|
+
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
descriptor = { name: 'testField', dataType: DataType.TEXT, label: 'mock' }; // Valor padrão para inicialização
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should return the original string if descriptor is undefined', () => {
|
|
64
|
+
const result = DataUnitInMemoryLoader.getConvertedValue(undefined as any, 'testValue');
|
|
65
|
+
expect(result).toBe('testValue');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should return the original string if dataType is TEXT', () => {
|
|
69
|
+
descriptor.dataType = DataType.TEXT;
|
|
70
|
+
const result = DataUnitInMemoryLoader.getConvertedValue(descriptor, 'testValue');
|
|
71
|
+
expect(result).toBe('testValue');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should convert to boolean when dataType is BOOLEAN', () => {
|
|
75
|
+
descriptor.dataType = DataType.BOOLEAN;
|
|
76
|
+
expect(DataUnitInMemoryLoader.getConvertedValue(descriptor, 'S')).toBe(true);
|
|
77
|
+
expect(DataUnitInMemoryLoader.getConvertedValue(descriptor, 'N')).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should convert to number when dataType is NUMBER', () => {
|
|
81
|
+
descriptor.dataType = DataType.NUMBER;
|
|
82
|
+
expect(DataUnitInMemoryLoader.getConvertedValue(descriptor, '123')).toBe(123);
|
|
83
|
+
expect(DataUnitInMemoryLoader.getConvertedValue(descriptor, '45.67')).toBe(45.67);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should parse JSON when dataType is OBJECT', () => {
|
|
87
|
+
descriptor.dataType = DataType.OBJECT;
|
|
88
|
+
const jsonString = '{"key": "value"}';
|
|
89
|
+
const expectedObject = { key: 'value' };
|
|
90
|
+
expect(DataUnitInMemoryLoader.getConvertedValue(descriptor, jsonString)).toEqual(expectedObject);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should convert to date when dataType is DATE and format is ISO', () => {
|
|
94
|
+
descriptor.dataType = DataType.DATE;
|
|
95
|
+
|
|
96
|
+
const isoDate = '2023-01-01T00:00:00Z';
|
|
97
|
+
jest.spyOn(DateUtils, 'validateDate').mockImplementation((date) => date);
|
|
98
|
+
|
|
99
|
+
const result = DataUnitInMemoryLoader.getConvertedValue(descriptor, isoDate, RECORD_DATE_FORMAT.ISO);
|
|
100
|
+
expect(DateUtils.validateDate).toHaveBeenCalledWith(new Date(isoDate), true);
|
|
101
|
+
expect(result).toEqual(new Date(isoDate));
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should convert to date when dataType is DATE and format is not ISO', () => {
|
|
105
|
+
descriptor.dataType = DataType.DATE;
|
|
106
|
+
|
|
107
|
+
const dateString = '01/01/2023';
|
|
108
|
+
jest.spyOn(DateUtils, 'strToDate').mockImplementation(() => new Date(2023, 0, 1));
|
|
109
|
+
|
|
110
|
+
const result = DataUnitInMemoryLoader.getConvertedValue(descriptor, dateString, RECORD_DATE_FORMAT.DD_MM_YYYY);
|
|
111
|
+
expect(DateUtils.strToDate).toHaveBeenCalledWith(dateString, true);
|
|
112
|
+
expect(result).toEqual(new Date(2023, 0, 1));
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should return the original string if no dataType matches', () => {
|
|
116
|
+
descriptor.dataType = undefined as any; // Simula um caso inválido
|
|
117
|
+
const result = DataUnitInMemoryLoader.getConvertedValue(descriptor, 'testValue');
|
|
118
|
+
expect(result).toBe('testValue');
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('DataUnitInMemoryLoader - removeLoader', () => {
|
|
123
|
+
let loader: DataUnitInMemoryLoader;
|
|
124
|
+
const mockedDataUnit = {} as DataUnit;
|
|
125
|
+
|
|
126
|
+
beforeEach(() => {
|
|
127
|
+
loader = new DataUnitInMemoryLoader();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should resolve with the provided record IDs', async () => {
|
|
131
|
+
const mockRecordIds = ['record1', 'record2', 'record3'];
|
|
132
|
+
|
|
133
|
+
const result = await loader.removeLoader(mockedDataUnit, mockRecordIds);
|
|
134
|
+
|
|
135
|
+
expect(result).toEqual(mockRecordIds);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should handle empty record ID array', async () => {
|
|
139
|
+
const mockRecordIds: string[] = [];
|
|
140
|
+
|
|
141
|
+
const result = await loader.removeLoader(mockedDataUnit, mockRecordIds);
|
|
142
|
+
|
|
143
|
+
expect(result).toEqual([]);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should resolve the promise', async () => {
|
|
147
|
+
const mockRecordIds = ['record1'];
|
|
148
|
+
|
|
149
|
+
await expect(loader.removeLoader(mockedDataUnit, mockRecordIds)).resolves.toEqual(mockRecordIds);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('DataUnitInMemoryLoader - buildInitialRecords (indiretamente via set records)', () => {
|
|
154
|
+
let loader: DataUnitInMemoryLoader;
|
|
155
|
+
let mockRecords: Array<Record> = [
|
|
156
|
+
{ id: '1', amount: '100', isActive: 'S', createdAt: '01/01/2023' },
|
|
157
|
+
{ id: '2', amount: '200.50', isActive: 'N', createdAt: '02/01/2023' },
|
|
158
|
+
] as unknown as Record[];
|
|
159
|
+
|
|
160
|
+
let mockMetadata = {
|
|
161
|
+
fields: [
|
|
162
|
+
{ name: 'id', label: 'id', dataType: DataType.TEXT },
|
|
163
|
+
{ name: 'amount', label: 'amount', dataType: DataType.NUMBER },
|
|
164
|
+
{ name: 'isActive', label: 'isActive', dataType: DataType.BOOLEAN },
|
|
165
|
+
{ name: 'createdAt', label: 'createdAt', dataType: DataType.DATE },
|
|
166
|
+
],
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
beforeEach(() => {
|
|
170
|
+
loader = new DataUnitInMemoryLoader(mockMetadata as any, [], { recordDateFormat: RECORD_DATE_FORMAT.DD_MM_YYYY });
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should build initial records and convert field values based on metadata', () => {
|
|
174
|
+
loader.records = mockRecords;
|
|
175
|
+
const initialRecords = loader['_initialRecords'];
|
|
176
|
+
|
|
177
|
+
expect(initialRecords).toHaveLength(2);
|
|
178
|
+
|
|
179
|
+
expect(initialRecords[0]).toEqual({
|
|
180
|
+
id: '1',
|
|
181
|
+
amount: 100,
|
|
182
|
+
isActive: true,
|
|
183
|
+
createdAt: expect.any(Date),
|
|
184
|
+
__record__id__: expect.any(String),
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
expect(initialRecords[1]).toEqual({
|
|
188
|
+
id: '2',
|
|
189
|
+
amount: 200.5,
|
|
190
|
+
isActive: false,
|
|
191
|
+
createdAt: expect.any(Date),
|
|
192
|
+
__record__id__: expect.any(String),
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('should generate unique IDs for records without "__record__id__"', () => {
|
|
197
|
+
loader.records = [{ id: '3', amount: '300' }] as unknown as Record[];
|
|
198
|
+
|
|
199
|
+
const builtRecords = loader['_initialRecords'];
|
|
200
|
+
expect(builtRecords).toHaveLength(1);
|
|
201
|
+
|
|
202
|
+
expect(builtRecords[0]).toHaveProperty('__record__id__');
|
|
203
|
+
expect(typeof builtRecords[0]['__record__id__']).toBe('string');
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('should leave fields untouched if no matching metadata exists', () => {
|
|
207
|
+
mockRecords[0]['extraField'] = 'unchanged';
|
|
208
|
+
loader.records = mockRecords;
|
|
209
|
+
|
|
210
|
+
const builtRecords = loader['_initialRecords'];
|
|
211
|
+
expect(builtRecords[0]).toHaveProperty('extraField', 'unchanged');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('should skip conversion for non-string field values', () => {
|
|
215
|
+
mockRecords[0].amount = 500;
|
|
216
|
+
loader.records = mockRecords;
|
|
217
|
+
|
|
218
|
+
const builtRecords = loader['_initialRecords'];
|
|
219
|
+
expect(builtRecords[0].amount).toBe(500);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
jest.mock('../../../../src/utils/ColumnFilterManager', () => ({
|
|
2
|
+
ColumnFilterManager: {
|
|
3
|
+
getColumnFilters: jest.fn(),
|
|
4
|
+
getFilterFunction: jest.fn(),
|
|
5
|
+
},
|
|
6
|
+
}));
|
|
7
|
+
|
|
8
|
+
jest.mock('../../../../src/utils/SortingUtils', () => {
|
|
9
|
+
return {
|
|
10
|
+
__esModule: true, // Indica que este módulo possui uma exportação padrão
|
|
11
|
+
default: {
|
|
12
|
+
getSortingFunction: jest.fn(),
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
import { DataUnitLoaderUtils } from '../../../../src/dataunit/loader/utils/dataUnitLoaderUtils';
|
|
19
|
+
import { IColumnFilter } from '../../../../src/utils/ColumnFilterManager';
|
|
20
|
+
import { Record } from '../../../../src/dataunit/DataUnit';
|
|
21
|
+
import { Filter, Sort, SortMode } from '../../../../src/dataunit/metadata/UnitMetadata';
|
|
22
|
+
import { DataType } from '../../../../src/dataunit/metadata/DataType';
|
|
23
|
+
import { ColumnFilterManager } from '../../../../src/utils/ColumnFilterManager';
|
|
24
|
+
import SortingUtils from '../../../../src/utils/SortingUtils';
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
describe('Utility Functions', () => {
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
jest.clearAllMocks();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('applyFilter', () => {
|
|
33
|
+
it('should return the original records if no filters are provided', () => {
|
|
34
|
+
const records: Record[] = [{ __record__id__: '1' }, { __record__id__: '2' }];
|
|
35
|
+
const filters: Filter[] = [];
|
|
36
|
+
const columnFilterMock = new Map<string, IColumnFilter>();
|
|
37
|
+
|
|
38
|
+
(ColumnFilterManager.getColumnFilters as jest.Mock).mockReturnValue(columnFilterMock);
|
|
39
|
+
(ColumnFilterManager.getFilterFunction as jest.Mock).mockReturnValue(undefined);
|
|
40
|
+
|
|
41
|
+
const result = DataUnitLoaderUtils.applyFilter(records, {} as any, filters);
|
|
42
|
+
|
|
43
|
+
expect(result).toEqual(records);
|
|
44
|
+
expect(ColumnFilterManager.getColumnFilters).toHaveBeenCalledWith(filters, '');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should filter records based on provided filters', () => {
|
|
48
|
+
const records: Record[] = [{ __record__id__: '1' }, { __record__id__: '2' }];
|
|
49
|
+
const filters: Filter[] = [{ name: 'test', expression: '1' }];
|
|
50
|
+
const columnFilterMock = new Map<string, IColumnFilter>();
|
|
51
|
+
columnFilterMock.set('test', { columnName: 'name', ...filters[0] } as IColumnFilter);
|
|
52
|
+
|
|
53
|
+
(ColumnFilterManager.getColumnFilters as jest.Mock).mockReturnValue(columnFilterMock);
|
|
54
|
+
(ColumnFilterManager.getFilterFunction as jest.Mock).mockReturnValue((record: Record) => record.__record__id__ === '1');
|
|
55
|
+
|
|
56
|
+
const result = DataUnitLoaderUtils.applyFilter(records, {} as any, filters);
|
|
57
|
+
|
|
58
|
+
expect(result).toEqual([{ __record__id__: '1' }]);
|
|
59
|
+
expect(ColumnFilterManager.getFilterFunction).toHaveBeenCalledWith({}, Array.from(columnFilterMock.values()));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('buildPaginationInfo function', () => {
|
|
64
|
+
it('should return correct pagination info with default values', () => {
|
|
65
|
+
|
|
66
|
+
const result = DataUnitLoaderUtils.buildPaginationInfo({
|
|
67
|
+
recordsLength: 0,
|
|
68
|
+
offset: 0,
|
|
69
|
+
recordsPerPage: 5,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(result).toEqual({
|
|
73
|
+
currentPage: 0,
|
|
74
|
+
firstRecord: 0,
|
|
75
|
+
lastRecord: 0,
|
|
76
|
+
total: 0,
|
|
77
|
+
hasMore: false,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should redosLenth as same size as recordsPerPage', () => {
|
|
82
|
+
const result = DataUnitLoaderUtils.buildPaginationInfo({
|
|
83
|
+
recordsLength: 10,
|
|
84
|
+
offset: 0,
|
|
85
|
+
recordsPerPage: 10,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(result).toEqual({
|
|
89
|
+
currentPage: 0,
|
|
90
|
+
firstRecord: 1,
|
|
91
|
+
lastRecord: 10,
|
|
92
|
+
total: 10,
|
|
93
|
+
hasMore: false,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
it('should handle case when totalRecordsLength and offset 0', () => {
|
|
99
|
+
const result = DataUnitLoaderUtils.buildPaginationInfo({
|
|
100
|
+
recordsLength: 10,
|
|
101
|
+
offset: 0,
|
|
102
|
+
recordsPerPage: 5,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
expect(result).toEqual({
|
|
106
|
+
currentPage: 0,
|
|
107
|
+
firstRecord: 1,
|
|
108
|
+
lastRecord: 5,
|
|
109
|
+
total: 10,
|
|
110
|
+
hasMore: true,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should handle case when currentPageLength is less than totalRecordsLength and lastPage', () => {
|
|
115
|
+
const result = DataUnitLoaderUtils.buildPaginationInfo({
|
|
116
|
+
recordsLength: 10,
|
|
117
|
+
offset: 5,
|
|
118
|
+
recordsPerPage: 5,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
expect(result).toEqual({
|
|
122
|
+
currentPage: 1,
|
|
123
|
+
firstRecord: 6,
|
|
124
|
+
lastRecord: 10,
|
|
125
|
+
total: 10,
|
|
126
|
+
hasMore: false,
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('applySorting function', () => {
|
|
132
|
+
|
|
133
|
+
it('should return the original records if no sorting is provided', () => {
|
|
134
|
+
const records: Record[] = [{ __record__id__: '1' }, { __record__id__: '2' }];
|
|
135
|
+
const sorting: Sort[] = [];
|
|
136
|
+
|
|
137
|
+
const result = DataUnitLoaderUtils.applySorting(records, {} as any, sorting);
|
|
138
|
+
|
|
139
|
+
expect(result).toEqual(records);
|
|
140
|
+
expect(SortingUtils.getSortingFunction).not.toHaveBeenCalled();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('should sort records based on provided sorting criteria', () => {
|
|
144
|
+
const records: Record[] = [{ __record__id__: '2' }, { __record__id__: '1' }];
|
|
145
|
+
const sorting: Sort[] = [{ field: '__record__id__', mode: SortMode.ASC, dataType: DataType.TEXT }];
|
|
146
|
+
|
|
147
|
+
const sortingFunction = (a: Record, b: Record) => (a.__record__id__ > b.__record__id__ ? 1 : -1);
|
|
148
|
+
(SortingUtils.getSortingFunction as jest.Mock).mockReturnValue(sortingFunction);
|
|
149
|
+
|
|
150
|
+
const result = DataUnitLoaderUtils.applySorting(records, {} as any, sorting);
|
|
151
|
+
|
|
152
|
+
expect(result).toEqual([{ __record__id__: '1' }, { __record__id__: '2' }]);
|
|
153
|
+
expect(SortingUtils.getSortingFunction).toHaveBeenCalledWith({}, sorting);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { ColumnFilterManager, IColumnFilter } from '../../src/utils/ColumnFilterManager.js';
|
|
2
|
+
import { FieldDescriptor, Filter, FilterParam } from '../../src/dataunit/metadata/UnitMetadata.js';
|
|
3
|
+
import DataUnit, { Record } from '../../src/dataunit/DataUnit';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
describe('ColumnFilterManager', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
jest.clearAllMocks();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
describe('getColumnFilters', () => {
|
|
13
|
+
it('should return an empty map if filters are undefined or empty', () => {
|
|
14
|
+
expect(ColumnFilterManager.getColumnFilters(undefined as any, 'field')).toEqual(new Map());
|
|
15
|
+
expect(ColumnFilterManager.getColumnFilters([], 'field')).toEqual(new Map());
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should return a map of filters matching the pattern and not the provided fieldName', () => {
|
|
19
|
+
const filters: Filter[] = [
|
|
20
|
+
{ name: 'FILTRO_COLUNA_field1', expression: '' },
|
|
21
|
+
{ name: 'FILTRO_COLUNA_field2', expression: '' },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const result = ColumnFilterManager.getColumnFilters(filters, 'field1');
|
|
25
|
+
|
|
26
|
+
expect(result.size).toBe(1);
|
|
27
|
+
expect(result.has('FILTRO_COLUNA_field2')).toBe(true);
|
|
28
|
+
expect(result.get('FILTRO_COLUNA_field2')?.columnName).toBe('field2');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
describe('getFilterFunction', () => {
|
|
34
|
+
const mockDataUnit = {
|
|
35
|
+
getField: jest.fn(),
|
|
36
|
+
valueFromString: jest.fn()
|
|
37
|
+
} as unknown as DataUnit;
|
|
38
|
+
|
|
39
|
+
mockDataUnit.getField = jest.fn().mockReturnValue({} as FieldDescriptor);
|
|
40
|
+
mockDataUnit.valueFromString = jest.fn().mockReturnValue('test');
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
jest.clearAllMocks();
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('should return undefined if no filters are provided', () => {
|
|
47
|
+
expect(ColumnFilterManager.getFilterFunction(mockDataUnit, undefined)).toBeUndefined();
|
|
48
|
+
expect(ColumnFilterManager.getFilterFunction(mockDataUnit, [])).toBeUndefined();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should return a function that evaluates records based on filters', () => {
|
|
52
|
+
const filters: IColumnFilter[] = [
|
|
53
|
+
{
|
|
54
|
+
columnName: 'field1',
|
|
55
|
+
name: 'FILTRO_COLUNA_field1',
|
|
56
|
+
expression: '',
|
|
57
|
+
params: [{value: "mockedPAram"} as FilterParam]
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
const filterFunction = ColumnFilterManager.getFilterFunction(mockDataUnit, filters);
|
|
63
|
+
expect(filterFunction).toBeDefined();
|
|
64
|
+
|
|
65
|
+
const record: Record = { field1: 'test' } as unknown as Record;
|
|
66
|
+
expect(filterFunction!(record)).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should return a function that evaluates records and return false', () => {
|
|
70
|
+
const filters: IColumnFilter[] = [
|
|
71
|
+
{
|
|
72
|
+
columnName: 'field1',
|
|
73
|
+
name: 'FILTRO_COLUNA_field1',
|
|
74
|
+
expression: '',
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
const filterFunction = ColumnFilterManager.getFilterFunction(mockDataUnit, filters);
|
|
79
|
+
expect(filterFunction).toBeDefined();
|
|
80
|
+
|
|
81
|
+
const record: Record = { field1: 'test' } as unknown as Record;
|
|
82
|
+
expect(filterFunction!(record)).toBe(false);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
describe("compileDistinct", () => {
|
|
88
|
+
const mockDataUnit = {
|
|
89
|
+
getField: jest.fn(),
|
|
90
|
+
valueFromString: jest.fn()
|
|
91
|
+
} as unknown as DataUnit;
|
|
92
|
+
|
|
93
|
+
mockDataUnit.getFormattedValue = jest.fn().mockImplementation((_, value) => value);
|
|
94
|
+
mockDataUnit.getFormattedValue = jest.fn().mockImplementation((_, value) => value);
|
|
95
|
+
|
|
96
|
+
const filters: Filter[] = [{ name: "FILTRO_COLUNA_fieldName", expression: '' }];
|
|
97
|
+
mockDataUnit.getLastLoadRequest = jest.fn().mockReturnValue({ filters });
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
beforeEach(() => {
|
|
101
|
+
jest.clearAllMocks();
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it("should return an array of distinct field values formatted correctly", () => {
|
|
105
|
+
mockDataUnit.records = [
|
|
106
|
+
{ fieldName: "value1" },
|
|
107
|
+
{ fieldName: "value2" },
|
|
108
|
+
{ fieldName: "value1" },
|
|
109
|
+
] as unknown as Record[];
|
|
110
|
+
|
|
111
|
+
const distinct = ColumnFilterManager.compileDistinct("fieldName", mockDataUnit);
|
|
112
|
+
|
|
113
|
+
expect(distinct).toEqual([
|
|
114
|
+
{ label: "value1", value: "value1", check: true },
|
|
115
|
+
{ label: "value2", value: "value2", check: true },
|
|
116
|
+
]);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("should filter records if a load request is present", () => {
|
|
120
|
+
mockDataUnit.records = [
|
|
121
|
+
{ fieldName: "value1" },
|
|
122
|
+
{ fieldName: "value2" },
|
|
123
|
+
] as unknown as Record[];
|
|
124
|
+
|
|
125
|
+
const distinct = ColumnFilterManager.compileDistinct("fieldName", mockDataUnit);
|
|
126
|
+
|
|
127
|
+
expect(distinct).toEqual([
|
|
128
|
+
{ label: "value1", value: "value1", check: true },
|
|
129
|
+
{ label: "value2", value: "value2", check: true },
|
|
130
|
+
]);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|