PromucFlow_constructor/app/client/src/entities/Action/actionProperties.test.ts
Arsalan Yaldram f58451aa5f
feat: upgrade to create react app 5 (#14000)
* Updated Typescript types.

* Typefixes after merge with release.

* chore: GenericApiResponse Removed alltogether.

* chore: resolved ApiResponse unknown errors removed PageListPayload.

* Added shouldBeDefined.

* fix: Resolved type errors.

* fix: Typescript upgrade to 4.5 and type fixes.

* feat: upgrade to cra 5

* feat: uncomment service worker registeration

* force secure websocket protocol

* jest test fixes

* fix: react function lint rule removed

* fix: klona test case.

* fix: typescirpt issues resolved

* fix: timeout for colorpicker test and change env.

* feat: update client-build.yml file

* fix: remove brotliplugin use compression plugin

* fix: build config fixed

* fix: upgrade webpack plugin

* fix: add branchbutton test to todo.

* fix: remove branch button test.

* fix: Add tailwind theme values, fix cypress tests

* fix: Typescript type fixes.

* feat: run jest tests in silent mode

* fix: cypress rgb values add branchbutton jest test

* fix: review comments, fixes for error.message

* fix: increase cache size for the workbox

* fix: remove OrgApi.ts file

* fix: cypress.json file remove credentials

* fix: downgrade react and react-dom packages

Co-authored-by: rahulramesha <rahul@appsmith.com>
2022-06-21 19:27:34 +05:30

342 lines
10 KiB
TypeScript

import { Action, PluginType } from "entities/Action/index";
import { getBindingAndReactivePathsOfAction } from "entities/Action/actionProperties";
import { EvaluationSubstitutionType } from "entities/DataTree/dataTreeFactory";
const DEFAULT_ACTION: Action = {
actionConfiguration: {},
cacheResponse: "",
datasource: {
id: "randomDatasource",
},
dynamicBindingPathList: [],
executeOnLoad: false,
id: "",
invalids: [],
isValid: false,
jsonPathKeys: [],
name: "",
workspaceId: "",
pageId: "",
pluginId: "",
messages: [],
pluginType: PluginType.DB,
};
describe("getReactivePathsOfAction", () => {
it("returns default list of no config is sent", () => {
const response = getBindingAndReactivePathsOfAction(
DEFAULT_ACTION,
undefined,
).reactivePaths;
expect(response).toStrictEqual({
data: EvaluationSubstitutionType.TEMPLATE,
isLoading: EvaluationSubstitutionType.TEMPLATE,
config: EvaluationSubstitutionType.TEMPLATE,
datasourceUrl: EvaluationSubstitutionType.TEMPLATE,
});
});
it("returns correct values for basic config", () => {
const config = [
{
sectionName: "",
id: 1,
children: [
{
label: "",
configProperty: "actionConfiguration.body",
controlType: "QUERY_DYNAMIC_TEXT",
},
{
label: "",
configProperty: "actionConfiguration.body2",
controlType: "QUERY_DYNAMIC_INPUT_TEXT",
},
{
label: "",
configProperty: "actionConfiguration.field1",
controlType: "QUERY_DYNAMIC_INPUT_TEXT",
evaluationSubstitutionType: "SMART_SUBSTITUTE",
},
{
label: "",
configProperty: "actionConfiguration.field2",
controlType: "QUERY_DYNAMIC_INPUT_TEXT",
evaluationSubstitutionType: "PARAMETER",
},
],
},
];
const basicAction = {
...DEFAULT_ACTION,
actionConfiguration: {
body: "basic action",
body2: "another body",
field1: "test",
field2: "anotherTest",
},
};
const response = getBindingAndReactivePathsOfAction(basicAction, config)
.reactivePaths;
expect(response).toStrictEqual({
data: EvaluationSubstitutionType.TEMPLATE,
isLoading: EvaluationSubstitutionType.TEMPLATE,
datasourceUrl: EvaluationSubstitutionType.TEMPLATE,
"config.body": EvaluationSubstitutionType.TEMPLATE,
"config.body2": EvaluationSubstitutionType.TEMPLATE,
"config.field1": EvaluationSubstitutionType.SMART_SUBSTITUTE,
"config.field2": EvaluationSubstitutionType.PARAMETER,
});
});
it("returns correct values for array field config", () => {
const config = [
{
sectionName: "",
id: 1,
children: [
{
label: "Test label",
configProperty: "actionConfiguration.params",
controlType: "ARRAY_FIELD",
schema: [
{
label: "Key",
key: "key",
controlType: "QUERY_DYNAMIC_INPUT_TEXT",
placeholderText: "Key",
},
{
label: "Value",
key: "value",
controlType: "QUERY_DYNAMIC_INPUT_TEXT",
placeholderText: "Key",
},
{
label: "random",
key: "randomKey",
controlType: "INPUT_TEXT",
placeholderText: "random",
},
],
},
],
},
];
const basicAction = {
...DEFAULT_ACTION,
actionConfiguration: {
params: [
{
key: "test1",
value: "test1",
randomKey: "test1",
},
{
key: "test2",
value: "test2",
randomKey: "test2",
},
],
},
};
// @ts-expect-error: Types are not available
const response = getBindingAndReactivePathsOfAction(basicAction, config)
.reactivePaths;
expect(response).toStrictEqual({
data: EvaluationSubstitutionType.TEMPLATE,
isLoading: EvaluationSubstitutionType.TEMPLATE,
datasourceUrl: EvaluationSubstitutionType.TEMPLATE,
"config.params[0].key": EvaluationSubstitutionType.TEMPLATE,
"config.params[0].value": EvaluationSubstitutionType.TEMPLATE,
"config.params[1].key": EvaluationSubstitutionType.TEMPLATE,
"config.params[1].value": EvaluationSubstitutionType.TEMPLATE,
});
});
it("handles recursive sections", () => {
const config = [
{
sectionName: "",
id: 1,
children: [
{
label: "random",
configProperty: "actionConfiguration.randomKey",
controlType: "INPUT_TEXT",
placeholderText: "random",
},
{
sectionName: "",
id: 2,
children: [
{
label: "Key",
configProperty: "actionConfiguration.key",
controlType: "QUERY_DYNAMIC_INPUT_TEXT",
placeholderText: "Key",
},
{
label: "Value",
configProperty: "actionConfiguration.value",
controlType: "QUERY_DYNAMIC_INPUT_TEXT",
placeholderText: "Key",
},
],
},
],
},
];
const basicAction = {
...DEFAULT_ACTION,
actionConfiguration: {
randomKey: "randomValue",
key: "test1",
test: "test2",
},
};
// @ts-expect-error: Types are not available
const response = getBindingAndReactivePathsOfAction(basicAction, config)
.reactivePaths;
expect(response).toStrictEqual({
data: EvaluationSubstitutionType.TEMPLATE,
isLoading: EvaluationSubstitutionType.TEMPLATE,
datasourceUrl: EvaluationSubstitutionType.TEMPLATE,
"config.key": EvaluationSubstitutionType.TEMPLATE,
"config.value": EvaluationSubstitutionType.TEMPLATE,
});
});
it("checks for hidden field and returns reactivePaths accordingly", () => {
const config = [
{
sectionName: "",
id: 1,
children: [
{
label: "",
configProperty: "actionConfiguration.body",
controlType: "QUERY_DYNAMIC_TEXT",
},
{
label: "",
configProperty: "actionConfiguration.body2",
controlType: "QUERY_DYNAMIC_INPUT_TEXT",
hidden: {
path: "actionConfiguration.template.setting",
comparison: "EQUALS",
value: false,
},
},
{
label: "",
configProperty: "actionConfiguration.field1",
controlType: "QUERY_DYNAMIC_INPUT_TEXT",
evaluationSubstitutionType: "SMART_SUBSTITUTE",
hidden: {
path: "actionConfiguration.template.setting",
comparison: "EQUALS",
value: true,
},
},
],
},
];
const basicAction = {
...DEFAULT_ACTION,
actionConfiguration: {
body: "basic action",
body2: "another body",
field1: "alternate body",
template: {
setting: false,
},
},
};
const response = getBindingAndReactivePathsOfAction(basicAction, config)
.reactivePaths;
expect(response).toStrictEqual({
data: EvaluationSubstitutionType.TEMPLATE,
isLoading: EvaluationSubstitutionType.TEMPLATE,
datasourceUrl: EvaluationSubstitutionType.TEMPLATE,
"config.body": EvaluationSubstitutionType.TEMPLATE,
"config.field1": EvaluationSubstitutionType.SMART_SUBSTITUTE,
});
basicAction.actionConfiguration.template.setting = true;
const response2 = getBindingAndReactivePathsOfAction(basicAction, config)
.reactivePaths;
expect(response2).toStrictEqual({
data: EvaluationSubstitutionType.TEMPLATE,
isLoading: EvaluationSubstitutionType.TEMPLATE,
datasourceUrl: EvaluationSubstitutionType.TEMPLATE,
"config.body": EvaluationSubstitutionType.TEMPLATE,
"config.body2": EvaluationSubstitutionType.TEMPLATE,
});
});
it("returns default list of no config is sent", () => {
const response = getBindingAndReactivePathsOfAction(
DEFAULT_ACTION,
undefined,
).bindingPaths;
expect(response).toStrictEqual({});
});
it("returns correct values for basic config", () => {
const config = [
{
sectionName: "",
id: 1,
children: [
{
label: "",
configProperty: "actionConfiguration.body",
controlType: "QUERY_DYNAMIC_TEXT",
},
{
label: "",
configProperty: "actionConfiguration.body2",
controlType: "QUERY_DYNAMIC_INPUT_TEXT",
},
{
label: "",
configProperty: "actionConfiguration.field1",
controlType: "QUERY_DYNAMIC_INPUT_TEXT",
evaluationSubstitutionType: "SMART_SUBSTITUTE",
},
{
label: "",
configProperty: "actionConfiguration.field2",
controlType: "QUERY_DYNAMIC_INPUT_TEXT",
evaluationSubstitutionType: "PARAMETER",
},
],
},
];
const basicAction = {
...DEFAULT_ACTION,
actionConfiguration: {
body: "basic action",
body2: "another body",
field1: "test",
field2: "anotherTest",
},
};
const response = getBindingAndReactivePathsOfAction(basicAction, config)
.bindingPaths;
expect(response).toStrictEqual({
"config.body": EvaluationSubstitutionType.TEMPLATE,
"config.body2": EvaluationSubstitutionType.TEMPLATE,
"config.field1": EvaluationSubstitutionType.SMART_SUBSTITUTE,
"config.field2": EvaluationSubstitutionType.PARAMETER,
});
});
});