PromucFlow_constructor/app/client/src/workers/evaluationUtils.test.ts

767 lines
20 KiB
TypeScript
Raw Normal View History

import {
DependencyMap,
EVAL_ERROR_PATH,
PropertyEvaluationErrorType,
} from "utils/DynamicBindingUtils";
import { RenderModes } from "constants/WidgetConstants";
import { ValidationTypes } from "constants/WidgetValidation";
import {
DataTreeEntity,
DataTreeWidget,
ENTITY_TYPE,
EvaluationSubstitutionType,
PrivateWidgets,
} from "entities/DataTree/dataTreeFactory";
import {
DataTreeDiff,
DataTreeDiffEvent,
getAllPaths,
getAllPrivateWidgetsInDataTree,
getDataTreeWithoutPrivateWidgets,
isPrivateEntityPath,
makeParentsDependOnChildren,
removeLintErrorsFromEntityProperty,
translateDiffEventToDataTreeDiffEvent,
} from "./evaluationUtils";
import { warn as logWarn } from "loglevel";
import { Diff } from "deep-diff";
import _, { get, flatten } from "lodash";
import { overrideWidgetProperties } from "./evaluationUtils";
import { DataTree } from "entities/DataTree/dataTreeFactory";
import { EvalMetaUpdates } from "./DataTreeEvaluator/types";
import { generateDataTreeWidget } from "entities/DataTree/dataTreeWidget";
import TableWidget, { CONFIG as TableWidgetConfig } from "widgets/TableWidget";
import InputWidget, {
CONFIG as InputWidgetV2Config,
} from "widgets/InputWidgetV2";
import { registerWidget } from "utils/WidgetRegisterHelpers";
import { Severity } from "entities/AppsmithConsole";
// to check if logWarn was called.
// use jest.unmock, if the mock needs to be removed.
jest.mock("loglevel");
const BASE_WIDGET: DataTreeWidget = {
logBlackList: {},
widgetId: "randomID",
widgetName: "randomWidgetName",
bottomRow: 0,
isLoading: false,
leftColumn: 0,
parentColumnSpace: 0,
parentRowSpace: 0,
renderMode: RenderModes.CANVAS,
rightColumn: 0,
topRow: 0,
type: "SKELETON_WIDGET",
parentId: "0",
version: 1,
bindingPaths: {},
reactivePaths: {},
triggerPaths: {},
validationPaths: {},
ENTITY_TYPE: ENTITY_TYPE.WIDGET,
privateWidgets: {},
propertyOverrideDependency: {},
overridingPropertyPaths: {},
meta: {},
};
const testDataTree: Record<string, DataTreeWidget> = {
Text1: {
...BASE_WIDGET,
widgetName: "Text1",
text: "Label",
type: "TEXT_WIDGET",
reactivePaths: {
text: EvaluationSubstitutionType.TEMPLATE,
},
validationPaths: {
text: { type: ValidationTypes.TEXT },
},
},
Text2: {
...BASE_WIDGET,
widgetName: "Text2",
text: "{{Text1.text}}",
dynamicBindingPathList: [{ key: "text" }],
type: "TEXT_WIDGET",
reactivePaths: {
text: EvaluationSubstitutionType.TEMPLATE,
},
validationPaths: {
text: { type: ValidationTypes.TEXT },
},
},
Text3: {
...BASE_WIDGET,
widgetName: "Text3",
text: "{{Text1.text}}",
dynamicBindingPathList: [{ key: "text" }],
type: "TEXT_WIDGET",
reactivePaths: {
text: EvaluationSubstitutionType.TEMPLATE,
},
validationPaths: {
text: { type: ValidationTypes.TEXT },
},
},
Text4: {
...BASE_WIDGET,
widgetName: "Text4",
text: "{{Text1.text}}",
dynamicBindingPathList: [{ key: "text" }],
type: "TEXT_WIDGET",
reactivePaths: {
text: EvaluationSubstitutionType.TEMPLATE,
},
validationPaths: {
text: { type: ValidationTypes.TEXT },
},
},
List1: {
...BASE_WIDGET,
privateWidgets: {
Text2: true,
},
},
List2: {
...BASE_WIDGET,
privateWidgets: {
Text3: true,
},
},
Button1: {
...BASE_WIDGET,
text: "undefined",
__evaluation__: {
errors: {
text: [
{
errorType: PropertyEvaluationErrorType.LINT,
raw:
" function closedFunction () { const result = Api24 return result; } closedFunction.call(THIS_CONTEXT) ",
severity: Severity.ERROR,
errorMessage: "'Api24' is not defined.",
errorSegment: " const result = Api24",
originalBinding: "Api24",
},
],
},
},
},
};
2021-01-29 17:59:23 +00:00
describe("Correctly handle paths", () => {
2021-01-29 17:59:23 +00:00
it("getsAllPaths", () => {
const myTree = {
WidgetName: {
1: "yo",
name: "WidgetName",
objectProperty: {
childObjectProperty: [
"1",
1,
{
key: "value",
2: 1,
},
["1", "2"],
],
},
},
};
const result = {
WidgetName: true,
"WidgetName.1": true,
"WidgetName.name": true,
"WidgetName.objectProperty": true,
"WidgetName.objectProperty.childObjectProperty": true,
"WidgetName.objectProperty.childObjectProperty[0]": true,
"WidgetName.objectProperty.childObjectProperty[1]": true,
"WidgetName.objectProperty.childObjectProperty[2]": true,
"WidgetName.objectProperty.childObjectProperty[2].key": true,
"WidgetName.objectProperty.childObjectProperty[2].2": true,
"WidgetName.objectProperty.childObjectProperty[3]": true,
"WidgetName.objectProperty.childObjectProperty[3][0]": true,
"WidgetName.objectProperty.childObjectProperty[3][1]": true,
};
const actual = getAllPaths(myTree);
expect(actual).toStrictEqual(result);
});
});
describe("privateWidgets", () => {
it("correctly checks if path is a PrivateEntityPath", () => {
const privateWidgets: PrivateWidgets = {
Button1: true,
Image1: true,
Button2: true,
Image2: true,
};
expect(
isPrivateEntityPath(privateWidgets, "List1.template.Button1.text"),
).toBeFalsy();
expect(isPrivateEntityPath(privateWidgets, "Button1.text")).toBeTruthy();
expect(
isPrivateEntityPath(privateWidgets, "List2.template.Image2.data"),
).toBeFalsy();
expect(isPrivateEntityPath(privateWidgets, "Image2.data")).toBeTruthy();
});
it("Returns list of all privateWidgets", () => {
const expectedPrivateWidgetsList = {
Text2: true,
Text3: true,
};
const actualPrivateWidgetsList = getAllPrivateWidgetsInDataTree(
testDataTree,
);
expect(expectedPrivateWidgetsList).toStrictEqual(actualPrivateWidgetsList);
});
it("Returns data tree without privateWidgets", () => {
const expectedDataTreeWithoutPrivateWidgets: Record<
string,
DataTreeWidget
> = {
Text1: {
...BASE_WIDGET,
widgetName: "Text1",
text: "Label",
type: "TEXT_WIDGET",
reactivePaths: {
text: EvaluationSubstitutionType.TEMPLATE,
},
validationPaths: {
text: { type: ValidationTypes.TEXT },
},
},
Text4: {
...BASE_WIDGET,
widgetName: "Text4",
text: "{{Text1.text}}",
dynamicBindingPathList: [{ key: "text" }],
type: "TEXT_WIDGET",
reactivePaths: {
text: EvaluationSubstitutionType.TEMPLATE,
},
validationPaths: {
text: { type: ValidationTypes.TEXT },
},
},
List1: {
...BASE_WIDGET,
privateWidgets: {
Text2: true,
},
},
List2: {
...BASE_WIDGET,
privateWidgets: {
Text3: true,
},
},
Button1: {
...BASE_WIDGET,
text: "undefined",
__evaluation__: {
errors: {
text: [
{
errorType: PropertyEvaluationErrorType.LINT,
raw:
" function closedFunction () { const result = Api24 return result; } closedFunction.call(THIS_CONTEXT) ",
severity: Severity.ERROR,
errorMessage: "'Api24' is not defined.",
errorSegment: " const result = Api24",
originalBinding: "Api24",
},
],
},
},
},
};
const actualDataTreeWithoutPrivateWidgets = getDataTreeWithoutPrivateWidgets(
testDataTree,
);
expect(expectedDataTreeWithoutPrivateWidgets).toStrictEqual(
actualDataTreeWithoutPrivateWidgets,
);
});
2021-01-29 17:59:23 +00:00
});
describe("makeParentsDependOnChildren", () => {
it("makes parent properties depend on child properties", () => {
let depMap: DependencyMap = {
Widget1: [],
"Widget1.defaultText": [],
"Widget1.defaultText.abc": [],
};
const allkeys: Record<string, true> = {
Widget1: true,
"Widget1.defaultText": true,
"Widget1.defaultText.abc": true,
};
depMap = makeParentsDependOnChildren(depMap, allkeys);
expect(depMap).toStrictEqual({
Widget1: ["Widget1.defaultText"],
"Widget1.defaultText": ["Widget1.defaultText.abc"],
"Widget1.defaultText.abc": [],
});
});
it("logs warning for child properties not listed in allKeys", () => {
const depMap: DependencyMap = {
Widget1: [],
"Widget1.defaultText": [],
};
const allkeys: Record<string, true> = {
Widget1: true,
};
makeParentsDependOnChildren(depMap, allkeys);
expect(logWarn).toBeCalledWith(
"makeParentsDependOnChild - Widget1.defaultText is not present in dataTree.",
"This might result in a cyclic dependency.",
);
});
});
describe("translateDiffEvent", () => {
it("noop when diff path does not exist", () => {
const noDiffPath: Diff<any, any> = {
kind: "E",
lhs: undefined,
rhs: undefined,
};
const result = translateDiffEventToDataTreeDiffEvent(noDiffPath, {});
expect(result).toStrictEqual({
payload: {
propertyPath: "",
value: "",
},
event: DataTreeDiffEvent.NOOP,
});
});
it("translates new and delete events", () => {
const diffs: Diff<any, any>[] = [
{
kind: "N",
path: ["Widget1"],
rhs: {},
},
{
kind: "N",
path: ["Widget1", "name"],
rhs: "Widget1",
},
{
kind: "D",
path: ["Widget1"],
lhs: {},
},
{
kind: "D",
path: ["Widget1", "name"],
lhs: "Widget1",
},
{
kind: "E",
path: ["Widget2", "name"],
rhs: "test",
lhs: "test2",
},
];
const expectedTranslations: DataTreeDiff[] = [
{
payload: {
propertyPath: "Widget1",
},
event: DataTreeDiffEvent.NEW,
},
{
payload: {
propertyPath: "Widget1.name",
},
event: DataTreeDiffEvent.NEW,
},
{
payload: {
propertyPath: "Widget1",
},
event: DataTreeDiffEvent.DELETE,
},
{
payload: {
propertyPath: "Widget1.name",
},
event: DataTreeDiffEvent.DELETE,
},
{
payload: {
propertyPath: "",
value: "",
},
event: DataTreeDiffEvent.NOOP,
},
];
const actualTranslations = flatten(
diffs.map((diff) => translateDiffEventToDataTreeDiffEvent(diff, {})),
);
expect(expectedTranslations).toStrictEqual(actualTranslations);
});
it("properly categorises the edit events", () => {
const diffs: Diff<any, any>[] = [
{
kind: "E",
path: ["Widget2", "name"],
rhs: "test",
lhs: "test2",
},
];
const expectedTranslations: DataTreeDiff[] = [
{
payload: {
propertyPath: "",
value: "",
},
event: DataTreeDiffEvent.NOOP,
},
];
const actualTranslations = flatten(
diffs.map((diff) => translateDiffEventToDataTreeDiffEvent(diff, {})),
);
expect(expectedTranslations).toStrictEqual(actualTranslations);
});
it("handles JsObject function renaming", () => {
// cyclic dependency case
const lhs = new String("() => {}");
_.set(lhs, "data", {});
const diffs: Diff<any, any>[] = [
{
kind: "E",
path: ["JsObject", "myFun1"],
rhs: "() => {}",
lhs,
},
];
const expectedTranslations: DataTreeDiff[] = [
{
event: DataTreeDiffEvent.DELETE,
payload: {
propertyPath: "JsObject.myFun1.data",
},
},
{
event: DataTreeDiffEvent.EDIT,
payload: {
propertyPath: "JsObject.myFun1",
value: "() => {}",
},
},
];
const actualTranslations = flatten(
diffs.map((diff) =>
translateDiffEventToDataTreeDiffEvent(diff, {
JsObject: ({
ENTITY_TYPE: ENTITY_TYPE.JSACTION,
} as unknown) as DataTreeEntity,
}),
),
);
expect(expectedTranslations).toStrictEqual(actualTranslations);
});
it("lists array accessors when object is replaced by an array", () => {
const diffs: Diff<any, any>[] = [
{
kind: "E",
path: ["Api1", "data"],
lhs: {},
rhs: [{ id: 1 }, { id: 2 }],
},
];
const expectedTranslations: DataTreeDiff[] = [
{
payload: {
propertyPath: "Api1.data[0]",
},
event: DataTreeDiffEvent.NEW,
},
{
payload: {
propertyPath: "Api1.data[1]",
},
event: DataTreeDiffEvent.NEW,
},
];
const actualTranslations = flatten(
diffs.map((diff) => translateDiffEventToDataTreeDiffEvent(diff, {})),
);
expect(expectedTranslations).toStrictEqual(actualTranslations);
});
it("lists array accessors when array is replaced by an object", () => {
const diffs: Diff<any, any>[] = [
{
kind: "E",
path: ["Api1", "data"],
lhs: [{ id: 1 }, { id: 2 }],
rhs: {},
},
];
const expectedTranslations: DataTreeDiff[] = [
{
payload: {
propertyPath: "Api1.data[0]",
},
event: DataTreeDiffEvent.DELETE,
},
{
payload: {
propertyPath: "Api1.data[1]",
},
event: DataTreeDiffEvent.DELETE,
},
];
const actualTranslations = flatten(
diffs.map((diff) => translateDiffEventToDataTreeDiffEvent(diff, {})),
);
expect(expectedTranslations).toStrictEqual(actualTranslations);
});
feat: Simplified Google Sheets queries (#14869) * Client changes 1 * add DSL functionality * Temp commit for refactoring changes * Do I even know what I'm doing here? * chore: Second GS layout * Update: Visibility conditional outputs for schemas - Added the output from conditional outputs for schema children too * Update: Entity selector visibility control - Added logic for controlling visibility of sub components via the JS expressions system * Update: Passing disabled prop to toggle button * Update: Passing disabled prop to toggle btn * Update: Styled component for toggle button - Added disabled styles based on the disabled prop sent to the toggle form view JSON button * Update: configProperty role in Entity Selector - Removed dependance of the configProperty of the entity selector children to it's parent component * Update: type of placeholder key - Made placeholder key from form config JSON to accept either string or an object - Earlier only string was accepted - This is for pagination component * Update: Added placeholder control for pagination * Client changes 1 * add DSL functionality * Do I even know what I'm doing here? * fix: updated uqi forms ui, clubbed JS switch button to ads, updated tooltip design * fix: updated tooltip component for wrong ui on entity explore * temp triggers * fix: updated uqi forms ui, clubbed JS switch button to ads, updated tooltip design (#12395) * fix: updated uqi forms ui, clubbed JS switch button to ads, updated tooltip design * fix: updated tooltip component for wrong ui on entity explore * fix: updated tooltip ui, where condition placement, sort by ui * temp form data access logic * fix: updated sorting type width ui * fix: updated ui for spacing, width and text issues * Update: Type for tooltip of UQI forms - Added option to send an object to the tooltipText object. - This allows for composite components like pagination to have tooltips for each sub component * Update: tooltip for pagination component - Added handling to parse the tooltip for multiple components. - This allows for composite components like pagination to have tooltips for each sub component * Update: Type cast for tooltip component - Made the content passed to tooltip component as a string only * Update: Fixed tooltip component CSS * Update: Dropdown option component - Added a tooltip wrapper to each option - This is to show on hover text like disabled state * fix: updated ẇhere clause broken ui for condition * Add: functions to check and extract expressions - Loop through the formConfig and find any keys that have a value that is bindable - Used pre defined regex to check if value is a moustache binding * Add: Types for evaluated form configs - Added types for the form configs to be evaluated and their output post eval * Add: Flow to run the form config - Run the form config and update the result to the redux state * Update: Name of the type for formconfigs - Updated since it was clashing with a component of the same name * Add: Function to enforce config type checks - This is done so that the improper configs can be weeded out and the rest of the form can be shown * Add: Function to update evaluated config - Added option to update the config if it's values needed evaluation * Add: Type check for schema sections * Update: Error handling for invalid control type - We were throwing an exception till now, changed it to a warning text * Add: Exposed tooltip for dropdown option disabled state * Update: switch to json mode functionality - Added logic to convert data to a string rather than an object when the first switch to JSON mode happens * Update: Added key to tooltip for dropdown options * Trigger API modification * Add: function to fetch default trigger URL * Update: Made URL optional in dynamic trigger config * Update: Dynamic trigger API call - Made the API call for dynamic triggers have URL as optional field - Added type check to the response of the API call * Update: resp type for trigger APIs * Update: Moved code to utils folder - Moved functions for UQI form eval processing to utils file * Update: passing original controltype to JS switch * Update: config for JSON editor mode - Updated the config to have different options for JSON mode depending on the original control type * Update: Connected line numbers flag to config * Revert: CSS changes for tooltip * Refactor: Removed consle * Add: type for the config of dynamic values * Add: Feature to evaluate config for triggers * Refactor: fix type check errors * fix: dropdown ui width with text alignment * Update: fixed selector for dynamic values * Update: selector call for fetchDynamicValues * Add table header index prop for columns selector * migration partial commit * migration partial commit * Refactor: removed unused import * Update: reused function for checking dynamic value * Update: removed unused import * Fix format JSON issues * Retrieve binding paths from entity selector components * Fixes 6 remaining issues with UQI implementation * Fix dropdown issues * Fix dropdown height issues and fixes triggering of APIs when option is deselected * Migration changes * Fix QA generated UQI issues * Fix projection component height and route change logic * Fix multi select dropdown placeholder text issue and json stringify issue with switching view types * Reset entity type value when command value changes * Test changes * Review comments * Moved migrations around * Corrected import statement * Added JSON schema migration * Updated schema version * perf improvements and filter dropdown options feature * Fix Code mirror component config for toggleComponentToJson input fields. * Fix prettier issues * fix prettier issues * Fix style issues as a result of the merged conflicts * Fix failing test case * Fixed a few other flows (#14225) * Fixed a few other flows * Review comments * Fix generate CRUD, fix evaluation of dynamic bindings and fix various styling issues. * More fixes (#14367) * Factor in the root formconfig parent key. * Fix flickering issues, and evaluatedFormConfig issues * fix: Teeny bugs (#14455) * Teeny bugs * Added previous functionality as is * Improvements in the way we fetch dynamic values * Fix stringiification issue and cyclic dependency issues * Resolve projection component values deletion * Resolve merge conflicts and fix prettier issues * fix: Tsc issues * Fix property pane connection navigation * updating ee locator * updating inputfield locator * dropdown locator update * Merge conflict not properly resolved. * Fix s3 spec * Fix Mongo Spec * Fix some more tests * fix: prevent cyclic dependency when switching to js mode (#14668) * add delete events for change from array to string in diff * add test to assert absence of cyclic dependency error when switching to js in switchgroup widget * Assert that evaluation is not disabled when no cyclic dependency happens * Cypress test preparations for google sheets and form controls * Fixed a few test errors (#14874) * Add: unit tests for uqi UI updates - view type tests - conditional output extraction - processing conditional output to handle view/enabled state of the component * Add: completed isValidFormConfig test * Update: improved tests for update config - These tests cover the functionality to update a section config after it's components are done evaluating * Fix failing cypress tests and cyclic dependency issue * Fixes some more tests * Fixed migration of row objects (#14896) * Bumped the version of design system package * Update: reverted change to EE selector * Fix deletion pointer * Update: selector for js on load spec - Synced with changes related to ADS dropdown * Fix mongoDBShoppingCart spec * Remove comments * Fix: mongo shopping cart test failures * fix: mongo shopping cart spec * Dummy push to retrigger vercel * fix: mongo shopping cart spec * Update MongoDBShoppingCart_spec.js * fix: removed unused click away * dummy commit * Update: moved helper functions to separate file * Add: added tests for saga functions - Worked on testing for - extractFetchDynamicValueFormConfigs - extractQueueOfValuesToBeFetched * Add if check for queueOfValuesToBeFetched * Resolve review comments * Empty-Commit Co-authored-by: Irongade <adeoluayangade@yahoo.com> Co-authored-by: Ayush Pahwa <ayush@appsmith.com> Co-authored-by: Aman Agarwal <aman@appsmith.com> Co-authored-by: Ayangade Adeoluwa <37867493+Irongade@users.noreply.github.com> Co-authored-by: Aishwarya UR <aishwarya@appsmith.com> Co-authored-by: Favour Ohanekwu <fohanekwu@gmail.com> Co-authored-by: Albin <albin@appsmith.com>
2022-07-04 05:43:27 +00:00
it("deletes member expressions when Array changes to string", () => {
const diffs: Diff<any, any>[] = [
{
kind: "E",
path: ["Api1", "data"],
lhs: [{ id: "{{a}}" }, { id: "{{a}}" }],
rhs: `{ id: "{{a}}" }, { id: "{{a}}" }`,
},
];
const expectedTranslations: DataTreeDiff[] = [
{
payload: {
propertyPath: "Api1.data",
value: `{ id: "{{a}}" }, { id: "{{a}}" }`,
},
event: DataTreeDiffEvent.EDIT,
},
{
payload: {
propertyPath: "Api1.data[0]",
},
event: DataTreeDiffEvent.DELETE,
},
{
payload: {
propertyPath: "Api1.data[1]",
},
event: DataTreeDiffEvent.DELETE,
},
];
const actualTranslations = flatten(
diffs.map((diff) => translateDiffEventToDataTreeDiffEvent(diff, {})),
);
expect(expectedTranslations).toEqual(actualTranslations);
});
});
describe("overrideWidgetProperties", () => {
beforeAll(() => {
registerWidget(TableWidget, TableWidgetConfig);
registerWidget(InputWidget, InputWidgetV2Config);
});
describe("1. Input widget ", () => {
const currentTree: DataTree = {};
beforeAll(() => {
const inputWidgetDataTree = generateDataTreeWidget(
{
type: InputWidget.getWidgetType(),
widgetId: "egwwwfgab",
widgetName: "Input1",
children: [],
bottomRow: 0,
isLoading: false,
parentColumnSpace: 0,
parentRowSpace: 0,
version: 1,
leftColumn: 0,
renderMode: RenderModes.CANVAS,
rightColumn: 0,
topRow: 0,
},
{},
);
currentTree["Input1"] = inputWidgetDataTree;
});
// When default text is re-evaluated it will override values of meta.text and text in InputWidget
it("1. defaultText updating meta.text and text", () => {
const evalMetaUpdates: EvalMetaUpdates = [];
const overwriteObj = overrideWidgetProperties({
currentTree,
entity: currentTree.Input1 as DataTreeWidget,
propertyPath: "defaultText",
value: "abcde",
evalMetaUpdates,
});
expect(overwriteObj).toStrictEqual(undefined);
expect(evalMetaUpdates).toStrictEqual([
{
//@ts-expect-error: widgetId does not exits on type DataTreeEntity
widgetId: currentTree.Input1.widgetId,
metaPropertyPath: ["inputText"],
value: "abcde",
},
{
//@ts-expect-error: widgetId does not exits on type DataTreeEntity
widgetId: currentTree.Input1.widgetId,
metaPropertyPath: ["text"],
value: "abcde",
},
]);
//@ts-expect-error: meta does not exits on type DataTreeEntity
expect(currentTree.Input1.meta).toStrictEqual({
text: "abcde",
inputText: "abcde",
});
});
// When meta.text is re-evaluated it will override values text in InputWidget
it("2. meta.text updating text", () => {
const evalMetaUpdates: EvalMetaUpdates = [];
const overwriteObj = overrideWidgetProperties({
currentTree,
entity: currentTree.Input1 as DataTreeWidget,
propertyPath: "meta.text",
value: "abcdefg",
evalMetaUpdates,
});
expect(overwriteObj).toStrictEqual(undefined);
expect(evalMetaUpdates).toStrictEqual([]);
//@ts-expect-error: text does not exits on type DataTreeEntity
expect(currentTree.Input1.text).toStrictEqual("abcdefg");
});
});
describe("2. Table widget ", () => {
const currentTree: DataTree = {};
beforeAll(() => {
const tableWidgetDataTree = generateDataTreeWidget(
{
type: TableWidget.getWidgetType(),
widgetId: "random",
widgetName: "Table1",
children: [],
bottomRow: 0,
isLoading: false,
parentColumnSpace: 0,
parentRowSpace: 0,
version: 1,
leftColumn: 0,
renderMode: RenderModes.CANVAS,
rightColumn: 0,
topRow: 0,
},
{},
);
currentTree["Table1"] = tableWidgetDataTree;
});
// When default defaultSelectedRow is re-evaluated it will override values of meta.selectedRowIndices, selectedRowIndices, meta.selectedRowIndex & selectedRowIndex.
it("1. On change of defaultSelectedRow ", () => {
const evalMetaUpdates: EvalMetaUpdates = [];
const overwriteObj = overrideWidgetProperties({
currentTree,
entity: currentTree.Table1 as DataTreeWidget,
propertyPath: "defaultSelectedRow",
value: [0, 1],
evalMetaUpdates,
});
expect(overwriteObj).toStrictEqual(undefined);
expect(evalMetaUpdates).toStrictEqual([
{
//@ts-expect-error: widgetId does not exits on type DataTreeEntity
widgetId: currentTree.Table1.widgetId,
metaPropertyPath: ["selectedRowIndex"],
value: [0, 1],
},
{
//@ts-expect-error: widgetId does not exits on type DataTreeEntity
widgetId: currentTree.Table1.widgetId,
metaPropertyPath: ["selectedRowIndices"],
value: [0, 1],
},
]);
//@ts-expect-error: meta does not exits on type DataTreeEntity
expect(currentTree.Table1.meta.selectedRowIndex).toStrictEqual([0, 1]);
//@ts-expect-error: meta does not exits on type DataTreeEntity
expect(currentTree.Table1.meta.selectedRowIndices).toStrictEqual([0, 1]);
});
// When meta.selectedRowIndex is re-evaluated it will override values selectedRowIndex
it("2. meta.selectedRowIndex updating selectedRowIndex", () => {
const evalMetaUpdates: EvalMetaUpdates = [];
const overwriteObj = overrideWidgetProperties({
currentTree,
entity: currentTree.Table1 as DataTreeWidget,
propertyPath: "meta.selectedRowIndex",
value: 0,
evalMetaUpdates,
});
expect(overwriteObj).toStrictEqual(undefined);
expect(evalMetaUpdates).toStrictEqual([]);
//@ts-expect-error: selectedRowIndex does not exits on type DataTreeEntity
expect(currentTree.Table1.selectedRowIndex).toStrictEqual(0);
});
});
});
describe("removeLintErrorsFromEntityProperty", () => {
it("returns correct result", function() {
const dataTree: DataTree = { ...testDataTree };
const path = "Button1.text";
removeLintErrorsFromEntityProperty(dataTree, path);
expect(get(dataTree, `Button1.${EVAL_ERROR_PATH}[text]`)).toEqual([]);
});
});