* update structure of chart data * update chart data * update chart data structure * remove array like validator * remove log * remove log * widget utils + update tests for chart data validations * update utils test * add migrations * remove unnecessary helper function * remove unnecessary helper function * update validation test cases * WIP * WIP 2 * Remove validationConfigMap from widget and add to properties * Update data tree validator to get validation from the correct place * Minor reference fixes * Fix test mocks * fix for bad setting of nested property path * add test for migration for chart widget function * fix test for widget utils * remove unused import; * remove unsued import * update migration version * remove console and add check if data is array * fix custom fusion chart + validation not working issue * move custom fusion chart config to chart data section * remove console and unused import * fix test * fix property config test * fix dynamicbinding path list in migration * remove old chart validation * remove old validation test * fix widget prop utils test * remove array codepath for widget utils * fix utils test * fix utils test * fix prettier issue Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: hetunandu <hetu@appsmith.com> Co-authored-by: Hetu Nandu <hetunandu@gmail.com>
91 lines
2.5 KiB
TypeScript
91 lines
2.5 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-namespace */
|
|
import { isString, get } from "lodash";
|
|
import config from "./propertyConfig";
|
|
|
|
declare global {
|
|
namespace jest {
|
|
interface Matchers<R> {
|
|
toBePropertyPaneConfig(): R;
|
|
}
|
|
}
|
|
}
|
|
const validateControl = (control: Record<string, unknown>) => {
|
|
if (typeof control !== "object") return false;
|
|
const properties = [
|
|
"propertyName",
|
|
"controlType",
|
|
"isBindProperty",
|
|
"isTriggerProperty",
|
|
];
|
|
properties.forEach((prop: string) => {
|
|
if (!control.hasOwnProperty(prop)) {
|
|
return false;
|
|
}
|
|
const value = control[prop];
|
|
if (isString(value) && value.length === 0) return false;
|
|
});
|
|
return true;
|
|
};
|
|
|
|
const validateSection = (section: Record<string, unknown>) => {
|
|
if (typeof section !== "object") return false;
|
|
if (!section.hasOwnProperty("sectionName")) return false;
|
|
const name = section.sectionName;
|
|
if ((name as string).length === 0) return false;
|
|
if (section.children) {
|
|
return (section.children as Array<Record<string, unknown>>).forEach(
|
|
(child) => {
|
|
if (!validateControl(child)) return false;
|
|
},
|
|
);
|
|
}
|
|
return true;
|
|
};
|
|
|
|
expect.extend({
|
|
toBePropertyPaneConfig(received) {
|
|
if (Array.isArray(received)) {
|
|
let pass = true;
|
|
received.forEach((section) => {
|
|
if (!validateSection(section) && !validateControl(section))
|
|
pass = false;
|
|
});
|
|
return {
|
|
pass,
|
|
message: () => "Expected value to be a property pane config internal",
|
|
};
|
|
}
|
|
return {
|
|
pass: false,
|
|
message: () => "Expected value to be a property pane config external",
|
|
};
|
|
},
|
|
});
|
|
|
|
describe("Validate Chart Widget's property config", () => {
|
|
it("Validates Chart Widget's property config", () => {
|
|
expect(config).toBePropertyPaneConfig();
|
|
});
|
|
|
|
it("Validates config when chartType is CUSTOM_FUSION_CHART", () => {
|
|
const hiddenFn: (props: any) => boolean = get(
|
|
config,
|
|
"[1].children.[0].hidden",
|
|
);
|
|
let result = true;
|
|
if (hiddenFn) result = hiddenFn({ chartType: "CUSTOM_FUSION_CHART" });
|
|
expect(result).toBeFalsy();
|
|
});
|
|
|
|
it("Validates that sections are hidden when chartType is CUSTOM_FUSION_CHART", () => {
|
|
const hiddenFns = [
|
|
get(config, "[1].children.[1].hidden"),
|
|
get(config, "[2].hidden"),
|
|
];
|
|
hiddenFns.forEach((fn: (props: any) => boolean) => {
|
|
const result = fn({ chartType: "CUSTOM_FUSION_CHART" });
|
|
expect(result).toBeTruthy();
|
|
});
|
|
});
|
|
});
|