@datagrok/compute 1.45.0 → 1.45.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/CHANGELOG.md +4 -0
- package/CREDITS.md +41 -0
- package/dist/package-test.js +1 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +3 -2
- package/scripts/complexInputs.js +13 -0
- package/scripts/globalValidationTest.js +11 -0
- package/scripts/simpleInputs.js +16 -0
- package/scripts/simpleInputsDefaultValues.js +15 -0
- package/scripts/validationTest.js +11 -0
- package/src/package-api.ts +16 -0
- package/src/package-test.ts +3 -0
- package/src/package.g.ts +24 -0
- package/src/package.ts +81 -2
- package/src/tests/rich-function-view-direct-tests.ts +403 -0
- package/src/tests/rich-function-view-tests.ts +512 -0
- package/src/tests/snapshots/fc1.json +1 -0
- package/src/tests/utils.ts +8 -0
- package/tsconfig.json +1 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/compute",
|
|
3
3
|
"friendlyName": "Compute",
|
|
4
|
-
"version": "1.45.
|
|
4
|
+
"version": "1.45.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Andrey Sharapov",
|
|
7
7
|
"email": "andrey.sharapov@softwarecountry.com"
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"directory": "packages/Compute"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@datagrok-libraries/compute-
|
|
16
|
+
"@datagrok-libraries/compute-api": "^0.7.6",
|
|
17
|
+
"@datagrok-libraries/compute-utils": "^1.46.1",
|
|
17
18
|
"@datagrok-libraries/test": "^1.2.0",
|
|
18
19
|
"@datagrok-libraries/utils": "^4.7.1",
|
|
19
20
|
"cash-dom": "^8.1.5",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//name: complexInputs
|
|
2
|
+
//language: javascript
|
|
3
|
+
//description: RichFunctionView custom input and df input
|
|
4
|
+
//input: dataframe df
|
|
5
|
+
//input: string data { input: Compute:CustomInputMock; inputOptions: { "arg1": 1, "arg2": "test", "arg3": true } }
|
|
6
|
+
//output: dataframe dfout
|
|
7
|
+
//output: string dataout
|
|
8
|
+
//editor: Compute:RichFunctionViewEditor
|
|
9
|
+
//meta.uploadMode: true
|
|
10
|
+
//tags: test
|
|
11
|
+
|
|
12
|
+
dfout=df;
|
|
13
|
+
dataout=data;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//name: globalValidationTest
|
|
2
|
+
//description: Global validators test
|
|
3
|
+
//language: javascript
|
|
4
|
+
//tags: simulation, test
|
|
5
|
+
//input: double a {caption: First value; validatorFunc: Compute:GlobalValidatorDemoFactory; validatorFuncOptions: { "max": 100 } }
|
|
6
|
+
//input: double b {caption: Second value; validatorFunc: Compute:GlobalValidatorDemoFactory; validatorFuncOptions: { "max": 100 } }
|
|
7
|
+
//input: double c {caption: Third value; validatorFunc: Compute:GlobalValidatorDemoFactory; validatorFuncOptions: { "max": 100 } }
|
|
8
|
+
//editor: Compute:RichFunctionViewEditor
|
|
9
|
+
//output: double s
|
|
10
|
+
|
|
11
|
+
s = a + b + c;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//name: simpleInputs
|
|
2
|
+
//language: javascript
|
|
3
|
+
//description: RichFunctionView simple inputs test
|
|
4
|
+
//input: int a
|
|
5
|
+
//input: double b
|
|
6
|
+
//input: string c
|
|
7
|
+
//output: int aout
|
|
8
|
+
//output: double bout
|
|
9
|
+
//output: string cout
|
|
10
|
+
//editor: Compute:RichFunctionViewEditor
|
|
11
|
+
//meta.uploadMode: true
|
|
12
|
+
//tags: test
|
|
13
|
+
|
|
14
|
+
aout=a;
|
|
15
|
+
bout=b;
|
|
16
|
+
cout=c;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//name: simpleInputsDefaultValues
|
|
2
|
+
//language: javascript
|
|
3
|
+
//description: RichFunctionView simple inputs
|
|
4
|
+
//input: int a=1
|
|
5
|
+
//input: double b=2.2
|
|
6
|
+
//input: string c="test"
|
|
7
|
+
//output: int aout
|
|
8
|
+
//output: double bout
|
|
9
|
+
//output: string cout
|
|
10
|
+
//editor: Compute:RichFunctionViewEditor
|
|
11
|
+
//tags: test
|
|
12
|
+
|
|
13
|
+
aout=a;
|
|
14
|
+
bout=b;
|
|
15
|
+
cout=c;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//name: validationTest
|
|
2
|
+
//description: Custom validators test
|
|
3
|
+
//language: javascript
|
|
4
|
+
//tags: simulation, test
|
|
5
|
+
//input: double a {caption: First value; validatorFunc: Compute:RangeValidatorFactory; validatorFuncOptions: { "min": 1, "max": 10 } }
|
|
6
|
+
//input: double b {caption: Second value; validatorFunc: Compute:RangeValidatorFactory; validatorFuncOptions: { "min": 20, "max": 100 } }
|
|
7
|
+
//input: double x=0 {caption: Async suggestions; validatorFunc: Compute:AsyncValidatorDemoFactory }
|
|
8
|
+
//editor: Compute:RichFunctionViewEditor
|
|
9
|
+
//output: double c
|
|
10
|
+
|
|
11
|
+
c = a + b;
|
package/src/package-api.ts
CHANGED
|
@@ -90,4 +90,20 @@ export namespace funcs {
|
|
|
90
90
|
export async function objectCoolingSelector(params: any ): Promise<any> {
|
|
91
91
|
return await grok.functions.call('Compute:ObjectCoolingSelector', { params });
|
|
92
92
|
}
|
|
93
|
+
|
|
94
|
+
export async function customInputMock(params: any ): Promise<any> {
|
|
95
|
+
return await grok.functions.call('Compute:CustomInputMock', { params });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function rangeValidatorFactory(params: any ): Promise<any> {
|
|
99
|
+
return await grok.functions.call('Compute:RangeValidatorFactory', { params });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function asyncValidatorDemoFactory(params: any ): Promise<any> {
|
|
103
|
+
return await grok.functions.call('Compute:AsyncValidatorDemoFactory', { params });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function globalValidatorDemoFactory(params: any ): Promise<any> {
|
|
107
|
+
return await grok.functions.call('Compute:GlobalValidatorDemoFactory', { params });
|
|
108
|
+
}
|
|
93
109
|
}
|
package/src/package-test.ts
CHANGED
|
@@ -2,6 +2,9 @@ import * as DG from 'datagrok-api/dg';
|
|
|
2
2
|
import * as grok from 'datagrok-api/grok';
|
|
3
3
|
import {runTests, tests, TestContext, initAutoTests as initTests} from '@datagrok-libraries/test/src/test';
|
|
4
4
|
|
|
5
|
+
import './tests/rich-function-view-tests';
|
|
6
|
+
import './tests/rich-function-view-direct-tests';
|
|
7
|
+
|
|
5
8
|
export const _package = new DG.Package();
|
|
6
9
|
export {tests};
|
|
7
10
|
|
package/src/package.g.ts
CHANGED
|
@@ -92,3 +92,27 @@ export function CustomStringInput(params: any) {
|
|
|
92
92
|
export function ObjectCoolingSelector(params: any) {
|
|
93
93
|
return PackageFunctions.ObjectCoolingSelector(params);
|
|
94
94
|
}
|
|
95
|
+
|
|
96
|
+
//input: object params
|
|
97
|
+
//output: object input
|
|
98
|
+
export async function CustomInputMock(params: any) : Promise<any> {
|
|
99
|
+
return await PackageFunctions.CustomInputMock(params);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//input: object params
|
|
103
|
+
//output: object validator
|
|
104
|
+
export function RangeValidatorFactory(params: any) {
|
|
105
|
+
return PackageFunctions.RangeValidatorFactory(params);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//input: object params
|
|
109
|
+
//output: object validator
|
|
110
|
+
export function AsyncValidatorDemoFactory(params: any) {
|
|
111
|
+
return PackageFunctions.AsyncValidatorDemoFactory(params);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//input: object params
|
|
115
|
+
//output: object validator
|
|
116
|
+
export function GlobalValidatorDemoFactory(params: any) {
|
|
117
|
+
return PackageFunctions.GlobalValidatorDemoFactory(params);
|
|
118
|
+
}
|
package/src/package.ts
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
import * as grok from 'datagrok-api/grok';
|
|
3
3
|
import * as ui from 'datagrok-api/ui';
|
|
4
4
|
import * as DG from 'datagrok-api/dg';
|
|
5
|
+
import {BehaviorSubject} from 'rxjs';
|
|
5
6
|
import {filter} from 'rxjs/operators';
|
|
6
7
|
import {OutliersSelectionViewer} from './outliers-selection/outliers-selection-viewer';
|
|
7
8
|
import {
|
|
8
9
|
ComputationView as ComputationViewInst,
|
|
9
10
|
RichFunctionView as RichFunctionViewInst,
|
|
10
11
|
PipelineView as PipelineViewInst,
|
|
11
|
-
CustomFunctionView as CustomFunctionViewInst,
|
|
12
12
|
UiUtils,
|
|
13
|
+
FuncCallInput,
|
|
13
14
|
} from '@datagrok-libraries/compute-utils';
|
|
14
15
|
import {
|
|
15
16
|
ValidationInfo,
|
|
@@ -30,12 +31,42 @@ import {
|
|
|
30
31
|
export * from './package.g';
|
|
31
32
|
export const _package = new DG.Package();
|
|
32
33
|
|
|
34
|
+
class InputMock implements FuncCallInput {
|
|
35
|
+
_value = new BehaviorSubject<any>(null);
|
|
36
|
+
notify = true;
|
|
37
|
+
enabled = true;
|
|
38
|
+
root = ui.div('', {style: {width: '100%'}});
|
|
39
|
+
input = ui.input.toggle('test', {value: true});
|
|
40
|
+
|
|
41
|
+
constructor() {
|
|
42
|
+
this.root.append(this.input.root);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
set value(v: any) {
|
|
46
|
+
const nv = v ? JSON.parse(v) : '';
|
|
47
|
+
this._value.next(nv);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get value() {
|
|
51
|
+
if (!this._value.value)
|
|
52
|
+
return '';
|
|
53
|
+
|
|
54
|
+
return JSON.stringify(this._value.value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
onInput(fn: Function) {
|
|
58
|
+
return this._value.subscribe(() => {
|
|
59
|
+
if (this.notify)
|
|
60
|
+
fn(this.value);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
33
65
|
// for compute-api pakage
|
|
34
66
|
export const testPipeline = testPipelineInst;
|
|
35
67
|
export const deepCopy = deepCopyInst;
|
|
36
68
|
export const CompView = ComputationViewInst;
|
|
37
69
|
export const RFV = RichFunctionViewInst;
|
|
38
|
-
export const CFV = CustomFunctionViewInst;
|
|
39
70
|
export const Pipeline = PipelineViewInst;
|
|
40
71
|
export const makeValidationResult = makeValidationResultInst;
|
|
41
72
|
export const makeAdvice = makeAdviceInst;
|
|
@@ -253,4 +284,52 @@ export class PackageFunctions {
|
|
|
253
284
|
}
|
|
254
285
|
|
|
255
286
|
|
|
287
|
+
@grok.decorators.func({outputs: [{type: 'object', name: 'input'}]})
|
|
288
|
+
static async CustomInputMock(
|
|
289
|
+
@grok.decorators.param({type: 'object'}) params: any): Promise<FuncCallInput> {
|
|
290
|
+
return new InputMock();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
@grok.decorators.func({outputs: [{type: 'object', name: 'validator'}]})
|
|
295
|
+
static RangeValidatorFactory(
|
|
296
|
+
@grok.decorators.param({type: 'object'}) params: any) {
|
|
297
|
+
const {min, max} = params;
|
|
298
|
+
return (val: number) => {
|
|
299
|
+
if (val < min || val > max)
|
|
300
|
+
return makeValidationResultInst({errors: [`Out of range [${min}, ${max}] value: ${val}`]});
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
@grok.decorators.func({outputs: [{type: 'object', name: 'validator'}]})
|
|
306
|
+
static AsyncValidatorDemoFactory(
|
|
307
|
+
@grok.decorators.param({type: 'object'}) params: any) {
|
|
308
|
+
return async (val: number) => {
|
|
309
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
310
|
+
if (val === 0)
|
|
311
|
+
return makeValidationResultInst({warnings: [`Try non-null value`]});
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
@grok.decorators.func({outputs: [{type: 'object', name: 'validator'}]})
|
|
317
|
+
static GlobalValidatorDemoFactory(
|
|
318
|
+
@grok.decorators.param({type: 'object'}) params: any) {
|
|
319
|
+
const {max} = params;
|
|
320
|
+
return async (_val: number, info: ValidationInfo) => {
|
|
321
|
+
if (info.isRevalidation) {
|
|
322
|
+
if (info.context?.isOk)
|
|
323
|
+
return makeValidationResultInst();
|
|
324
|
+
return makeValidationResultInst({warnings: [`Try lowering a value as well`]});
|
|
325
|
+
}
|
|
326
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
327
|
+
const {a, b, c} = info.funcCall.inputs;
|
|
328
|
+
const s = a + b + c;
|
|
329
|
+
const isOk = s <= max;
|
|
330
|
+
const valRes = isOk ? makeValidationResultInst() : makeValidationResultInst({warnings: [`Try lowering a value`]});
|
|
331
|
+
const fields = ['a', 'b', 'c'].filter((p) => p !== info.param);
|
|
332
|
+
return makeRevalidationInst(fields, {isOk}, valRes);
|
|
333
|
+
};
|
|
334
|
+
}
|
|
256
335
|
}
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import * as DG from 'datagrok-api/dg';
|
|
2
|
+
import {category, test, before, delay} from '@datagrok-libraries/test/src/test';
|
|
3
|
+
import {RichFunctionView} from '@datagrok-libraries/compute-utils';
|
|
4
|
+
import {take, filter} from 'rxjs/operators';
|
|
5
|
+
import {applyTransformations} from '@datagrok-libraries/utils/src/json-serialization';
|
|
6
|
+
import {getFuncCallIO} from './utils';
|
|
7
|
+
import {expectDeepEqual} from '@datagrok-libraries/utils/src/expect';
|
|
8
|
+
import {InputVariants} from '@datagrok-libraries/compute-utils/old-views/src/rich-function-view';
|
|
9
|
+
import fc1 from './snapshots/fc1.json';
|
|
10
|
+
|
|
11
|
+
category('Compute: RichFunctionView Inputs', async () => {
|
|
12
|
+
before(async () => {
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('Simple inputs setParamValue', async () => {
|
|
16
|
+
const view = new RichFunctionView('Compute:simpleInputs', {historyEnabled: false, isTabbed: false});
|
|
17
|
+
const inputValues: Record<string, any> = {
|
|
18
|
+
a: 1,
|
|
19
|
+
b: 2.2,
|
|
20
|
+
c: 'test',
|
|
21
|
+
};
|
|
22
|
+
const inputsMap: Record<string, InputVariants> = {};
|
|
23
|
+
view.afterInputPropertyRender.subscribe(({prop, input}) => {
|
|
24
|
+
inputsMap[prop.name] = input;
|
|
25
|
+
});
|
|
26
|
+
await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
|
|
27
|
+
view.funcCall.setParamValue('a', 1);
|
|
28
|
+
view.funcCall.setParamValue('b', 2.2);
|
|
29
|
+
view.funcCall.setParamValue('c', 'test');
|
|
30
|
+
await view.doRun();
|
|
31
|
+
const expected = {
|
|
32
|
+
'inputs': [
|
|
33
|
+
['a', 1],
|
|
34
|
+
['b', 2.2],
|
|
35
|
+
['c', 'test'],
|
|
36
|
+
],
|
|
37
|
+
'outputs': [
|
|
38
|
+
['aout', 1],
|
|
39
|
+
['bout', 2.2],
|
|
40
|
+
['cout', 'test'],
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
expectDeepEqual(getFuncCallIO(view.funcCall), expected, {prefix: 'funcCall'});
|
|
44
|
+
expectDeepEqual(getFuncCallIO(view.lastCall!), expected, {prefix: 'lastCall'});
|
|
45
|
+
for (const [name, val] of Object.entries(inputValues))
|
|
46
|
+
expectDeepEqual(inputsMap[name].value, val, {prefix: `input ${name}`});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('Simple inputs inputs tweak', async () => {
|
|
50
|
+
const view = new RichFunctionView('Compute:simpleInputs', {historyEnabled: false, isTabbed: false});
|
|
51
|
+
const inputValues: Record<string, any> = {
|
|
52
|
+
a: 1,
|
|
53
|
+
b: 2.2,
|
|
54
|
+
c: 'test',
|
|
55
|
+
};
|
|
56
|
+
const inputsMap: Record<string, InputVariants> = {};
|
|
57
|
+
view.afterInputPropertyRender.subscribe(({prop, input}) => {
|
|
58
|
+
inputsMap[prop.name] = input;
|
|
59
|
+
});
|
|
60
|
+
await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
|
|
61
|
+
await delay(100);
|
|
62
|
+
for (const [name, input] of Object.entries(inputsMap)) {
|
|
63
|
+
input.value = inputValues[name];
|
|
64
|
+
const element = (input as any).input;
|
|
65
|
+
element.dispatchEvent(new Event('input', {bubbles: true}));
|
|
66
|
+
}
|
|
67
|
+
await delay(300);
|
|
68
|
+
await view.doRun();
|
|
69
|
+
const expected = {
|
|
70
|
+
'inputs': [
|
|
71
|
+
['a', 1],
|
|
72
|
+
['b', 2.2],
|
|
73
|
+
['c', 'test'],
|
|
74
|
+
],
|
|
75
|
+
'outputs': [
|
|
76
|
+
['aout', 1],
|
|
77
|
+
['bout', 2.2],
|
|
78
|
+
['cout', 'test'],
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
expectDeepEqual(getFuncCallIO(view.funcCall), expected, {prefix: 'funcCall'});
|
|
82
|
+
expectDeepEqual(getFuncCallIO(view.lastCall!), expected, {prefix: 'lastCall'});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('Simple inputs setParamValue rerun', async () => {
|
|
86
|
+
const view = new RichFunctionView('Compute:simpleInputsDefaultValues', {historyEnabled: false, isTabbed: false});
|
|
87
|
+
const inputValues: Record<string, any> = {
|
|
88
|
+
a: 2,
|
|
89
|
+
b: 3.2,
|
|
90
|
+
c: 'test2',
|
|
91
|
+
};
|
|
92
|
+
const inputsMap: Record<string, InputVariants> = {};
|
|
93
|
+
view.afterInputPropertyRender.subscribe(({prop, input}) => {
|
|
94
|
+
inputsMap[prop.name] = input;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
|
|
98
|
+
await delay(100);
|
|
99
|
+
await view.doRun();
|
|
100
|
+
view.funcCall.setParamValue('a', 2);
|
|
101
|
+
view.funcCall.setParamValue('b', 3.2);
|
|
102
|
+
view.funcCall.setParamValue('c', 'test2');
|
|
103
|
+
await view.doRun();
|
|
104
|
+
const expected = {
|
|
105
|
+
'inputs': [
|
|
106
|
+
['a', 2],
|
|
107
|
+
['b', 3.2],
|
|
108
|
+
['c', 'test2'],
|
|
109
|
+
],
|
|
110
|
+
'outputs': [
|
|
111
|
+
['aout', 2],
|
|
112
|
+
['bout', 3.2],
|
|
113
|
+
['cout', 'test2'],
|
|
114
|
+
],
|
|
115
|
+
};
|
|
116
|
+
expectDeepEqual(getFuncCallIO(view.funcCall), expected, {prefix: 'funcCall'});
|
|
117
|
+
expectDeepEqual(getFuncCallIO(view.lastCall!), expected, {prefix: 'lastCall'});
|
|
118
|
+
for (const [name, val] of Object.entries(inputValues))
|
|
119
|
+
expectDeepEqual(inputsMap[name].value, val, {prefix: `input ${name}`});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('Simple inputs inputs tweak rerun', async () => {
|
|
123
|
+
const view = new RichFunctionView('Compute:simpleInputsDefaultValues', {historyEnabled: false, isTabbed: false});
|
|
124
|
+
const inputValues: Record<string, any> = {
|
|
125
|
+
a: 2,
|
|
126
|
+
b: 3.2,
|
|
127
|
+
c: 'test2',
|
|
128
|
+
};
|
|
129
|
+
const inputsMap: Record<string, InputVariants> = {};
|
|
130
|
+
view.afterInputPropertyRender.subscribe(({prop, input}) => {
|
|
131
|
+
inputsMap[prop.name] = input;
|
|
132
|
+
});
|
|
133
|
+
await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
|
|
134
|
+
await delay(100);
|
|
135
|
+
await view.doRun();
|
|
136
|
+
await delay(100);
|
|
137
|
+
for (const [name, input] of Object.entries(inputsMap)) {
|
|
138
|
+
input.value = inputValues[name];
|
|
139
|
+
const element = (input as any).input;
|
|
140
|
+
element.dispatchEvent(new Event('input', {bubbles: true}));
|
|
141
|
+
}
|
|
142
|
+
await delay(300);
|
|
143
|
+
await view.doRun();
|
|
144
|
+
const expected = {
|
|
145
|
+
'inputs': [
|
|
146
|
+
['a', 2],
|
|
147
|
+
['b', 3.2],
|
|
148
|
+
['c', 'test2'],
|
|
149
|
+
],
|
|
150
|
+
'outputs': [
|
|
151
|
+
['aout', 2],
|
|
152
|
+
['bout', 3.2],
|
|
153
|
+
['cout', 'test2'],
|
|
154
|
+
],
|
|
155
|
+
};
|
|
156
|
+
expectDeepEqual(getFuncCallIO(view.funcCall), expected, {prefix: 'funcCall'});
|
|
157
|
+
expectDeepEqual(getFuncCallIO(view.lastCall!), expected, {prefix: 'lastCall'});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('Simple inputs default values', async () => {
|
|
161
|
+
const view = new RichFunctionView('Compute:simpleInputsDefaultValues', {historyEnabled: false, isTabbed: false});
|
|
162
|
+
|
|
163
|
+
await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
|
|
164
|
+
await delay(100);
|
|
165
|
+
const expected = {
|
|
166
|
+
'inputs': [
|
|
167
|
+
['a', 1],
|
|
168
|
+
['b', 2.2],
|
|
169
|
+
['c', 'test'],
|
|
170
|
+
],
|
|
171
|
+
};
|
|
172
|
+
expectDeepEqual(getFuncCallIO(view.funcCall).inputs, expected.inputs);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('Complex inputs setParamValue', async () => {
|
|
176
|
+
const view = new RichFunctionView('Compute:complexInputs', {historyEnabled: false, isTabbed: false});
|
|
177
|
+
const inputValues: Record<string, any> = {
|
|
178
|
+
df: DG.DataFrame.fromColumns([
|
|
179
|
+
DG.Column.fromList('double', 'col', [1.1, 2.2, 3.3]),
|
|
180
|
+
]),
|
|
181
|
+
data: JSON.stringify({a: 1, b: 'test'}),
|
|
182
|
+
};
|
|
183
|
+
const inputsMap: Record<string, InputVariants> = {};
|
|
184
|
+
view.afterInputPropertyRender.subscribe(({prop, input}) => {
|
|
185
|
+
inputsMap[prop.name] = input;
|
|
186
|
+
});
|
|
187
|
+
view.funcCall.setParamValue('df', inputValues['df']);
|
|
188
|
+
view.funcCall.setParamValue('data', inputValues['data']);
|
|
189
|
+
await view.doRun();
|
|
190
|
+
expectDeepEqual(getFuncCallIO(view.funcCall), applyTransformations(fc1), {prefix: 'funcCall'});
|
|
191
|
+
expectDeepEqual(getFuncCallIO(view.lastCall!), applyTransformations(fc1), {prefix: 'lastCall'});
|
|
192
|
+
expectDeepEqual(inputsMap.data.value, inputValues.data, {prefix: 'data'});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('Complex inputs inputs tweak', async () => {
|
|
196
|
+
const view = new RichFunctionView('Compute:complexInputs', {historyEnabled: false, isTabbed: false});
|
|
197
|
+
const inputValues: Record<string, any> = {
|
|
198
|
+
df: DG.DataFrame.fromColumns([
|
|
199
|
+
DG.Column.fromList('double', 'col', [1.1, 2.2, 3.3]),
|
|
200
|
+
]),
|
|
201
|
+
data: JSON.stringify({a: 1, b: 'test'}),
|
|
202
|
+
};
|
|
203
|
+
const inputsMap: Record<string, InputVariants> = {};
|
|
204
|
+
view.afterInputPropertyRender.subscribe(({prop, input}) => {
|
|
205
|
+
inputsMap[prop.name] = input;
|
|
206
|
+
});
|
|
207
|
+
await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
|
|
208
|
+
await delay(100);
|
|
209
|
+
inputsMap['data'].value = inputValues['data'];
|
|
210
|
+
view.funcCall.setParamValue('df', inputValues['df']);
|
|
211
|
+
await delay(300);
|
|
212
|
+
await view.doRun();
|
|
213
|
+
expectDeepEqual(getFuncCallIO(view.funcCall), applyTransformations(fc1), {prefix: 'funcCall'});
|
|
214
|
+
expectDeepEqual(getFuncCallIO(view.lastCall!), applyTransformations(fc1), {prefix: 'lastCall'});
|
|
215
|
+
expectDeepEqual(inputsMap.data.value, inputValues.data, {prefix: 'data'});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test('Complex inputs setParamValue rerun', async () => {
|
|
219
|
+
const view = new RichFunctionView('Compute:complexInputs', {historyEnabled: false, isTabbed: false});
|
|
220
|
+
const inputValuesPre: Record<string, any> = {
|
|
221
|
+
df: DG.DataFrame.fromColumns([
|
|
222
|
+
DG.Column.fromList('double', 'col', [11.1, 12.2, 13.3]),
|
|
223
|
+
]),
|
|
224
|
+
data: JSON.stringify({a: 2, b: 'pretest'}),
|
|
225
|
+
};
|
|
226
|
+
const inputsMap: Record<string, InputVariants> = {};
|
|
227
|
+
view.afterInputPropertyRender.subscribe(({prop, input}) => {
|
|
228
|
+
inputsMap[prop.name] = input;
|
|
229
|
+
});
|
|
230
|
+
await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
|
|
231
|
+
view.funcCall.setParamValue('df', inputValuesPre['df']);
|
|
232
|
+
view.funcCall.setParamValue('data', inputValuesPre['data']);
|
|
233
|
+
await view.doRun();
|
|
234
|
+
const inputValues: Record<string, any> = {
|
|
235
|
+
df: DG.DataFrame.fromColumns([
|
|
236
|
+
DG.Column.fromList('double', 'col', [1.1, 2.2, 3.3]),
|
|
237
|
+
]),
|
|
238
|
+
data: JSON.stringify({a: 1, b: 'test'}),
|
|
239
|
+
};
|
|
240
|
+
view.funcCall.setParamValue('df', inputValues['df']);
|
|
241
|
+
view.funcCall.setParamValue('data', inputValues['data']);
|
|
242
|
+
await view.doRun();
|
|
243
|
+
expectDeepEqual(getFuncCallIO(view.funcCall), applyTransformations(fc1), {prefix: 'funcCall'});
|
|
244
|
+
expectDeepEqual(getFuncCallIO(view.lastCall!), applyTransformations(fc1), {prefix: 'lastCall'});
|
|
245
|
+
expectDeepEqual(inputsMap.data.value, inputValues.data, {prefix: 'data'});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test('Complex inputs inputs tweak rerun', async () => {
|
|
249
|
+
const view = new RichFunctionView('Compute:complexInputs', {historyEnabled: false, isTabbed: false});
|
|
250
|
+
const inputValuesPre: Record<string, any> = {
|
|
251
|
+
df: DG.DataFrame.fromColumns([
|
|
252
|
+
DG.Column.fromList('double', 'col', [11.1, 12.2, 13.3]),
|
|
253
|
+
]),
|
|
254
|
+
data: JSON.stringify({a: 2, b: 'pretest'}),
|
|
255
|
+
};
|
|
256
|
+
const inputsMap: Record<string, InputVariants> = {};
|
|
257
|
+
view.afterInputPropertyRender.subscribe(({prop, input}) => {
|
|
258
|
+
inputsMap[prop.name] = input;
|
|
259
|
+
});
|
|
260
|
+
await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
|
|
261
|
+
await delay(100);
|
|
262
|
+
inputsMap['data'].value = inputValuesPre['data'];
|
|
263
|
+
view.funcCall.setParamValue('df', inputValuesPre['df']);
|
|
264
|
+
await delay(300);
|
|
265
|
+
await view.doRun();
|
|
266
|
+
const inputValues: Record<string, any> = {
|
|
267
|
+
df: DG.DataFrame.fromColumns([
|
|
268
|
+
DG.Column.fromList('double', 'col', [1.1, 2.2, 3.3]),
|
|
269
|
+
]),
|
|
270
|
+
data: JSON.stringify({a: 1, b: 'test'}),
|
|
271
|
+
};
|
|
272
|
+
inputsMap['data'].value = inputValues['data'];
|
|
273
|
+
view.funcCall.setParamValue('df', inputValues['df']);
|
|
274
|
+
await delay(300);
|
|
275
|
+
await view.doRun();
|
|
276
|
+
expectDeepEqual(getFuncCallIO(view.funcCall), applyTransformations(fc1), {prefix: 'funcCall'});
|
|
277
|
+
expectDeepEqual(getFuncCallIO(view.lastCall!), applyTransformations(fc1), {prefix: 'lastCall'});
|
|
278
|
+
expectDeepEqual(inputsMap.data.value, inputValues.data, {prefix: 'data'});
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
category('Compute: RichFunctionView Validation', async () => {
|
|
283
|
+
before(async () => {
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test('Validate on start', async () => {
|
|
287
|
+
const view = new RichFunctionView('Compute:validationTest', {historyEnabled: false, isTabbed: false});
|
|
288
|
+
await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
|
|
289
|
+
await delay(1500);
|
|
290
|
+
const results = view.getValidationState();
|
|
291
|
+
expectDeepEqual(
|
|
292
|
+
results,
|
|
293
|
+
{
|
|
294
|
+
'a': {
|
|
295
|
+
'errors': [
|
|
296
|
+
{'description': 'Missing value'},
|
|
297
|
+
{'description': 'Out of range [1, 10] value: null'},
|
|
298
|
+
],
|
|
299
|
+
'warnings': [],
|
|
300
|
+
'notifications': [],
|
|
301
|
+
'revalidate': [],
|
|
302
|
+
'context': {},
|
|
303
|
+
},
|
|
304
|
+
'b': {
|
|
305
|
+
'errors': [
|
|
306
|
+
{'description': 'Missing value'},
|
|
307
|
+
{'description': 'Out of range [20, 100] value: null'},
|
|
308
|
+
],
|
|
309
|
+
'warnings': [],
|
|
310
|
+
'notifications': [],
|
|
311
|
+
'revalidate': [],
|
|
312
|
+
'context': {},
|
|
313
|
+
},
|
|
314
|
+
'x': {
|
|
315
|
+
'errors': [],
|
|
316
|
+
'warnings': [
|
|
317
|
+
{'description': 'Try non-null value'},
|
|
318
|
+
],
|
|
319
|
+
'notifications': [],
|
|
320
|
+
'revalidate': [],
|
|
321
|
+
'context': {},
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test('Validate on input', async () => {
|
|
328
|
+
const view = new RichFunctionView('Compute:validationTest', {historyEnabled: false, isTabbed: false});
|
|
329
|
+
const inputValues: Record<string, any> = {
|
|
330
|
+
a: 2.3,
|
|
331
|
+
b: 3.2,
|
|
332
|
+
x: -1,
|
|
333
|
+
};
|
|
334
|
+
const inputsMap: Record<string, InputVariants> = {};
|
|
335
|
+
view.afterInputPropertyRender.subscribe(({prop, input}) => {
|
|
336
|
+
inputsMap[prop.name] = input;
|
|
337
|
+
});
|
|
338
|
+
await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
|
|
339
|
+
await delay(1500);
|
|
340
|
+
for (const [name, input] of Object.entries(inputsMap)) {
|
|
341
|
+
input.value = inputValues[name];
|
|
342
|
+
const element = (input as any).input;
|
|
343
|
+
element.dispatchEvent(new Event('input', {bubbles: true}));
|
|
344
|
+
}
|
|
345
|
+
await delay(400);
|
|
346
|
+
|
|
347
|
+
const results = view.getValidationState();
|
|
348
|
+
expectDeepEqual(
|
|
349
|
+
results,
|
|
350
|
+
{
|
|
351
|
+
'b': {
|
|
352
|
+
'errors': [
|
|
353
|
+
{'description': 'Out of range [20, 100] value: 3.2'},
|
|
354
|
+
],
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
test('Revalidation sequence', async () => {
|
|
361
|
+
const view = new RichFunctionView('Compute:globalValidationTest', {historyEnabled: false, isTabbed: false});
|
|
362
|
+
const inputValues: Record<string, any> = {
|
|
363
|
+
a: 30,
|
|
364
|
+
b: 40,
|
|
365
|
+
c: 50,
|
|
366
|
+
};
|
|
367
|
+
const inputsMap: Record<string, InputVariants> = {};
|
|
368
|
+
view.afterInputPropertyRender.subscribe(({prop, input}) => {
|
|
369
|
+
inputsMap[prop.name] = input;
|
|
370
|
+
});
|
|
371
|
+
await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
|
|
372
|
+
await delay(1500);
|
|
373
|
+
for (const [name, input] of Object.entries(inputsMap)) {
|
|
374
|
+
input.value = inputValues[name];
|
|
375
|
+
const element = (input as any).input;
|
|
376
|
+
element.dispatchEvent(new Event('input', {bubbles: true}));
|
|
377
|
+
}
|
|
378
|
+
await delay(1000);
|
|
379
|
+
const results = view.getValidationState();
|
|
380
|
+
expectDeepEqual(
|
|
381
|
+
results,
|
|
382
|
+
{
|
|
383
|
+
'a': {
|
|
384
|
+
'revalidate': ['b', 'c'],
|
|
385
|
+
'context': {'isOk': false},
|
|
386
|
+
'warnings': [
|
|
387
|
+
{'description': 'Try lowering a value'},
|
|
388
|
+
],
|
|
389
|
+
},
|
|
390
|
+
'b': {
|
|
391
|
+
'warnings': [
|
|
392
|
+
{'description': 'Try lowering a value as well'},
|
|
393
|
+
],
|
|
394
|
+
},
|
|
395
|
+
'c': {
|
|
396
|
+
'warnings': [
|
|
397
|
+
{'description': 'Try lowering a value as well'},
|
|
398
|
+
],
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
);
|
|
402
|
+
});
|
|
403
|
+
});
|