Skip to content

Commit

Permalink
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
Browse files Browse the repository at this point in the history
…o overflow-tabs-list-view
  • Loading branch information
albinAppsmith committed Jun 24, 2024
2 parents 77611ad + cb89dda commit 7d07044
Show file tree
Hide file tree
Showing 5 changed files with 356 additions and 10 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build-client-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ jobs:
secrets: inherit
with:
pr: ${{fromJson(needs.file-check.outputs.pr)}}
matrix: ${{needs.file-check.outputs.matrix_count}}

ci-test-limited-existing-docker-image:
needs: [file-check]
Expand All @@ -143,7 +142,6 @@ jobs:
with:
pr: ${{fromJson(needs.file-check.outputs.pr)}}
previous-workflow-run-id: ${{ fromJson(needs.file-check.outputs.runId) }}
matrix: ${{ needs.file-check.outputs.matrix_count }}

ci-test-limited-result:
needs: [file-check, ci-test-limited]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
import { select } from "redux-saga/effects";
import { addWidgetsSaga, moveWidgetsSaga } from ".";
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
import { generateReactKey } from "@shared/dsl/src/migrate/utils";
import { LayoutComponentTypes } from "layoutSystems/anvil/utils/anvilTypes";
import { expectSaga } from "redux-saga-test-plan";
import { getWidgets } from "sagas/selectors";
import { registerWidgets } from "WidgetProvider/factory/registrationHelper";
import { SectionWidget } from "widgets/anvil/SectionWidget";
import { ZoneWidget } from "widgets/anvil/ZoneWidget";
import { WDSButtonWidget } from "widgets/wds/WDSButtonWidget";
import {
getCanvasWidth,
getIsAutoLayoutMobileBreakPoint,
} from "selectors/editorSelectors";
import { getCurrentlyOpenAnvilDetachedWidgets } from "../../modalSelectors";
import { getDataTree } from "selectors/dataTreeSelectors";
import { getLayoutSystemType } from "selectors/layoutSystemSelectors";
import { registerLayoutComponents } from "layoutSystems/anvil/utils/layouts/layoutUtils";
import { getIsAnvilLayout } from "../../selectors";
import { selectWidgetInitAction } from "actions/widgetSelectionActions";
import { SelectionRequestType } from "sagas/WidgetSelectUtils";
import { WDSModalWidget } from "widgets/wds/WDSModalWidget";
import { generateMockDataWithTwoSections } from "./mockData.helper";
import type { AnvilMoveWidgetsPayload } from "../../actions/actionTypes";
import {
AnvilReduxActionTypes,
type AnvilNewWidgetsPayload,
} from "../../actions/actionTypes";
import { AnvilDraggedWidgetTypesEnum } from "layoutSystems/anvil/editor/canvasArenas/types";
import {
FlexLayerAlignment,
ResponsiveBehavior,
} from "layoutSystems/common/utils/constants";
import { mockAnvilHighlightInfo } from "mocks/mockHighlightInfo";

