add unit test (#13776)

This commit is contained in:
Anand Srinivasan 2022-05-18 13:16:16 +05:30 committed by GitHub
parent f3dec5ca0f
commit 4e5cf6c156
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 305 additions and 1 deletions

View File

@ -1,5 +1,5 @@
import DataTreeEvaluator from "../DataTreeEvaluator";
import { unEvalTree } from "./mockUnEvalTree";
import { asyncTagUnevalTree, unEvalTree } from "./mockUnEvalTree";
import { DataTree } from "entities/DataTree/dataTreeFactory";
import { DataTreeDiff } from "workers/evaluationUtils";
import { ALL_WIDGETS_AND_CONFIG } from "utils/WidgetRegistry";
@ -186,4 +186,19 @@ describe("DataTreeEvaluator", () => {
});
});
});
describe("parseJsActions", () => {
beforeEach(() => {
dataTreeEvaluator.createFirstTree({});
});
it("set's isAsync tag for cross JsObject references", () => {
const result = dataTreeEvaluator.parseJSActions(asyncTagUnevalTree);
expect(
result.jsUpdates["JSObject1"]?.parsedBody?.actions[0].isAsync,
).toBe(true);
expect(
result.jsUpdates["JSObject2"]?.parsedBody?.actions[0].isAsync,
).toBe(true);
});
});
});

View File

