2021-01-04 10:16:08 +00:00
import {
DataTreeAction ,
DataTreeWidget ,
ENTITY_TYPE ,
2021-04-26 05:41:32 +00:00
EvaluationSubstitutionType ,
2022-01-28 11:10:05 +00:00
} from "entities/DataTree/dataTreeFactory" ;
import { WidgetTypeConfigMap } from "utils/WidgetFactory" ;
import { RenderModes } from "constants/WidgetConstants" ;
import { PluginType } from "entities/Action" ;
2021-02-22 11:14:08 +00:00
import DataTreeEvaluator from "workers/DataTreeEvaluator" ;
2021-07-26 05:50:46 +00:00
import { ValidationTypes } from "constants/WidgetValidation" ;
2022-01-28 11:10:05 +00:00
import WidgetFactory from "utils/WidgetFactory" ;
import { generateDataTreeWidget } from "entities/DataTree/dataTreeWidget" ;
/ * *
* This function sorts the object ' s value which is array of string .
*
* @param { Record < string , Array < string > > } data
* @return { * }
* /
const sortObject = ( data : Record < string , Array < string > > ) = > {
Object . entries ( data ) . map ( ( [ key , value ] ) = > {
data [ key ] = value . sort ( ) ;
} ) ;
return data ;
} ;
2021-01-04 10:16:08 +00:00
const WIDGET_CONFIG_MAP : WidgetTypeConfigMap = {
CONTAINER_WIDGET : {
defaultProperties : { } ,
derivedProperties : { } ,
metaProperties : { } ,
} ,
TEXT_WIDGET : {
defaultProperties : { } ,
derivedProperties : {
value : "{{ this.text }}" ,
} ,
metaProperties : { } ,
} ,
BUTTON_WIDGET : {
defaultProperties : { } ,
derivedProperties : { } ,
metaProperties : { } ,
} ,
2022-01-18 07:52:24 +00:00
INPUT_WIDGET_V2 : {
2021-01-04 10:16:08 +00:00
defaultProperties : {
text : "defaultText" ,
} ,
derivedProperties : {
isValid :
'{{\n function(){\n let parsedRegex = null;\n if (this.regex) {\n /*\n * break up the regexp pattern into 4 parts: given regex, regex prefix , regex pattern, regex flags\n * Example /test/i will be split into ["/test/gi", "/", "test", "gi"]\n */\n const regexParts = this.regex.match(/(\\/?)(.+)\\1([a-z]*)/i);\n if (!regexParts) {\n parsedRegex = new RegExp(this.regex);\n } else {\n /*\n * if we don\'t have a regex flags (gmisuy), convert provided string into regexp directly\n /*\n if (regexParts[3] && !/^(?!.*?(.).*?\\1)[gmisuy]+$/.test(regexParts[3])) {\n parsedRegex = RegExp(this.regex);\n }\n /*\n * if we have a regex flags, use it to form regexp\n */\n parsedRegex = new RegExp(regexParts[2], regexParts[3]);\n }\n }\n if (this.inputType === "EMAIL") {\n const emailRegex = new RegExp(/^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$/);\n return emailRegex.test(this.text);\n }\n else if (this.inputType === "NUMBER") {\n return !isNaN(this.text)\n }\n else if (this.isRequired) {\n if(this.text && this.text.length) {\n if (parsedRegex) {\n return parsedRegex.test(this.text)\n } else {\n return true;\n }\n } else {\n return false;\n }\n } if (parsedRegex) {\n return parsedRegex.test(this.text)\n } else {\n return true;\n }\n }()\n }}' ,
value : "{{this.text}}" ,
} ,
metaProperties : {
isFocused : false ,
isDirty : false ,
} ,
} ,
CHECKBOX_WIDGET : {
defaultProperties : {
isChecked : "defaultCheckedState" ,
} ,
derivedProperties : {
value : "{{this.isChecked}}" ,
} ,
metaProperties : { } ,
} ,
DROP_DOWN_WIDGET : {
defaultProperties : {
selectedOptionValue : "defaultOptionValue" ,
selectedOptionValueArr : "defaultOptionValue" ,
} ,
derivedProperties : {
isValid :
"{{this.isRequired ? this.selectionType === 'SINGLE_SELECT' ? !!this.selectedOption : !!this.selectedIndexArr && this.selectedIndexArr.length > 0 : true}}" ,
selectedOption :
"{{ this.selectionType === 'SINGLE_SELECT' ? _.find(this.options, { value: this.selectedOptionValue }) : undefined}}" ,
selectedOptionArr :
'{{this.selectionType === "MULTI_SELECT" ? this.options.filter(opt => _.includes(this.selectedOptionValueArr, opt.value)) : undefined}}' ,
selectedIndex :
"{{ _.findIndex(this.options, { value: this.selectedOption.value } ) }}" ,
selectedIndexArr :
"{{ this.selectedOptionValueArr.map(o => _.findIndex(this.options, { value: o })) }}" ,
value :
"{{ this.selectionType === 'SINGLE_SELECT' ? this.selectedOptionValue : this.selectedOptionValueArr }}" ,
selectedOptionValues : "{{ this.selectedOptionValueArr }}" ,
} ,
metaProperties : { } ,
} ,
RADIO_GROUP_WIDGET : {
defaultProperties : {
selectedOptionValue : "defaultOptionValue" ,
} ,
derivedProperties : {
selectedOption :
"{{_.find(this.options, { value: this.selectedOptionValue })}}" ,
isValid : "{{ this.isRequired ? !!this.selectedOptionValue : true }}" ,
value : "{{this.selectedOptionValue}}" ,
} ,
metaProperties : { } ,
} ,
IMAGE_WIDGET : {
defaultProperties : { } ,
derivedProperties : { } ,
metaProperties : { } ,
} ,
TABLE_WIDGET : {
defaultProperties : {
searchText : "defaultSearchText" ,
selectedRowIndex : "defaultSelectedRow" ,
selectedRowIndices : "defaultSelectedRow" ,
} ,
derivedProperties : {
selectedRow : ` {{ _.get(this.filteredTableData, this.selectedRowIndex, _.mapValues(this.filteredTableData[0], () => undefined)) }} ` ,
selectedRows : ` {{ this.filteredTableData.filter((item, i) => selectedRowIndices.includes(i) }); }} ` ,
} ,
metaProperties : {
pageNo : 1 ,
selectedRow : { } ,
selectedRows : [ ] ,
} ,
} ,
VIDEO_WIDGET : {
defaultProperties : { } ,
derivedProperties : { } ,
metaProperties : {
playState : "NOT_STARTED" ,
} ,
} ,
FILE_PICKER_WIDGET : {
defaultProperties : { } ,
derivedProperties : {
isValid : "{{ this.isRequired ? this.files.length > 0 : true }}" ,
value : "{{this.files}}" ,
} ,
metaProperties : {
files : [ ] ,
uploadedFileData : { } ,
} ,
} ,
DATE_PICKER_WIDGET : {
defaultProperties : {
selectedDate : "defaultDate" ,
} ,
derivedProperties : {
isValid : "{{ this.isRequired ? !!this.selectedDate : true }}" ,
value : "{{ this.selectedDate }}" ,
} ,
metaProperties : { } ,
} ,
2021-02-23 12:35:09 +00:00
DATE_PICKER_WIDGET2 : {
defaultProperties : {
selectedDate : "defaultDate" ,
} ,
derivedProperties : {
isValid : "{{ this.isRequired ? !!this.selectedDate : true }}" ,
value : "{{ this.selectedDate }}" ,
} ,
metaProperties : { } ,
} ,
2021-01-04 10:16:08 +00:00
TABS_WIDGET : {
defaultProperties : { } ,
derivedProperties : {
selectedTab :
"{{_.find(this.tabs, { widgetId: this.selectedTabWidgetId }).label}}" ,
} ,
metaProperties : { } ,
} ,
MODAL_WIDGET : {
defaultProperties : { } ,
derivedProperties : { } ,
metaProperties : { } ,
} ,
RICH_TEXT_EDITOR_WIDGET : {
defaultProperties : {
text : "defaultText" ,
} ,
derivedProperties : {
value : "{{this.text}}" ,
} ,
metaProperties : { } ,
} ,
CHART_WIDGET : {
defaultProperties : { } ,
derivedProperties : { } ,
metaProperties : { } ,
} ,
FORM_WIDGET : {
defaultProperties : { } ,
derivedProperties : { } ,
metaProperties : { } ,
} ,
FORM_BUTTON_WIDGET : {
defaultProperties : { } ,
derivedProperties : { } ,
metaProperties : { } ,
} ,
MAP_WIDGET : {
defaultProperties : {
markers : "defaultMarkers" ,
center : "mapCenter" ,
} ,
derivedProperties : { } ,
metaProperties : { } ,
} ,
CANVAS_WIDGET : {
defaultProperties : { } ,
derivedProperties : { } ,
metaProperties : { } ,
} ,
ICON_WIDGET : {
defaultProperties : { } ,
derivedProperties : { } ,
metaProperties : { } ,
} ,
SKELETON_WIDGET : {
defaultProperties : { } ,
derivedProperties : { } ,
metaProperties : { } ,
} ,
} ;
const BASE_WIDGET : DataTreeWidget = {
2021-07-20 05:04:12 +00:00
logBlackList : { } ,
2021-01-04 10:16:08 +00:00
widgetId : "randomID" ,
2021-01-29 06:04:28 +00:00
widgetName : "randomWidgetName" ,
2021-01-04 10:16:08 +00:00
bottomRow : 0 ,
isLoading : false ,
leftColumn : 0 ,
parentColumnSpace : 0 ,
parentRowSpace : 0 ,
renderMode : RenderModes.CANVAS ,
rightColumn : 0 ,
topRow : 0 ,
2021-09-09 15:10:22 +00:00
type : "SKELETON_WIDGET" ,
2021-01-04 10:16:08 +00:00
parentId : "0" ,
2021-02-23 12:35:09 +00:00
version : 1 ,
2021-02-16 10:29:08 +00:00
bindingPaths : { } ,
triggerPaths : { } ,
2021-04-21 14:34:25 +00:00
validationPaths : { } ,
2021-01-04 10:16:08 +00:00
ENTITY_TYPE : ENTITY_TYPE.WIDGET ,
2022-01-28 11:10:05 +00:00
propertyOverrideDependency : { } ,
overridingPropertyPaths : { } ,
2022-01-21 12:08:40 +00:00
privateWidgets : { } ,
2021-01-04 10:16:08 +00:00
} ;
const BASE_ACTION : DataTreeAction = {
2021-12-02 10:03:43 +00:00
clear : { } ,
2021-07-20 05:04:12 +00:00
logBlackList : { } ,
2021-01-04 10:16:08 +00:00
actionId : "randomId" ,
2021-01-29 06:04:28 +00:00
name : "randomActionName" ,
2022-01-28 11:10:05 +00:00
datasourceUrl : "" ,
2021-01-04 10:16:08 +00:00
config : {
timeoutInMillisecond : 10 ,
} ,
dynamicBindingPathList : [ ] ,
isLoading : false ,
pluginType : PluginType.API ,
run : { } ,
data : { } ,
2021-05-14 06:51:09 +00:00
responseMeta : { isExecutionSuccess : false } ,
2021-01-04 10:16:08 +00:00
ENTITY_TYPE : ENTITY_TYPE.ACTION ,
2021-02-16 10:29:08 +00:00
bindingPaths : {
2021-04-26 05:41:32 +00:00
isLoading : EvaluationSubstitutionType.TEMPLATE ,
data : EvaluationSubstitutionType.TEMPLATE ,
2021-02-16 10:29:08 +00:00
} ,
2021-04-26 05:41:32 +00:00
dependencyMap : { } ,
2022-01-21 12:08:40 +00:00
datasourceUrl : "" ,
2021-01-04 10:16:08 +00:00
} ;
2022-01-28 11:10:05 +00:00
const metaMock = jest . spyOn ( WidgetFactory , "getWidgetMetaPropertiesMap" ) ;
const mockDefault = jest . spyOn ( WidgetFactory , "getWidgetDefaultPropertiesMap" ) ;
const mockDerived = jest . spyOn ( WidgetFactory , "getWidgetDerivedPropertiesMap" ) ;
const dependencyMap = {
Dropdown1 : [
"Dropdown1.defaultOptionValue" ,
"Dropdown1.isValid" ,
"Dropdown1.selectedIndex" ,
"Dropdown1.selectedIndexArr" ,
"Dropdown1.selectedOption" ,
"Dropdown1.selectedOptionArr" ,
"Dropdown1.selectedOptionValue" ,
"Dropdown1.selectedOptionValueArr" ,
"Dropdown1.selectedOptionValues" ,
"Dropdown1.value" ,
] ,
"Dropdown1.isValid" : [ ] ,
"Dropdown1.selectedIndex" : [ ] ,
"Dropdown1.selectedIndexArr" : [ ] ,
"Dropdown1.selectedOption" : [ ] ,
"Dropdown1.selectedOptionArr" : [ ] ,
"Dropdown1.selectedOptionValue" : [ "Dropdown1.defaultOptionValue" ] ,
"Dropdown1.selectedOptionValueArr" : [ "Dropdown1.defaultOptionValue" ] ,
"Dropdown1.selectedOptionValues" : [ ] ,
"Dropdown1.value" : [ ] ,
Table1 : [
"Table1.defaultSearchText" ,
"Table1.defaultSelectedRow" ,
"Table1.searchText" ,
"Table1.selectedRow" ,
"Table1.selectedRowIndex" ,
"Table1.selectedRowIndices" ,
"Table1.selectedRows" ,
"Table1.tableData" ,
] ,
"Table1.searchText" : [ "Table1.defaultSearchText" ] ,
"Table1.selectedRow" : [ ] ,
"Table1.selectedRowIndex" : [ "Table1.defaultSelectedRow" ] ,
"Table1.selectedRowIndices" : [ "Table1.defaultSelectedRow" ] ,
"Table1.selectedRows" : [ ] ,
"Table1.tableData" : [ "Text1.text" ] ,
Text1 : [ "Text1.text" , "Text1.value" ] ,
"Text1.value" : [ "Text1.text" ] ,
Text2 : [ "Text2.text" , "Text2.value" ] ,
"Text2.text" : [ "Text1.text" ] ,
"Text2.value" : [ "Text2.text" ] ,
Text3 : [ "Text3.text" , "Text3.value" ] ,
"Text3.value" : [ "Text3.text" ] ,
Text4 : [ "Text4.text" , "Text4.value" ] ,
"Text4.text" : [ "Table1.selectedRow" ] ,
"Text4.value" : [ ] ,
} ;
2021-01-04 10:16:08 +00:00
describe ( "DataTreeEvaluator" , ( ) = > {
2022-01-28 11:10:05 +00:00
metaMock . mockImplementation ( ( type ) = > {
return WIDGET_CONFIG_MAP [ type ] . metaProperties ;
} ) ;
mockDefault . mockImplementation ( ( type ) = > {
return WIDGET_CONFIG_MAP [ type ] . defaultProperties ;
} ) ;
mockDerived . mockImplementation ( ( type ) = > {
return WIDGET_CONFIG_MAP [ type ] . derivedProperties ;
} ) ;
const Input1 = generateDataTreeWidget (
{
2021-01-04 10:16:08 +00:00
. . . BASE_WIDGET ,
2022-01-28 11:10:05 +00:00
text : undefined ,
defaultText : "Default value" ,
widgetName : "Input1" ,
type : "INPUT_WIDGET_V2" ,
2021-02-16 10:29:08 +00:00
bindingPaths : {
2022-01-28 11:10:05 +00:00
defaultText : EvaluationSubstitutionType.TEMPLATE ,
isValid : EvaluationSubstitutionType.TEMPLATE ,
value : EvaluationSubstitutionType.TEMPLATE ,
2021-04-26 05:41:32 +00:00
text : EvaluationSubstitutionType.TEMPLATE ,
} ,
2021-01-04 10:16:08 +00:00
} ,
2022-01-28 11:10:05 +00:00
{ } ,
) ;
const unEvalTree : Record < string , DataTreeWidget > = {
Text1 : generateDataTreeWidget (
{
. . . BASE_WIDGET ,
widgetName : "Text1" ,
text : "Label" ,
type : "TEXT_WIDGET" ,
2021-02-16 10:29:08 +00:00
} ,
2022-01-28 11:10:05 +00:00
{ } ,
) ,
Text2 : generateDataTreeWidget (
{
. . . BASE_WIDGET ,
widgetName : "Text2" ,
text : "{{Text1.text}}" ,
dynamicBindingPathList : [ { key : "text" } ] ,
type : "TEXT_WIDGET" ,
2021-04-21 14:34:25 +00:00
} ,
2022-01-28 11:10:05 +00:00
{ } ,
) ,
Text3 : generateDataTreeWidget (
{
. . . BASE_WIDGET ,
widgetName : "Text3" ,
text : "{{Text1.text}}" ,
dynamicBindingPathList : [ { key : "text" } ] ,
type : "TEXT_WIDGET" ,
} ,
{ } ,
) ,
Dropdown1 : generateDataTreeWidget (
{
. . . BASE_WIDGET ,
options : [
{
label : "test" ,
value : "valueTest" ,
} ,
{
label : "test2" ,
value : "valueTest2" ,
} ,
] ,
type : "DROP_DOWN_WIDGET" ,
2021-02-16 10:29:08 +00:00
} ,
2022-01-28 11:10:05 +00:00
{ } ,
) ,
Table1 : generateDataTreeWidget (
{
. . . BASE_WIDGET ,
tableData :
"{{Api1.data.map(datum => ({ ...datum, raw: Text1.text }) )}}" ,
dynamicBindingPathList : [ { key : "tableData" } ] ,
type : "TABLE_WIDGET" ,
2021-04-21 14:34:25 +00:00
} ,
2022-01-28 11:10:05 +00:00
{ } ,
) ,
Text4 : generateDataTreeWidget (
{
. . . BASE_WIDGET ,
text : "{{Table1.selectedRow.test}}" ,
dynamicBindingPathList : [ { key : "text" } ] ,
type : "TEXT_WIDGET" ,
bindingPaths : {
text : EvaluationSubstitutionType.TEMPLATE ,
2021-01-04 10:16:08 +00:00
} ,
2022-01-28 11:10:05 +00:00
validationPaths : {
text : { type : ValidationTypes . TEXT } ,
2021-01-04 10:16:08 +00:00
} ,
2021-04-21 14:34:25 +00:00
} ,
2022-01-28 11:10:05 +00:00
{ } ,
) ,
2021-01-04 10:16:08 +00:00
} ;
const evaluator = new DataTreeEvaluator ( WIDGET_CONFIG_MAP ) ;
evaluator . createFirstTree ( unEvalTree ) ;
it ( "Evaluates a binding in first run" , ( ) = > {
const evaluation = evaluator . evalTree ;
const dependencyMap = evaluator . dependencyMap ;
expect ( evaluation ) . toHaveProperty ( "Text2.text" , "Label" ) ;
expect ( evaluation ) . toHaveProperty ( "Text3.text" , "Label" ) ;
2022-01-28 11:10:05 +00:00
expect ( sortObject ( dependencyMap ) ) . toStrictEqual ( dependencyMap ) ;
2021-01-04 10:16:08 +00:00
} ) ;
it ( "Evaluates a value change in update run" , ( ) = > {
const updatedUnEvalTree = {
. . . unEvalTree ,
Text1 : {
. . . unEvalTree . Text1 ,
text : "Hey there" ,
} ,
} ;
2021-07-20 05:04:12 +00:00
evaluator . updateDataTree ( updatedUnEvalTree ) ;
const dataTree = evaluator . evalTree ;
2021-06-04 07:09:36 +00:00
expect ( dataTree ) . toHaveProperty ( "Text2.text" , "Hey there" ) ;
expect ( dataTree ) . toHaveProperty ( "Text3.text" , "Hey there" ) ;
2021-01-04 10:16:08 +00:00
} ) ;
it ( "Evaluates a dependency change in update run" , ( ) = > {
const updatedUnEvalTree = {
. . . unEvalTree ,
Text3 : {
. . . unEvalTree . Text3 ,
text : "Label 3" ,
} ,
} ;
2021-07-20 05:04:12 +00:00
evaluator . updateDataTree ( updatedUnEvalTree ) ;
const dataTree = evaluator . evalTree ;
2021-01-04 10:16:08 +00:00
const updatedDependencyMap = evaluator . dependencyMap ;
2021-06-04 07:09:36 +00:00
expect ( dataTree ) . toHaveProperty ( "Text2.text" , "Label" ) ;
expect ( dataTree ) . toHaveProperty ( "Text3.text" , "Label 3" ) ;
2022-01-28 11:10:05 +00:00
expect ( sortObject ( updatedDependencyMap ) ) . toStrictEqual ( dependencyMap ) ;
2021-01-04 10:16:08 +00:00
} ) ;
it ( "Overrides with default value" , ( ) = > {
const updatedUnEvalTree = {
. . . unEvalTree ,
2022-01-28 11:10:05 +00:00
Input1 ,
2021-01-04 10:16:08 +00:00
} ;
2021-07-20 05:04:12 +00:00
evaluator . updateDataTree ( updatedUnEvalTree ) ;
const dataTree = evaluator . evalTree ;
2021-06-04 07:09:36 +00:00
expect ( dataTree ) . toHaveProperty ( "Input1.text" , "Default value" ) ;
2021-01-04 10:16:08 +00:00
} ) ;
it ( "Evaluates for value changes in nested diff paths" , ( ) = > {
const updatedUnEvalTree = {
. . . unEvalTree ,
2021-02-16 10:29:08 +00:00
Dropdown2 : {
2021-01-04 10:16:08 +00:00
. . . BASE_WIDGET ,
options : [
{
label : "newValue" ,
value : "valueTest" ,
} ,
{
label : "test2" ,
value : "valueTest2" ,
} ,
] ,
2021-09-09 15:10:22 +00:00
type : "DROP_DOWN_WIDGET" ,
2021-02-16 10:29:08 +00:00
bindingPaths : {
2021-04-26 05:41:32 +00:00
options : EvaluationSubstitutionType.TEMPLATE ,
defaultOptionValue : EvaluationSubstitutionType.TEMPLATE ,
isRequired : EvaluationSubstitutionType.TEMPLATE ,
isVisible : EvaluationSubstitutionType.TEMPLATE ,
isDisabled : EvaluationSubstitutionType.TEMPLATE ,
isValid : EvaluationSubstitutionType.TEMPLATE ,
selectedOption : EvaluationSubstitutionType.TEMPLATE ,
selectedOptionArr : EvaluationSubstitutionType.TEMPLATE ,
selectedIndex : EvaluationSubstitutionType.TEMPLATE ,
selectedIndexArr : EvaluationSubstitutionType.TEMPLATE ,
value : EvaluationSubstitutionType.TEMPLATE ,
selectedOptionValues : EvaluationSubstitutionType.TEMPLATE ,
2021-02-16 10:29:08 +00:00
} ,
2021-01-04 10:16:08 +00:00
} ,
} ;
2021-07-20 05:04:12 +00:00
evaluator . updateDataTree ( updatedUnEvalTree ) ;
const dataTree = evaluator . evalTree ;
2021-06-04 07:09:36 +00:00
expect ( dataTree ) . toHaveProperty ( "Dropdown2.options.0.label" , "newValue" ) ;
2021-01-04 10:16:08 +00:00
} ) ;
it ( "Adds an entity with a complicated binding" , ( ) = > {
const updatedUnEvalTree = {
. . . unEvalTree ,
Api1 : {
. . . BASE_ACTION ,
2021-01-29 06:04:28 +00:00
name : "Api1" ,
2021-01-04 10:16:08 +00:00
data : [
{
test : "Hey" ,
} ,
{
test : "Ho" ,
} ,
] ,
} ,
} ;
2021-07-20 05:04:12 +00:00
evaluator . updateDataTree ( updatedUnEvalTree ) ;
const dataTree = evaluator . evalTree ;
2021-01-04 10:16:08 +00:00
const updatedDependencyMap = evaluator . dependencyMap ;
2021-06-04 07:09:36 +00:00
expect ( dataTree ) . toHaveProperty ( "Table1.tableData" , [
2021-01-04 10:16:08 +00:00
{
test : "Hey" ,
raw : "Label" ,
} ,
{
test : "Ho" ,
raw : "Label" ,
} ,
] ) ;
2022-01-28 11:10:05 +00:00
expect ( sortObject ( updatedDependencyMap ) ) . toStrictEqual ( {
2021-01-04 10:16:08 +00:00
Api1 : [ "Api1.data" ] ,
2022-01-28 11:10:05 +00:00
. . . dependencyMap ,
2021-01-04 10:16:08 +00:00
"Table1.tableData" : [ "Api1.data" , "Text1.text" ] ,
2022-01-28 11:10:05 +00:00
"Text3.text" : [ "Text1.text" ] ,
2021-01-04 10:16:08 +00:00
} ) ;
} ) ;
it ( "Selects a row" , ( ) = > {
const updatedUnEvalTree = {
. . . unEvalTree ,
Table1 : {
. . . unEvalTree . Table1 ,
selectedRowIndex : 0 ,
selectedRow : {
test : "Hey" ,
raw : "Label" ,
} ,
} ,
Api1 : {
. . . BASE_ACTION ,
2021-01-29 06:04:28 +00:00
name : "Api1" ,
2021-01-04 10:16:08 +00:00
data : [
{
test : "Hey" ,
} ,
{
test : "Ho" ,
} ,
] ,
} ,
} ;
2021-07-20 05:04:12 +00:00
evaluator . updateDataTree ( updatedUnEvalTree ) ;
const dataTree = evaluator . evalTree ;
2021-01-04 10:16:08 +00:00
const updatedDependencyMap = evaluator . dependencyMap ;
2021-06-04 07:09:36 +00:00
expect ( dataTree ) . toHaveProperty ( "Table1.tableData" , [
2021-01-04 10:16:08 +00:00
{
test : "Hey" ,
raw : "Label" ,
} ,
{
test : "Ho" ,
raw : "Label" ,
} ,
] ) ;
2021-06-04 07:09:36 +00:00
expect ( dataTree ) . toHaveProperty ( "Text4.text" , "Hey" ) ;
2022-01-28 11:10:05 +00:00
expect ( sortObject ( updatedDependencyMap ) ) . toStrictEqual ( {
2021-01-04 10:16:08 +00:00
Api1 : [ "Api1.data" ] ,
2022-01-28 11:10:05 +00:00
. . . dependencyMap ,
2021-01-04 10:16:08 +00:00
"Table1.tableData" : [ "Api1.data" , "Text1.text" ] ,
2022-01-28 11:10:05 +00:00
"Text3.text" : [ "Text1.text" ] ,
2021-01-04 10:16:08 +00:00
} ) ;
} ) ;
2021-04-26 05:41:32 +00:00
it ( "Honors predefined action dependencyMap" , ( ) = > {
const updatedTree1 = {
. . . unEvalTree ,
Text1 : {
. . . BASE_WIDGET ,
text : "Test" ,
} ,
Api2 : {
. . . BASE_ACTION ,
dependencyMap : {
"config.body" : [ "config.pluginSpecifiedTemplates[0].value" ] ,
} ,
bindingPaths : {
. . . BASE_ACTION . bindingPaths ,
"config.body" : EvaluationSubstitutionType . TEMPLATE ,
} ,
config : {
. . . BASE_ACTION . config ,
body : "" ,
pluginSpecifiedTemplates : [
{
value : false ,
} ,
] ,
} ,
} ,
} ;
evaluator . updateDataTree ( updatedTree1 ) ;
expect ( evaluator . dependencyMap [ "Api2.config.body" ] ) . toStrictEqual ( [
2021-11-10 14:43:21 +00:00
"Api2.config.pluginSpecifiedTemplates[0].value" ,
2021-04-26 05:41:32 +00:00
] ) ;
const updatedTree2 = {
. . . updatedTree1 ,
Api2 : {
. . . updatedTree1 . Api2 ,
dynamicBindingPathList : [
{
key : "config.body" ,
} ,
] ,
config : {
. . . updatedTree1 . Api2 . config ,
body : "{ 'name': {{ Text1.text }} }" ,
} ,
} ,
} ;
2021-07-20 05:04:12 +00:00
evaluator . updateDataTree ( updatedTree2 ) ;
const dataTree = evaluator . evalTree ;
2021-04-26 05:41:32 +00:00
expect ( evaluator . dependencyMap [ "Api2.config.body" ] ) . toStrictEqual ( [
"Text1.text" ,
2021-11-10 14:43:21 +00:00
"Api2.config.pluginSpecifiedTemplates[0].value" ,
2021-04-26 05:41:32 +00:00
] ) ;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
2021-06-04 07:09:36 +00:00
expect ( dataTree . Api2 . config . body ) . toBe ( "{ 'name': Test }" ) ;
2021-04-26 05:41:32 +00:00
const updatedTree3 = {
. . . updatedTree2 ,
Api2 : {
. . . updatedTree2 . Api2 ,
bindingPaths : {
. . . updatedTree2 . Api2 . bindingPaths ,
"config.body" : EvaluationSubstitutionType . SMART_SUBSTITUTE ,
} ,
config : {
. . . updatedTree2 . Api2 . config ,
pluginSpecifiedTemplates : [
{
value : true ,
} ,
] ,
} ,
} ,
} ;
2021-07-20 05:04:12 +00:00
evaluator . updateDataTree ( updatedTree3 ) ;
const dataTree3 = evaluator . evalTree ;
2021-04-26 05:41:32 +00:00
expect ( evaluator . dependencyMap [ "Api2.config.body" ] ) . toStrictEqual ( [
"Text1.text" ,
2021-11-10 14:43:21 +00:00
"Api2.config.pluginSpecifiedTemplates[0].value" ,
2021-04-26 05:41:32 +00:00
] ) ;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
2021-06-04 07:09:36 +00:00
expect ( dataTree3 . Api2 . config . body ) . toBe ( "{ 'name': \"Test\" }" ) ;
2021-04-26 05:41:32 +00:00
} ) ;
2021-01-04 10:16:08 +00:00
} ) ;