describe("", () => {
beforeAll(() => {
registerLayoutComponents();
registerWidgets([
SectionWidget,
ZoneWidget,
WDSButtonWidget,
WDSModalWidget,
]);
});
// Successfully adds a new widget to the main canvas
it("should successfully add a new widget to the main canvas", async () => {
const mainCanvasLayoutId = generateReactKey();
const newWidgetId = generateReactKey();
const allWidgets: any = {
[MAIN_CONTAINER_WIDGET_ID]: {
widgetName: "Main Container",
widgetId: MAIN_CONTAINER_WIDGET_ID,
children: [],
layout: [
{
layoutId: mainCanvasLayoutId,
layoutType: LayoutComponentTypes.ALIGNED_LAYOUT_COLUMN,
layout: [],
},
],
},
};
const payload: AnvilNewWidgetsPayload = {
dragMeta: {
draggedOn: "MAIN_CANVAS",
draggedWidgetTypes: AnvilDraggedWidgetTypesEnum.WIDGETS,
},
highlight: mockAnvilHighlightInfo({
alignment: FlexLayerAlignment.Start,
canvasId: MAIN_CONTAINER_WIDGET_ID,
layoutId: mainCanvasLayoutId,
layoutOrder: [mainCanvasLayoutId],
}),
newWidget: {
width: 100,
height: 50,
newWidgetId,
type: "WDS_BUTTON_WIDGET",
detachFromLayout: false,
},
};
const actionPayload = {
type: AnvilReduxActionTypes.ANVIL_ADD_NEW_WIDGET,
payload,
};
const { effects } = await expectSaga(addWidgetsSaga, actionPayload)
.provide([
[select(getWidgets), allWidgets],
[select(getCanvasWidth), 100],
[select(getIsAutoLayoutMobileBreakPoint), false],
[select(getCurrentlyOpenAnvilDetachedWidgets), []],
[select(getDataTree), {}],
[select(getLayoutSystemType), "ANVIL"],
[select(getIsAnvilLayout), true],
])
.run();
const widgetSelectPutEffect = effects.put[effects.put.length - 1];
expect(widgetSelectPutEffect.payload.action).toEqual(
selectWidgetInitAction(SelectionRequestType.Create, [newWidgetId]),
);
const updateWidgetsPutEffect = effects.put[effects.put.length - 2];
expect(updateWidgetsPutEffect.payload.action.type).toBe("UPDATE_LAYOUT");
// check if new widget was added to main canvas by wrapping it in a section and zone
const updatedWidgets =
updateWidgetsPutEffect.payload.action.payload.widgets;
const mainCanvasWidget = updatedWidgets[MAIN_CONTAINER_WIDGET_ID];
const sectionWidgetId = mainCanvasWidget.children[0];
const sectionWidget = updatedWidgets[sectionWidgetId];
const zoneWidgetId = sectionWidget.children[0];
const zoneWidget = updatedWidgets[zoneWidgetId];
expect(zoneWidget.children).toContain(newWidgetId);
});
it("should successfully add a new modal widget to the main canvas", async () => {
const mainCanvasLayoutId = generateReactKey();
const newModalId = generateReactKey();
const allWidgets: any = {
[MAIN_CONTAINER_WIDGET_ID]: {
widgetName: "Main Container",
widgetId: MAIN_CONTAINER_WIDGET_ID,
children: [],
layout: [
{
layoutId: mainCanvasLayoutId,
layoutType: LayoutComponentTypes.ALIGNED_LAYOUT_COLUMN,
layout: [],
},
],
},
};
const payload: AnvilNewWidgetsPayload = {
dragMeta: {
draggedOn: "MAIN_CANVAS",
draggedWidgetTypes: AnvilDraggedWidgetTypesEnum.WIDGETS,
},
highlight: mockAnvilHighlightInfo({
alignment: FlexLayerAlignment.Start,
canvasId: MAIN_CONTAINER_WIDGET_ID,
layoutId: mainCanvasLayoutId,
layoutOrder: [mainCanvasLayoutId],
}),
newWidget: {
width: 100,
height: 50,
newWidgetId: newModalId,
type: "WDS_MODAL_WIDGET",
detachFromLayout: true,
},
};
const actionPayload = {
type: AnvilReduxActionTypes.ANVIL_ADD_NEW_WIDGET,
payload,
};

const { effects } = await expectSaga(addWidgetsSaga, actionPayload)
.provide([
[select(getWidgets), allWidgets],
[select(getCanvasWidth), 100],
[select(getIsAutoLayoutMobileBreakPoint), false],
[select(getCurrentlyOpenAnvilDetachedWidgets), []],
[select(getDataTree), {}],
[select(getLayoutSystemType), "ANVIL"],
[select(getIsAnvilLayout), true],
])
.run();
const widgetSelectPutEffect = effects.put[effects.put.length - 1];
expect(widgetSelectPutEffect.payload.action).toEqual(
selectWidgetInitAction(SelectionRequestType.Create, [newModalId]),
);
const updateWidgetsPutEffect = effects.put[effects.put.length - 2];
expect(updateWidgetsPutEffect.payload.action.type).toBe("UPDATE_LAYOUT");
// check if new widget was added to main canvas by wrapping it in a section and zone
const updatedWidgets =
updateWidgetsPutEffect.payload.action.payload.widgets;
const mainCanvasWidget = updatedWidgets[MAIN_CONTAINER_WIDGET_ID];
const modalWidgetId = mainCanvasWidget.children[0];
expect(modalWidgetId).toContain(newModalId);
});

it("should successfully move widget to the main canvas", async () => {
const { allWidgets, mainCanvasLayoutId, section1Id, section2Id } =
generateMockDataWithTwoSections();
const payload: AnvilMoveWidgetsPayload = {
dragMeta: {
draggedOn: "MAIN_CANVAS",
draggedWidgetTypes: AnvilDraggedWidgetTypesEnum.SECTION,
},
movedWidgets: [
{
widgetId: section2Id,
type: "SECTION_WIDGET",
parentId: MAIN_CONTAINER_WIDGET_ID,
responsiveBehavior: ResponsiveBehavior.Fill,
},
],
highlight: mockAnvilHighlightInfo({
alignment: FlexLayerAlignment.Start,
rowIndex: 0,
canvasId: MAIN_CONTAINER_WIDGET_ID,
layoutId: mainCanvasLayoutId,
layoutOrder: [mainCanvasLayoutId],
}),
};
const actionPayload = {
type: AnvilReduxActionTypes.ANVIL_MOVE_WIDGET,
payload,
};
const { effects } = await expectSaga(moveWidgetsSaga, actionPayload)
.provide([
[select(getWidgets), allWidgets],
[select(getCanvasWidth), 100],
[select(getIsAutoLayoutMobileBreakPoint), false],
[select(getCurrentlyOpenAnvilDetachedWidgets), []],
[select(getDataTree), {}],
[select(getLayoutSystemType), "ANVIL"],
[select(getIsAnvilLayout), true],
])
.run();
const updateWidgetsPutEffect = effects.put[effects.put.length - 1];
expect(updateWidgetsPutEffect.payload.action.type).toBe("UPDATE_LAYOUT");
// expect section2 to be moved to the first position in layout
const updatedWidgets =
updateWidgetsPutEffect.payload.action.payload.widgets;
const mainCanvasWidget = updatedWidgets[MAIN_CONTAINER_WIDGET_ID];
const mainCanvasLayout = mainCanvasWidget.layout[0];
const firstWidgetRow = mainCanvasLayout.layout[0];
const secondWidgetRow = mainCanvasLayout.layout[1];
expect(firstWidgetRow.layout[0].widgetId).toBe(section2Id);
expect(secondWidgetRow.layout[0].widgetId).toBe(section1Id);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import type {
WidgetLayoutProps,
} from "layoutSystems/anvil/utils/anvilTypes";
import { getWidget, getWidgets } from "sagas/selectors";
import { addWidgetsToPreset } from "../../utils/layouts/update/additionUtils";
import { addWidgetsToPreset } from "../../../utils/layouts/update/additionUtils";
import type {
AnvilMoveWidgetsPayload,
AnvilNewWidgetsPayload,
} from "../actions/actionTypes";
import { AnvilReduxActionTypes } from "../actions/actionTypes";
} from "../../actions/actionTypes";
import { AnvilReduxActionTypes } from "../../actions/actionTypes";
import { generateDefaultLayoutPreset } from "layoutSystems/anvil/layoutComponents/presets/DefaultLayoutPreset";
import { selectWidgetInitAction } from "actions/widgetSelectionActions";
import { SelectionRequestType } from "sagas/WidgetSelectUtils";
Expand All @@ -39,7 +39,7 @@ import {
addNewWidgetToDsl,
getCreateWidgetPayload,
} from "layoutSystems/anvil/utils/widgetAdditionUtils";
import { updateAndSaveAnvilLayout } from "../../utils/anvilChecksUtils";
import { updateAndSaveAnvilLayout } from "../../../utils/anvilChecksUtils";
import { moveWidgetsToZone } from "layoutSystems/anvil/utils/layouts/update/zoneUtils";

// Function to retrieve highlighting information for the last row in the main canvas layout
Expand Down Expand Up @@ -201,7 +201,9 @@ export function* addNewChildToDSL(
}

// function to handle the addition of new widgets to the Anvil layout
function* addWidgetsSaga(actionPayload: ReduxAction<AnvilNewWidgetsPayload>) {
export function* addWidgetsSaga(
actionPayload: ReduxAction<AnvilNewWidgetsPayload>,
) {
try {
const start = performance.now();

Expand Down Expand Up @@ -297,7 +299,9 @@ function* addWidgetToGenericLayout(
* Remove widgets from current parents and layouts.
* Add to new parent and layout.
*/
function* moveWidgetsSaga(actionPayload: ReduxAction<AnvilMoveWidgetsPayload>) {
export function* moveWidgetsSaga(
actionPayload: ReduxAction<AnvilMoveWidgetsPayload>,
) {
try {
const start = performance.now();
const {
Expand Down
Loading

0 comments on commit 7d07044

Please sign in to comment.