@ -1,3 +1,12 @@
import { PluginType, PaginationType } from "entities/Action";
import {
DataTree,
EvaluationSubstitutionType,
DataTreeWidget,
DataTreeAppsmith,
ENTITY_TYPE,
} from "entities/DataTree/dataTreeFactory";
export const unEvalTree = {
MainContainer: {
widgetName: "MainContainer",
@ -291,3 +300,283 @@ export const unEvalTree = {
ENTITY_TYPE: "APPSMITH",
},
};
export const asyncTagUnevalTree: DataTree = {
Api1: {
run: {},
clear: {},
actionId: "6279ff0c0b47255c280c4631",
name: "Api1",
pluginId: "5ca385dc81b37f0004b4db85",
pluginType: PluginType.API,
config: {
timeoutInMillisecond: 10000,
paginationType: PaginationType.NONE,
path: "/echo/get",
queryParameters: [],
pluginSpecifiedTemplates: [
{
value: true,
},
],
formData: {
apiContentType: "none",
},
},
dynamicBindingPathList: [],
data: {
args: {},
url: "https://mock-api.appsmith.com/echo/get",
headers: {
accept: "*/*",
authorization: "Basic dGVzdDo=",
"cloudfront-forwarded-proto": "https",
"cloudfront-is-desktop-viewer": "true",
"cloudfront-is-mobile-viewer": "false",
"cloudfront-is-smarttv-viewer": "false",
"cloudfront-is-tablet-viewer": "false",
"cloudfront-viewer-country": "US",
host: "mock-api.appsmith.com",
test: "val",
"user-agent": "ReactorNetty/1.0.15",
via: "1.1 290e11478c5b9149e389233998147082.cloudfront.net (CloudFront)",
"x-amz-cf-id":
"xKBvLoL6ObBLGeqyky6ZuXl2I9ZgQu58BKzcYvR5VDgDdKgCexv8Zg==",
"x-amzn-trace-id": "Root=1-627ba66a-2f010d2a5dcfb14009419780",
"x-forwarded-for": "18.223.74.85, 64.252.147.156",
"x-forwarded-port": "443",
"x-forwarded-proto": "https",
"x-request-id": "2c751e3c-7d54-4f08-908a-a9c909d4f12b",
"content-length": 0,
},
},
responseMeta: {
statusCode: "200 OK",
isExecutionSuccess: true,
headers: {
"Content-Type": ["application/json; charset=utf-8"],
Connection: ["keep-alive"],
Date: ["Wed, 11 May 2022 12:04:58 GMT"],
"x-amzn-RequestId": ["2c751e3c-7d54-4f08-908a-a9c909d4f12b"],
"x-amzn-Remapped-content-length": ["802"],
"x-amz-apigw-id": ["R9bwsHujiYcF0IQ="],
etag: ['W/"322-KKw8fZnypLi/dqYHfS13soe8o2s"'],
"x-powered-by": ["Express"],
"X-Amzn-Trace-Id": [
"Root=1-627ba66a-2f010d2a5dcfb14009419780;Sampled=0",
],
"X-Cache": ["Miss from cloudfront"],
Via: [
"1.1 290e11478c5b9149e389233998147082.cloudfront.net (CloudFront)",
],
"X-Amz-Cf-Pop": ["YTO50-C1"],
"X-Amz-Cf-Id": [
"xKBvLoL6ObBLGeqyky6ZuXl2I9ZgQu58BKzcYvR5VDgDdKgCexv8Zg==",
],
"content-length": ["802"],
"X-APPSMITH-DATATYPE": ["JSON"],
},
},
ENTITY_TYPE: ENTITY_TYPE.ACTION,
isLoading: false,
bindingPaths: {
"config.path": EvaluationSubstitutionType.TEMPLATE,
"config.body": EvaluationSubstitutionType.SMART_SUBSTITUTE,
},
reactivePaths: {
data: EvaluationSubstitutionType.TEMPLATE,
isLoading: EvaluationSubstitutionType.TEMPLATE,
datasourceUrl: EvaluationSubstitutionType.TEMPLATE,
"config.path": EvaluationSubstitutionType.TEMPLATE,
"config.body": EvaluationSubstitutionType.SMART_SUBSTITUTE,
},
dependencyMap: {
"config.body": ["config.pluginSpecifiedTemplates[0].value"],
},
logBlackList: {},
datasourceUrl: "",
},
JSObject1: {
name: "JSObject1",
actionId: "627217a38a368d6f1efcd0d8",
pluginType: PluginType.JS,
ENTITY_TYPE: ENTITY_TYPE.JSACTION,
body:
"export default { \n\tmyFun1: () => {\n\t\treturn JSObject2.callApi();\n\t},\n}",
meta: {
myFun1: {
arguments: [],
isAsync: false,
confirmBeforeExecute: false,
},
},
bindingPaths: {
body: EvaluationSubstitutionType.SMART_SUBSTITUTE,
myFun1: EvaluationSubstitutionType.SMART_SUBSTITUTE,
},
reactivePaths: {
body: EvaluationSubstitutionType.SMART_SUBSTITUTE,
myFun1: EvaluationSubstitutionType.SMART_SUBSTITUTE,
},
dynamicBindingPathList: [
{
key: "body",
},
{
key: "myFun1",
},
],
variables: [],
dependencyMap: {
body: ["myFun1"],
},
myFun1: {
data: {},
},
},
JSObject2: {
name: "JSObject2",
actionId: "627babc60b47255c28138865",
pluginType: PluginType.JS,
ENTITY_TYPE: ENTITY_TYPE.JSACTION,
body:
"export default {\n\tcallApi: () => {\n\t\treturn Api1.run()\n\t},\n}",
meta: {
callApi: {
arguments: [],
isAsync: false,
confirmBeforeExecute: false,
},
},
bindingPaths: {
body: EvaluationSubstitutionType.SMART_SUBSTITUTE,
callApi: EvaluationSubstitutionType.SMART_SUBSTITUTE,
},
reactivePaths: {
body: EvaluationSubstitutionType.SMART_SUBSTITUTE,
callApi: EvaluationSubstitutionType.SMART_SUBSTITUTE,
},
dynamicBindingPathList: [
{
key: "body",
},
{
key: "callApi",
},
],
variables: [],
dependencyMap: {
body: ["callApi"],
},
callApi: {
data: {},
},
},
MainContainer: ({
widgetName: "MainContainer",
backgroundColor: "none",
rightColumn: 4896,
snapColumns: 64,
detachFromLayout: true,
widgetId: "0",
topRow: 0,
bottomRow: 1320,
containerStyle: "none",
snapRows: 125,
parentRowSpace: 1,
type: "CANVAS_WIDGET",
canExtend: true,
version: 57,
minHeight: 1292,
parentColumnSpace: 1,
dynamicBindingPathList: [],
leftColumn: 0,
children: [],
defaultProps: {},
defaultMetaProps: [],
logBlackList: {},
meta: {},
propertyOverrideDependency: {},
overridingPropertyPaths: {},
bindingPaths: {},
reactivePaths: {},
triggerPaths: {},
validationPaths: {},
ENTITY_TYPE: ENTITY_TYPE.WIDGET,
privateWidgets: {},
} as unknown) as DataTreeWidget,
pageList: [
{
pageName: "Page1",
pageId: "6272179d8a368d6f1efcd0d2",
isDefault: true,
isHidden: false,
slug: "page1",
},
],
appsmith: ({
user: {
email: "anand@appsmith.com",
organizationIds: [
"61431979a67ce2289d3c7c6d",
"61431a95a67ce2289d3c7c74",
"5f7add8687af934ed846dd6a",
"5f9fd13993794869fdbb8dcb",
"618b5af5da7cd651ee273112",
"604ef1c5c046f668d7bcc051",
"61b3389cd3e4214454c26bd1",
"61b3389cd3e4214454c26bd2",
"620a0d896b4b1e154a3c057a",
"620b37296b4b1e154a3c1fd7",
"60c1a5273535574772b6377b",
"6066e71a034ece74b1481ad2",
"623b36e34d9aea1b062b15b3",
"623b37de4d9aea1b062b170f",
"624fe51b457aa64da9e02ed3",
"6176537b515e45415cc7fd15",
"6206486d6b4b1e154a3be208",
],
username: "anand@appsmith.com",
name: "Anand Srinivasan",
enableTelemetry: true,
idToken: {
sub: "109879730040206968321",
email_verified: true,
name: "Anand Srinivasan",
given_name: "Anand",
locale: "en",
hd: "appsmith.com",
family_name: "Srinivasan",
picture:
"https://lh3.googleusercontent.com/a-/AOh14Gi4HfYY0sKhaG93YAHB_E5-dL4BkFxdf8ZfQ2w7=s96-c",
email: "anand@appsmith.com",
},
accountNonExpired: true,
accountNonLocked: true,
credentialsNonExpired: true,
emptyInstance: false,
isAnonymous: false,
isEnabled: true,
isSuperUser: false,
isConfigurable: true,
},
URL: {
fullPath:
"https://app.appsmith.com/app/untitled-application-25/page1-6272179d8a368d6f1efcd0d2/edit",
host: "app.appsmith.com",
hostname: "app.appsmith.com",
queryParams: {},
protocol: "https:",
pathname:
"/app/untitled-application-25/page1-6272179d8a368d6f1efcd0d2/edit",
port: "",
hash: "",
},
store: {},
geolocation: {
canBeRequested: true,
},
mode: "EDIT",
ENTITY_TYPE: ENTITY_TYPE.APPSMITH,
} as unknown) as DataTreeAppsmith,
};