PromucFlow_constructor/app/client/test/factories/Actions/JSObject.ts
Hetu Nandu f5553ed2af
chore: Add IDE JS Rendering tests (#32056)
## Description
Adds IDE rendering tests for JS routes

Fixes #31867 

## Automation

/ok-to-test tags="@tag.IDE"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!IMPORTANT]  
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/8431959142>
> Commit: `ead16d0a5a8bb41003d7c75ae5a4f4fa648e3420`
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8431959142&attempt=1"
target="_blank">Click here!</a>
> All cypress tests have passed 🎉🎉🎉

<!-- end of auto-generated comment: Cypress test results  -->




<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **Tests**
- Introduced test cases for rendering JavaScript components in different
states within the IDE.
- **Chores**
- Added mock data factories for JavaScript objects with actions,
enhancing testing capabilities.
- Updated factory utilities to support JavaScript actions in IDE test
states.
- Included a new entry for the JavaScript plugin in the mock plugins
state configuration.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-03-26 12:50:00 +05:30

104 lines
3.0 KiB
TypeScript

import * as Factory from "factory.ts";
import type { JSCollection } from "entities/JSCollection";
import { PluginPackageName, PluginType } from "entities/Action";
import { PluginIDs } from "test/factories/MockPluginsState";
export const JSObjectFactory = Factory.Sync.makeFactory<JSCollection>({
id: "js_id",
workspaceId: "workspaceId",
applicationId: "appId",
name: Factory.each((i) => `JSObject${i + 1}`),
pageId: "5ff4735253b64c03e830009b",
pluginId: PluginIDs[PluginPackageName.JS],
pluginType: PluginType.JS,
actions: [
{
id: "myFunc1_id",
workspaceId: "workspaceId",
pluginId: PluginIDs[PluginPackageName.JS],
name: "myFun1",
fullyQualifiedName: "JSObject1.myFun1",
pageId: "page_id",
collectionId: "js_id",
actionConfiguration: {
timeoutInMillisecond: 10000,
body: "function (){\n\t\t//\twrite code here\n\t\t//\tthis.myVar1 = [1,2,3]\n\t}",
jsArguments: [],
},
executeOnLoad: false,
clientSideExecution: true,
dynamicBindingPathList: [
{
key: "body",
},
],
isValid: true,
invalids: [],
messages: [],
jsonPathKeys: [
"function (){\n\t\t//\twrite code here\n\t\t//\tthis.myVar1 = [1,2,3]\n\t}",
],
confirmBeforeExecute: false,
userPermissions: [
"read:actions",
"delete:actions",
"execute:actions",
"manage:actions",
],
cacheResponse: "",
},
{
id: "myFunc2_id",
workspaceId: "workspaceId",
pluginId: "613a26d921750e4b557a9241",
name: "myFun2",
fullyQualifiedName: "JSObject1.myFun2",
pageId: "5ff4735253b64c03e830009b",
collectionId: "660261174b59877d57fc3670",
actionConfiguration: {
timeoutInMillisecond: 10000,
body: "async function () {\n\t\t//\tuse async-await or promises\n\t\t//\tawait storeValue('varName', 'hello world')\n\t}",
jsArguments: [],
},
executeOnLoad: false,
clientSideExecution: true,
dynamicBindingPathList: [
{
key: "body",
},
],
isValid: true,
invalids: [],
messages: [],
jsonPathKeys: [
"async function () {\n\t\t//\tuse async-await or promises\n\t\t//\tawait storeValue('varName', 'hello world')\n\t}",
],
confirmBeforeExecute: false,
userPermissions: [
"read:actions",
"delete:actions",
"execute:actions",
"manage:actions",
],
cacheResponse: "",
},
],
body: "export default {\n\tmyVar1: [],\n\tmyVar2: {},\n\tmyFun1 () {\n\t\t//\twrite code here\n\t\t//\tthis.myVar1 = [1,2,3]\n\t},\n\tasync myFun2 () {\n\t\t//\tuse async-await or promises\n\t\t//\tawait storeValue('varName', 'hello world')\n\t}\n}",
variables: [
{
name: "myVar1",
value: [],
},
{
name: "myVar2",
value: {},
},
],
userPermissions: [
"read:actions",
"delete:actions",
"execute:actions",
"manage:actions",
],
});