2021-04-21 14:34:25 +00:00
|
|
|
import { FlattenedWidgetProps } from "reducers/entityReducers/canvasWidgetsReducer";
|
|
|
|
|
import { generateDataTreeWidget } from "entities/DataTree/dataTreeWidget";
|
2021-04-26 05:41:32 +00:00
|
|
|
import {
|
|
|
|
|
DataTreeWidget,
|
|
|
|
|
ENTITY_TYPE,
|
|
|
|
|
EvaluationSubstitutionType,
|
|
|
|
|
} from "entities/DataTree/dataTreeFactory";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { RenderModes } from "constants/WidgetConstants";
|
2021-04-21 14:34:25 +00:00
|
|
|
import WidgetFactory from "utils/WidgetFactory";
|
2021-09-09 15:10:22 +00:00
|
|
|
|
2021-07-26 05:50:46 +00:00
|
|
|
import { ValidationTypes } from "constants/WidgetValidation";
|
2021-04-21 14:34:25 +00:00
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
// const WidgetTypes = WidgetFactory.widgetTypes;
|
|
|
|
|
|
2021-04-21 14:34:25 +00:00
|
|
|
describe("generateDataTreeWidget", () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
const getMetaProps = jest.spyOn(
|
|
|
|
|
WidgetFactory,
|
|
|
|
|
"getWidgetMetaPropertiesMap",
|
|
|
|
|
);
|
|
|
|
|
getMetaProps.mockReturnValueOnce({
|
|
|
|
|
text: undefined,
|
|
|
|
|
isDirty: false,
|
|
|
|
|
isFocused: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const getDerivedProps = jest.spyOn(
|
|
|
|
|
WidgetFactory,
|
|
|
|
|
"getWidgetDerivedPropertiesMap",
|
|
|
|
|
);
|
|
|
|
|
getDerivedProps.mockReturnValueOnce({
|
|
|
|
|
isValid: "{{true}}",
|
|
|
|
|
value: "{{this.text}}",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const getDefaultProps = jest.spyOn(
|
|
|
|
|
WidgetFactory,
|
|
|
|
|
"getWidgetDefaultPropertiesMap",
|
|
|
|
|
);
|
|
|
|
|
getDefaultProps.mockReturnValueOnce({
|
|
|
|
|
text: "defaultText",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const getPropertyConfig = jest.spyOn(
|
|
|
|
|
WidgetFactory,
|
|
|
|
|
"getWidgetPropertyPaneConfig",
|
|
|
|
|
);
|
|
|
|
|
getPropertyConfig.mockReturnValueOnce([
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "inputType",
|
|
|
|
|
label: "Data Type",
|
|
|
|
|
controlType: "DROP_DOWN",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "defaultText",
|
|
|
|
|
label: "Default Text",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.TEXT },
|
2021-04-21 14:34:25 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "placeholderText",
|
|
|
|
|
label: "Placeholder",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.TEXT },
|
2021-04-21 14:34:25 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "regex",
|
|
|
|
|
label: "Regex",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.REGEX },
|
2021-04-21 14:34:25 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "errorMessage",
|
|
|
|
|
label: "Error Message",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.TEXT },
|
2021-04-21 14:34:25 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isRequired",
|
|
|
|
|
label: "Required",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
2021-04-21 14:34:25 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isVisible",
|
|
|
|
|
label: "Visible",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
2021-04-21 14:34:25 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isDisabled",
|
|
|
|
|
label: "Disabled",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
2021-04-21 14:34:25 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "resetOnSubmit",
|
|
|
|
|
label: "Reset on submit",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
2021-04-21 14:34:25 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Actions",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "onTextChanged",
|
|
|
|
|
label: "onTextChanged",
|
|
|
|
|
controlType: "ACTION_SELECTOR",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "onSubmit",
|
|
|
|
|
label: "onSubmit",
|
|
|
|
|
controlType: "ACTION_SELECTOR",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
jest.clearAllMocks();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("generates enhanced widget with the right properties", () => {
|
|
|
|
|
const widget: FlattenedWidgetProps = {
|
|
|
|
|
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: "INPUT_WIDGET",
|
2021-04-21 14:34:25 +00:00
|
|
|
version: 0,
|
|
|
|
|
widgetId: "123",
|
|
|
|
|
widgetName: "Input1",
|
|
|
|
|
defaultText: "Testing",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const widgetMetaProps: Record<string, unknown> = {
|
|
|
|
|
text: "Tester",
|
|
|
|
|
isDirty: true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getMetaProps = jest.spyOn(
|
|
|
|
|
WidgetFactory,
|
|
|
|
|
"getWidgetMetaPropertiesMap",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
getMetaProps.mockReturnValueOnce({
|
|
|
|
|
text: true,
|
|
|
|
|
isDirty: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const expected: DataTreeWidget = {
|
|
|
|
|
bindingPaths: {
|
2021-04-26 05:41:32 +00:00
|
|
|
defaultText: EvaluationSubstitutionType.TEMPLATE,
|
|
|
|
|
errorMessage: EvaluationSubstitutionType.TEMPLATE,
|
|
|
|
|
isDirty: EvaluationSubstitutionType.TEMPLATE,
|
|
|
|
|
isDisabled: EvaluationSubstitutionType.TEMPLATE,
|
|
|
|
|
isFocused: EvaluationSubstitutionType.TEMPLATE,
|
|
|
|
|
isRequired: EvaluationSubstitutionType.TEMPLATE,
|
|
|
|
|
isValid: EvaluationSubstitutionType.TEMPLATE,
|
|
|
|
|
isVisible: EvaluationSubstitutionType.TEMPLATE,
|
|
|
|
|
placeholderText: EvaluationSubstitutionType.TEMPLATE,
|
|
|
|
|
regex: EvaluationSubstitutionType.TEMPLATE,
|
|
|
|
|
resetOnSubmit: EvaluationSubstitutionType.TEMPLATE,
|
|
|
|
|
text: EvaluationSubstitutionType.TEMPLATE,
|
|
|
|
|
value: EvaluationSubstitutionType.TEMPLATE,
|
2021-04-21 14:34:25 +00:00
|
|
|
},
|
|
|
|
|
triggerPaths: {
|
|
|
|
|
onSubmit: true,
|
|
|
|
|
onTextChanged: true,
|
|
|
|
|
},
|
|
|
|
|
validationPaths: {
|
2021-07-26 05:50:46 +00:00
|
|
|
defaultText: { type: ValidationTypes.TEXT },
|
|
|
|
|
errorMessage: { type: ValidationTypes.TEXT },
|
|
|
|
|
isDisabled: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
isRequired: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
isVisible: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
placeholderText: { type: ValidationTypes.TEXT },
|
|
|
|
|
regex: { type: ValidationTypes.REGEX },
|
|
|
|
|
resetOnSubmit: { type: ValidationTypes.BOOLEAN },
|
2021-04-21 14:34:25 +00:00
|
|
|
},
|
|
|
|
|
dynamicBindingPathList: [
|
|
|
|
|
{
|
|
|
|
|
key: "isValid",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: "value",
|
|
|
|
|
},
|
|
|
|
|
],
|
2021-06-04 07:09:36 +00:00
|
|
|
logBlackList: {
|
|
|
|
|
isValid: true,
|
|
|
|
|
value: true,
|
|
|
|
|
},
|
2021-04-21 14:34:25 +00:00
|
|
|
value: "{{Input1.text}}",
|
|
|
|
|
isDirty: true,
|
|
|
|
|
isFocused: false,
|
|
|
|
|
isValid: "{{true}}",
|
|
|
|
|
text: "Tester",
|
|
|
|
|
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: "INPUT_WIDGET",
|
2021-04-21 14:34:25 +00:00
|
|
|
version: 0,
|
|
|
|
|
widgetId: "123",
|
|
|
|
|
widgetName: "Input1",
|
|
|
|
|
ENTITY_TYPE: ENTITY_TYPE.WIDGET,
|
|
|
|
|
defaultText: "Testing",
|
2021-06-18 07:42:57 +00:00
|
|
|
defaultMetaProps: ["text", "isDirty", "isFocused"],
|
|
|
|
|
defaultProps: {
|
|
|
|
|
text: "defaultText",
|
|
|
|
|
},
|
2021-04-21 14:34:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const result = generateDataTreeWidget(widget, widgetMetaProps);
|
|
|
|
|
|
|
|
|
|
expect(result).toStrictEqual(expected);
|
|
|
|
|
});
|
|
|
|
|
});
|