## Description Split canvasWidgetsReducer and canvasWidgetsStructureReducer for UI modules Fixes https://github.com/appsmithorg/appsmith/issues/39326 ## 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/13385385883> > Commit: ec13bb0625735d4a0c1b918fd785b3a5ea858245 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13385385883&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Tue, 18 Feb 2025 08:41:34 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Streamlined internal dependency management and reorganized module paths for improved maintainability. - Updated import paths for `CanvasWidgetsReduxState`, `FlattenedWidgetProps`, and related types to reflect a new organizational structure. - These behind-the-scenes changes do not affect any user-visible functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
203 lines
4.9 KiB
TypeScript
203 lines
4.9 KiB
TypeScript
import type { CanvasWidgetsReduxState } from "ee/reducers/entityReducers/canvasWidgetsReducer";
|
|
import {
|
|
deselectAll,
|
|
pushPopWidgetSelection,
|
|
selectMultipleWidgets,
|
|
selectOneWidget,
|
|
shiftSelectWidgets,
|
|
unselectWidget,
|
|
} from "./WidgetSelectUtils";
|
|
|
|
describe("Wigdet selection methods", () => {
|
|
const allWidgetsMock: CanvasWidgetsReduxState = {
|
|
widgetId1: {
|
|
widgetId: "widgetId1",
|
|
parentId: "0",
|
|
type: "BUTTON_WIDGET",
|
|
widgetName: "Button1",
|
|
version: 0,
|
|
renderMode: "CANVAS",
|
|
parentColumnSpace: 0,
|
|
parentRowSpace: 0,
|
|
leftColumn: 0,
|
|
rightColumn: 0,
|
|
topRow: 0,
|
|
bottomRow: 0,
|
|
isLoading: false,
|
|
},
|
|
widgetId2: {
|
|
widgetId: "widgetId2",
|
|
parentId: "0",
|
|
type: "BUTTON_WIDGET",
|
|
widgetName: "Button2",
|
|
version: 0,
|
|
renderMode: "CANVAS",
|
|
parentColumnSpace: 0,
|
|
parentRowSpace: 0,
|
|
leftColumn: 0,
|
|
rightColumn: 0,
|
|
topRow: 0,
|
|
bottomRow: 0,
|
|
isLoading: false,
|
|
},
|
|
widgetId3: {
|
|
widgetId: "widgetId3",
|
|
parentId: "1",
|
|
type: "BUTTON_WIDGET",
|
|
widgetName: "Button3",
|
|
version: 0,
|
|
renderMode: "CANVAS",
|
|
parentColumnSpace: 0,
|
|
parentRowSpace: 0,
|
|
leftColumn: 0,
|
|
rightColumn: 0,
|
|
topRow: 0,
|
|
bottomRow: 0,
|
|
isLoading: false,
|
|
},
|
|
};
|
|
|
|
describe("Deselect", () => {
|
|
it("returns an empty selection", () => {
|
|
const result = deselectAll([]);
|
|
|
|
expect(result).toStrictEqual([]);
|
|
});
|
|
it("will error out when request has any widgets", () => {
|
|
expect(() => deselectAll(["any"])).toThrow("Wrong payload supplied");
|
|
});
|
|
});
|
|
|
|
describe("Select One", () => {
|
|
it("returns a selection", () => {
|
|
const result = selectOneWidget(["widgetId"]);
|
|
|
|
expect(result).toStrictEqual(["widgetId"]);
|
|
});
|
|
it("will error out when wrong payload supplied", () => {
|
|
expect(() => selectOneWidget([])).toThrow("Wrong payload supplied");
|
|
expect(() => selectOneWidget(["widgetId1", "widgetId2"])).toThrow(
|
|
"Wrong payload supplied",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("Select Multiple", () => {
|
|
it("returns a selection", () => {
|
|
const result = selectMultipleWidgets(
|
|
["widgetId1", "widgetId2"],
|
|
allWidgetsMock,
|
|
);
|
|
|
|
expect(result).toStrictEqual(["widgetId1", "widgetId2"]);
|
|
});
|
|
|
|
it("returns no selection if widgets are not siblings", () => {
|
|
const result = selectMultipleWidgets(
|
|
["widgetId1", "widgetId3"],
|
|
allWidgetsMock,
|
|
);
|
|
|
|
expect(result).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe("Shift Select", () => {
|
|
it("forward selection", () => {
|
|
const result = shiftSelectWidgets(
|
|
["w5"],
|
|
["w1", "w2", "w3", "w4", "w5"],
|
|
["w1"],
|
|
"w1",
|
|
);
|
|
|
|
expect(result).toStrictEqual(["w1", "w5", "w2", "w3", "w4"]);
|
|
});
|
|
|
|
it("backwards selection", () => {
|
|
const result = shiftSelectWidgets(
|
|
["w2"],
|
|
["w1", "w2", "w3", "w4", "w5"],
|
|
["w5"],
|
|
"w5",
|
|
);
|
|
|
|
expect(result).toStrictEqual(["w5", "w2", "w3", "w4"]);
|
|
});
|
|
|
|
it("appended selection on overlap", () => {
|
|
const result = shiftSelectWidgets(
|
|
["w1"],
|
|
["w1", "w2", "w3", "w4", "w5"],
|
|
["w5", "w3"],
|
|
"w5",
|
|
);
|
|
|
|
expect(result).toStrictEqual(["w5", "w3", "w1", "w2", "w4"]);
|
|
});
|
|
|
|
it("a single selection when last selected is not a sibling", () => {
|
|
const result = shiftSelectWidgets(
|
|
["w2"],
|
|
["w1", "w2", "w3", "w4", "w5"],
|
|
["w7"],
|
|
"w7",
|
|
);
|
|
|
|
expect(result).toStrictEqual(["w2"]);
|
|
});
|
|
|
|
it("unselect when already selected", () => {
|
|
const result = shiftSelectWidgets(
|
|
["w2"],
|
|
["w1", "w2", "w3", "w4", "w5"],
|
|
["w1", "w2"],
|
|
"w2",
|
|
);
|
|
|
|
expect(result).toStrictEqual(["w1"]);
|
|
});
|
|
});
|
|
describe("Push Pop Select", () => {
|
|
it("adds a selection", () => {
|
|
const result = pushPopWidgetSelection(
|
|
["w1"],
|
|
["w2", "w3"],
|
|
["w1", "w2", "w3"],
|
|
);
|
|
|
|
expect(result).toStrictEqual(["w2", "w3", "w1"]);
|
|
});
|
|
|
|
it("removes a selection", () => {
|
|
const result = pushPopWidgetSelection(
|
|
["w1"],
|
|
["w2", "w1"],
|
|
["w1", "w2", "w3"],
|
|
);
|
|
|
|
expect(result).toStrictEqual(["w2"]);
|
|
});
|
|
|
|
it("removes other if new selection is not a sibling", () => {
|
|
const result = pushPopWidgetSelection(["w1"], ["w3", "w4"], ["w1", "w2"]);
|
|
|
|
expect(result).toStrictEqual(["w1"]);
|
|
});
|
|
});
|
|
|
|
describe("UnSelect", () => {
|
|
it("returns selection without the widget", () => {
|
|
const result = unselectWidget(["w1"], ["w1", "w2", "w3"]);
|
|
|
|
expect(result).toStrictEqual(["w2", "w3"]);
|
|
});
|
|
|
|
it("returns selection even if not selected", () => {
|
|
const result = unselectWidget(["w1"], ["w2", "w3"]);
|
|
|
|
expect(result).toStrictEqual(["w2", "w3"]);
|
|
});
|
|
});
|
|
});
|