PromucFlow_constructor/app/client/src/utils/canvasStructureHelpers.test.ts
Valera Melnikov a2bfe450b6
chore: enable no-explicit-any rule (#35321)
## Description
-  Enabled the rule `@typescript-eslint/no-explicit-any`
- Suppressed errors with comment
```
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
```

Fixes #35308 

## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10181176984>
> Commit: 7fc604e24fa234da7ab2ff56e0b1c715268796ee
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10181176984&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 31 Jul 2024 15:00:45 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
2024-07-31 18:41:28 +03:00

173 lines
3.7 KiB
TypeScript

import type { CanvasStructure } from "reducers/uiReducers/pageCanvasStructureReducer";
import { compareAndGenerateImmutableCanvasStructure } from "./canvasStructureHelpers";
const canvasStructure: CanvasStructure = {
widgetId: "x",
widgetName: "x",
type: "CONTAINER_WIDGET",
children: [
{
widgetId: "y",
widgetName: "y",
type: "CONTAINER_WIDGET",
children: [
{
widgetId: "z",
widgetName: "z",
type: "CONTAINER_WIDGET",
},
],
},
{
widgetId: "m",
widgetName: "m",
type: "CONTAINER_WIDGET",
children: [
{
widgetId: "n",
widgetName: "n",
type: "CONTAINER_WIDGET",
children: [
{
widgetId: "o",
widgetName: "o",
type: "CONTAINER_WIDGET",
},
],
},
],
},
],
};
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const simpleDSL: any = {
widgetId: "x",
widgetName: "x",
type: "CONTAINER_WIDGET",
children: [
{
widgetId: "y",
widgetName: "y",
type: "CONTAINER_WIDGET",
children: [
{
widgetId: "z",
widgetName: "z",
type: "CONTAINER_WIDGET",
},
],
},
{
widgetId: "m",
widgetName: "m",
type: "CONTAINER_WIDGET",
children: [
{
widgetId: "n",
widgetName: "n",
type: "CONTAINER_WIDGET",
children: [
{
widgetId: "o",
widgetName: "o",
type: "CONTAINER_WIDGET",
},
],
},
],
},
],
};
describe("Immutable Canvas structures", () => {
it("generates the same object if it is run with the same dsl", () => {
const nextState = compareAndGenerateImmutableCanvasStructure(
canvasStructure,
simpleDSL,
);
expect(nextState).toBe(canvasStructure);
});
it("updates the diff appropriately", () => {
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const dsl: any = {
widgetId: "x",
widgetName: "x",
children: [
{
widgetId: "y",
widgetName: "y",
children: [
{
widgetId: "z",
widgetName: "z",
},
],
},
{
widgetId: "m",
widgetName: "newName",
children: [
{
widgetId: "n",
widgetName: "n",
children: [
{
widgetId: "o",
widgetName: "o",
},
],
},
],
},
],
};
const expectedCanvasStructure = {
widgetId: "x",
widgetName: "x",
children: [
{
widgetId: "y",
widgetName: "y",
children: [
{
widgetId: "z",
widgetName: "z",
},
],
},
{
widgetId: "m",
widgetName: "newName",
children: [
{
widgetId: "n",
widgetName: "n",
children: [
{
widgetId: "o",
widgetName: "o",
},
],
},
],
},
],
};
const nextState = compareAndGenerateImmutableCanvasStructure(
canvasStructure,
dsl,
);
expect(nextState).not.toBe(expectedCanvasStructure);
expect(JSON.stringify(nextState)).toBe(
JSON.stringify(expectedCanvasStructure),
);
});
});