PromucFlow_constructor/app/client/src/widgets/MenuButtonWidget/validations.test.ts
ChandanBalajiBP b72dea33f3
feat: Error handling phase 1 (#20629)
## Description
This PR updates the error logs 
- Establishing a consistent format for all error messages.
- Revising error titles and details for improved understanding.
- Compiling internal documentation of all error categories,
subcategories, and error descriptions.

Updated Error Interface:
https://www.notion.so/appsmith/Error-Interface-for-Plugin-Execution-Error-7b3f5323ba4c40bfad281ae717ccf79b

PRD:
https://www.notion.so/appsmith/PRD-Error-Handling-Framework-4ac9747057fd4105a9d52cb8b42f4452?pvs=4#008e9c79ff3c484abf0250a5416cf052

>TL;DR 

Fixes # 


Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video


## Type of change

- New feature (non-breaking change which adds functionality)


## How Has This Been Tested?

- Manual
- Jest
- Cypress

### Test Plan


### Issues raised during DP testing


## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] PR is being merged under a feature flag


### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test

---------

Co-authored-by: subrata <subrata@appsmith.com>
2023-02-18 18:25:46 +05:30

94 lines
2.0 KiB
TypeScript

import _ from "lodash";
import { sourceDataArrayValidation } from "./validations";
describe("sourceDataArrayValidation", () => {
it("Should test with valid values", () => {
const mockSourceData = [
{
step: "#1",
task: "Drop a table",
status: "✅",
action: "",
},
{
step: "#2",
task: "Create a query fetch_users with the Mock DB",
status: "--",
action: "",
},
{
step: "#3",
task: "Bind the query using => fetch_users.data",
status: "--",
action: "",
},
];
const result = sourceDataArrayValidation(
mockSourceData,
undefined as any,
_,
);
const expected = {
isValid: true,
parsed: mockSourceData,
messages: [{ name: "", message: "" }],
};
expect(result).toStrictEqual(expected);
});
it("Should test when sourceData has a length more than 10", () => {
const mockSourceData = Array(11).fill((_: null, index: number) => {
return {
step: `#${index}`,
task: `Task ${index}`,
status: "--",
action: "",
};
});
const result = sourceDataArrayValidation(
mockSourceData,
undefined as any,
_,
);
const expected = {
isValid: false,
parsed: [],
messages: [
{
name: "RangeError",
message: "Source data cannot have more than 10 items",
},
],
};
expect(result).toStrictEqual(expected);
});
it("Should test when sourceData is not an array", () => {
const mockSourceData = {
step: "#1",
task: "Drop a table",
status: "✅",
action: "",
};
const result = sourceDataArrayValidation(
mockSourceData,
undefined as any,
_,
);
const expected = {
isValid: false,
parsed: [],
messages: [
{
name: "TypeError",
message: "This value does not evaluate to type Array",
},
],
};
expect(result).toStrictEqual(expected);
});
});