chore: jest test spy on klona/full to prevent regression (#27983)
## Description Added jest test that tracks the number of times klona/full is called during first update tree code flow. This is to prevent regressing on the number of clone operations performed during each evaluation cycle > #### 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 - Chore (housekeeping or task changes that don't impact user perception) > ## Testing > #### How Has This Been Tested? - [x] Manual > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] 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 - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
This commit is contained in:
parent
094e859973
commit
f1595dbedc
|
|
@ -17,6 +17,15 @@ import { ValidationTypes } from "constants/WidgetValidation";
|
||||||
import WidgetFactory from "WidgetProvider/factory";
|
import WidgetFactory from "WidgetProvider/factory";
|
||||||
import { generateDataTreeWidget } from "entities/DataTree/dataTreeWidget";
|
import { generateDataTreeWidget } from "entities/DataTree/dataTreeWidget";
|
||||||
import { sortObjectWithArray } from "../../../utils/treeUtils";
|
import { sortObjectWithArray } from "../../../utils/treeUtils";
|
||||||
|
import klona from "klona";
|
||||||
|
|
||||||
|
const klonaFullSpy = jest.fn();
|
||||||
|
jest.mock("klona/full", () => ({
|
||||||
|
klona: (arg: any) => {
|
||||||
|
klonaFullSpy(arg);
|
||||||
|
return klona.klona(arg);
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
const WIDGET_CONFIG_MAP: WidgetTypeConfigMap = {
|
const WIDGET_CONFIG_MAP: WidgetTypeConfigMap = {
|
||||||
CONTAINER_WIDGET: {
|
CONTAINER_WIDGET: {
|
||||||
|
|
@ -334,6 +343,9 @@ const initialdependencies = {
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("DataTreeEvaluator", () => {
|
describe("DataTreeEvaluator", () => {
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
metaMock.mockImplementation((type) => {
|
metaMock.mockImplementation((type) => {
|
||||||
return WIDGET_CONFIG_MAP[type].metaProperties;
|
return WIDGET_CONFIG_MAP[type].metaProperties;
|
||||||
});
|
});
|
||||||
|
|
@ -548,8 +560,14 @@ describe("DataTreeEvaluator", () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const evaluator = new DataTreeEvaluator(WIDGET_CONFIG_MAP);
|
const evaluator = new DataTreeEvaluator(WIDGET_CONFIG_MAP);
|
||||||
|
|
||||||
|
it("Checks the number of clone operations in first tree flow", () => {
|
||||||
evaluator.setupFirstTree(unEvalTree, configTree);
|
evaluator.setupFirstTree(unEvalTree, configTree);
|
||||||
evaluator.evalAndValidateFirstTree();
|
evaluator.evalAndValidateFirstTree();
|
||||||
|
// Hard check to not regress on the number of clone operations. Try to improve this number.
|
||||||
|
expect(klonaFullSpy).toBeCalledTimes(41);
|
||||||
|
});
|
||||||
|
|
||||||
it("Evaluates a binding in first run", () => {
|
it("Evaluates a binding in first run", () => {
|
||||||
const evaluation = evaluator.evalTree;
|
const evaluation = evaluator.evalTree;
|
||||||
const dependencies = evaluator.dependencies;
|
const dependencies = evaluator.dependencies;
|
||||||
|
|
@ -1021,4 +1039,38 @@ describe("DataTreeEvaluator", () => {
|
||||||
expect(dataTree).toHaveProperty("TextX.text", 123);
|
expect(dataTree).toHaveProperty("TextX.text", 123);
|
||||||
expect(dataTree).toHaveProperty("Text1.text", "Label");
|
expect(dataTree).toHaveProperty("Text1.text", "Label");
|
||||||
});
|
});
|
||||||
|
it("Checks the number of clone operations performed in update tree flow", () => {
|
||||||
|
const { configEntity, unEvalEntity } = generateDataTreeWidget(
|
||||||
|
{
|
||||||
|
...BASE_WIDGET_CONFIG,
|
||||||
|
...BASE_WIDGET,
|
||||||
|
widgetName: "TextY",
|
||||||
|
text: "{{Text1.text = 123}}",
|
||||||
|
dynamicBindingPathList: [{ key: "text" }],
|
||||||
|
type: "TEXT_WIDGET",
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
new Set(),
|
||||||
|
);
|
||||||
|
const updatedUnEvalTree = {
|
||||||
|
...unEvalTree,
|
||||||
|
TextY: unEvalEntity,
|
||||||
|
};
|
||||||
|
const updatedConfigTree = {
|
||||||
|
...configTree,
|
||||||
|
TextY: configEntity,
|
||||||
|
};
|
||||||
|
const { evalOrder, nonDynamicFieldValidationOrder, unEvalUpdates } =
|
||||||
|
evaluator.setupUpdateTree(updatedUnEvalTree, updatedConfigTree);
|
||||||
|
expect(evalOrder).toContain("TextY.text");
|
||||||
|
expect(evalOrder.length).toBe(2);
|
||||||
|
evaluator.evalAndValidateSubTree(
|
||||||
|
evalOrder,
|
||||||
|
nonDynamicFieldValidationOrder,
|
||||||
|
updatedConfigTree,
|
||||||
|
unEvalUpdates,
|
||||||
|
);
|
||||||
|
// Hard check to not regress on the number of clone operations. Try to improve this number.
|
||||||
|
expect(klonaFullSpy).toBeCalledTimes(7);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user