PromucFlow_constructor/app/client/src/sagas/SnipingModeSaga.test.ts

111 lines
3.4 KiB
TypeScript
Raw Normal View History

import type { ModuleInstance } from "ee/constants/ModuleInstanceConstants";
fix: sniping mode for module to bind to existing and new widgets (#35072) ## Description Fixes sniping for module instances. For binding to widgets, the module instance id and moduleInstance name was to be passed to the `BindDataButton` component. Fixes https://github.com/appsmithorg/appsmith/issues/31957 ## Automation /ok-to-test tags="@tag.All" ### :mag: 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/10056587287> > Commit: 74ec4dc42fee3ca211037c60753aee4c869a4e83 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10056587287&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Tue, 23 Jul 2024 10:37:32 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [x] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced new `apiName` prop in the `ApiResponseView` component for enhanced flexibility in API response rendering. - Added `moduleInstanceId` to `BindDataButtonProps` for improved data binding context. - Enhanced `QueryResponseTab` components by adding `actionName` prop, improving functionality and display. - **Bug Fixes** - Updated logic in `QueryResponseTab` to allow for fallback to `actionName` when rendering, enhancing adaptability. - **Tests** - Added a comprehensive test suite for `bindDataToWidgetSaga` to ensure expected behavior and integration with Redux state management. - **Refactor** - Improved the logic in `bindDataToWidgetSaga` to utilize `actionName`, streamlining the data binding process. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-07-23 11:06:22 +00:00
import { keyBy } from "lodash";
import { testStore } from "store";
import { PostgresFactory } from "test/factories/Actions/Postgres";
import type { Saga } from "redux-saga";
import { runSaga } from "redux-saga";
import { bindDataToWidgetSaga } from "./SnipingModeSagas";
import { ReduxActionTypes } from "ee/constants/ReduxActionConstants";
import { getModuleInstanceById } from "ee/selectors/moduleInstanceSelectors";
fix: sniping mode for module to bind to existing and new widgets (#35072) ## Description Fixes sniping for module instances. For binding to widgets, the module instance id and moduleInstance name was to be passed to the `BindDataButton` component. Fixes https://github.com/appsmithorg/appsmith/issues/31957 ## Automation /ok-to-test tags="@tag.All" ### :mag: 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/10056587287> > Commit: 74ec4dc42fee3ca211037c60753aee4c869a4e83 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10056587287&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Tue, 23 Jul 2024 10:37:32 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [x] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced new `apiName` prop in the `ApiResponseView` component for enhanced flexibility in API response rendering. - Added `moduleInstanceId` to `BindDataButtonProps` for improved data binding context. - Enhanced `QueryResponseTab` components by adding `actionName` prop, improving functionality and display. - **Bug Fixes** - Updated logic in `QueryResponseTab` to allow for fallback to `actionName` when rendering, enhancing adaptability. - **Tests** - Added a comprehensive test suite for `bindDataToWidgetSaga` to ensure expected behavior and integration with Redux state management. - **Refactor** - Improved the logic in `bindDataToWidgetSaga` to utilize `actionName`, streamlining the data binding process. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-07-23 11:06:22 +00:00
import WidgetFactory from "WidgetProvider/factory";
import TableWidget from "widgets/TableWidget/widget";
import { InputFactory } from "test/factories/Widgets/InputFactory";
jest.mock("ee/selectors/moduleInstanceSelectors", () => ({
...jest.requireActual("ee/selectors/moduleInstanceSelectors"),
fix: sniping mode for module to bind to existing and new widgets (#35072) ## Description Fixes sniping for module instances. For binding to widgets, the module instance id and moduleInstance name was to be passed to the `BindDataButton` component. Fixes https://github.com/appsmithorg/appsmith/issues/31957 ## Automation /ok-to-test tags="@tag.All" ### :mag: 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/10056587287> > Commit: 74ec4dc42fee3ca211037c60753aee4c869a4e83 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10056587287&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Tue, 23 Jul 2024 10:37:32 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [x] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced new `apiName` prop in the `ApiResponseView` component for enhanced flexibility in API response rendering. - Added `moduleInstanceId` to `BindDataButtonProps` for improved data binding context. - Enhanced `QueryResponseTab` components by adding `actionName` prop, improving functionality and display. - **Bug Fixes** - Updated logic in `QueryResponseTab` to allow for fallback to `actionName` when rendering, enhancing adaptability. - **Tests** - Added a comprehensive test suite for `bindDataToWidgetSaga` to ensure expected behavior and integration with Redux state management. - **Refactor** - Improved the logic in `bindDataToWidgetSaga` to utilize `actionName`, streamlining the data binding process. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-07-23 11:06:22 +00:00
getModuleInstanceById: jest.fn(),
}));
describe("SnipingModeSaga", () => {
beforeEach(() => {
jest.restoreAllMocks();
});
it("should check for moduleInstance and use when action is missing", async () => {
const widget = InputFactory.build();
const action = PostgresFactory.build();
const moduleInstance = {
id: "module-instance-id",
name: "ModuleInstance1",
} as ModuleInstance;
(getModuleInstanceById as jest.Mock).mockReturnValue(moduleInstance);
const spy = jest
.spyOn(WidgetFactory, "getWidgetMethods")
.mockImplementation(TableWidget.getMethods);
const store = testStore({
entities: {
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fix: sniping mode for module to bind to existing and new widgets (#35072) ## Description Fixes sniping for module instances. For binding to widgets, the module instance id and moduleInstance name was to be passed to the `BindDataButton` component. Fixes https://github.com/appsmithorg/appsmith/issues/31957 ## Automation /ok-to-test tags="@tag.All" ### :mag: 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/10056587287> > Commit: 74ec4dc42fee3ca211037c60753aee4c869a4e83 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10056587287&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Tue, 23 Jul 2024 10:37:32 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [x] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced new `apiName` prop in the `ApiResponseView` component for enhanced flexibility in API response rendering. - Added `moduleInstanceId` to `BindDataButtonProps` for improved data binding context. - Enhanced `QueryResponseTab` components by adding `actionName` prop, improving functionality and display. - **Bug Fixes** - Updated logic in `QueryResponseTab` to allow for fallback to `actionName` when rendering, enhancing adaptability. - **Tests** - Added a comprehensive test suite for `bindDataToWidgetSaga` to ensure expected behavior and integration with Redux state management. - **Refactor** - Improved the logic in `bindDataToWidgetSaga` to utilize `actionName`, streamlining the data binding process. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-07-23 11:06:22 +00:00
...({} as any),
actions: [
{
config: action,
},
],
canvasWidgets: keyBy([widget], "widgetId"),
},
ui: {
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fix: sniping mode for module to bind to existing and new widgets (#35072) ## Description Fixes sniping for module instances. For binding to widgets, the module instance id and moduleInstance name was to be passed to the `BindDataButton` component. Fixes https://github.com/appsmithorg/appsmith/issues/31957 ## Automation /ok-to-test tags="@tag.All" ### :mag: 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/10056587287> > Commit: 74ec4dc42fee3ca211037c60753aee4c869a4e83 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10056587287&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Tue, 23 Jul 2024 10:37:32 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [x] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced new `apiName` prop in the `ApiResponseView` component for enhanced flexibility in API response rendering. - Added `moduleInstanceId` to `BindDataButtonProps` for improved data binding context. - Enhanced `QueryResponseTab` components by adding `actionName` prop, improving functionality and display. - **Bug Fixes** - Updated logic in `QueryResponseTab` to allow for fallback to `actionName` when rendering, enhancing adaptability. - **Tests** - Added a comprehensive test suite for `bindDataToWidgetSaga` to ensure expected behavior and integration with Redux state management. - **Refactor** - Improved the logic in `bindDataToWidgetSaga` to utilize `actionName`, streamlining the data binding process. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-07-23 11:06:22 +00:00
...({} as any),
editor: {
snipModeBindTo: "module-instance-id",
},
},
});
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fix: sniping mode for module to bind to existing and new widgets (#35072) ## Description Fixes sniping for module instances. For binding to widgets, the module instance id and moduleInstance name was to be passed to the `BindDataButton` component. Fixes https://github.com/appsmithorg/appsmith/issues/31957 ## Automation /ok-to-test tags="@tag.All" ### :mag: 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/10056587287> > Commit: 74ec4dc42fee3ca211037c60753aee4c869a4e83 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10056587287&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Tue, 23 Jul 2024 10:37:32 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [x] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced new `apiName` prop in the `ApiResponseView` component for enhanced flexibility in API response rendering. - Added `moduleInstanceId` to `BindDataButtonProps` for improved data binding context. - Enhanced `QueryResponseTab` components by adding `actionName` prop, improving functionality and display. - **Bug Fixes** - Updated logic in `QueryResponseTab` to allow for fallback to `actionName` when rendering, enhancing adaptability. - **Tests** - Added a comprehensive test suite for `bindDataToWidgetSaga` to ensure expected behavior and integration with Redux state management. - **Refactor** - Improved the logic in `bindDataToWidgetSaga` to utilize `actionName`, streamlining the data binding process. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-07-23 11:06:22 +00:00
const dispatched: any[] = [];
await runSaga(
{
dispatch: (action) => dispatched.push(action),
getState: () => store.getState(),
},
bindDataToWidgetSaga as Saga,
{ payload: { widgetId: widget.widgetId, bindingQuery: "data" } },
).toPromise();
expect(dispatched).toEqual([
{
payload: {
updates: [
{
isDynamic: true,
propertyPath: "tableData",
skipValidation: true,
},
],
widgetId: widget.widgetId,
},
type: ReduxActionTypes.BATCH_SET_WIDGET_DYNAMIC_PROPERTY,
},
{
payload: {
shouldReplay: true,
updates: { modify: { tableData: `{{${moduleInstance.name}.data}}` } },
widgetId: widget.widgetId,
},
type: ReduxActionTypes.BATCH_UPDATE_WIDGET_PROPERTY,
},
{
payload: { bindTo: undefined, isActive: false },
type: ReduxActionTypes.SET_SNIPING_MODE,
},
{
payload: {
invokedBy: undefined,
pageId: undefined,
payload: [widget.widgetId],
selectionRequestType: "One",
},
type: ReduxActionTypes.SELECT_WIDGET_INIT,
},
]);
spy.mockRestore();
});
});