PromucFlow_constructor/app/client/src/sagas/WidgetOperationSaga.test.tsx
Sangeeth Sivan ef69dbd259
chore: Make use of widget methods to get binding properties in sniping mode (#25429)
## Description
- Refactoring sniping mode code to fix abstraction leak and to optimise
the process further.
#### PR fixes following issue(s)
Fixes #24737 
#### 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?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [x] Manual
- [x] Jest
- [x] Cypress
>
>
#### 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
- [x] 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
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] 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
2023-07-26 11:08:11 +05:30

298 lines
7.6 KiB
TypeScript

const updateAndSaveLayoutMock = jest.fn();
import {
setWidgetDynamicPropertySaga,
removeDynamicBindingProperties,
handleUpdateWidgetDynamicProperty,
batchUpdateWidgetDynamicPropertySaga,
} from "./WidgetOperationSagas";
const widget = {
isVisible: "true",
dynamicPropertyPathList: [],
dynamicBindingPathList: [],
};
const widget1 = {
isVisible: "{{true}}",
dynamicPropertyPathList: [
{
key: "isVisible",
},
],
dynamicBindingPathList: [
{
key: "isVisible",
},
],
};
jest.mock("redux-saga/effects", () => {
const originalModule = jest.requireActual("redux-saga/effects");
return {
__esModule: true,
...originalModule,
select: jest.fn(),
call: jest.fn(),
put: jest.fn(),
};
});
jest.mock("actions/pageActions", () => {
const originalModule = jest.requireActual("actions/pageActions");
return {
__esModule: true,
...originalModule,
updateAndSaveLayout: updateAndSaveLayoutMock,
};
});
describe("WidgetOperationSaga - ", () => {
describe("Should test setWidgetDynamicPropertySaga ", () => {
it("should update dynamicBindingPathList on js toggle", () => {
const value = setWidgetDynamicPropertySaga({
type: "test",
payload: {
isDynamic: true,
propertyPath: "isVisible",
widgetId: "test",
},
});
value.next(); // start
value.next(widget as any); // yield select
value.next({
...widget,
dynamicPropertyPathList: [
{
key: "isVisible",
},
],
} as any);
value.next({
test: widget,
} as any); // yield select
value.next(); //yield put
expect(updateAndSaveLayoutMock).toHaveBeenCalledWith({
test: {
...widget,
dynamicPropertyPathList: [
{
key: "isVisible",
},
],
},
});
});
it("should remove property from dynamicBindingList on js toggle off", () => {
const value = setWidgetDynamicPropertySaga({
type: "test",
payload: {
isDynamic: false,
propertyPath: "isVisible",
widgetId: "test",
},
});
value.next(); // start
value.next(widget1 as any); // yield select
value.next({
...widget1,
dynamicPropertyPathList: [],
dynamicBindingPathList: [],
isVisible: 1,
} as any);
value.next({
test: widget1,
} as any); // yield select
value.next(); //yield put
expect(updateAndSaveLayoutMock).toHaveBeenCalledWith({
test: {
dynamicPropertyPathList: [],
dynamicBindingPathList: [],
isVisible: 1,
},
});
});
});
});
describe("Should test handleUpdateWidgetDynamicProperty ", () => {
it("should update dynamicBindingPathList on js toggle and return the widget with dynamicBindingPath", () => {
const value = handleUpdateWidgetDynamicProperty(widget as any, {
isDynamic: true,
propertyPath: "isVisible",
});
value.next(); // start
value.next(widget as any); // yield select
value.next({
test: widget,
} as any); // yield select
value.return({
test: {
...widget,
dynamicPropertyPathList: [
{
key: "isVisible",
},
],
},
} as any);
expect(value.next().done).toEqual(true);
});
});
describe("Should test batchUpdateWidgetDynamicPropertySaga ", () => {
it("should update dynamicBindingPathList on js toggle and return the widget with dynamicBindingPath", () => {
const value = batchUpdateWidgetDynamicPropertySaga({
type: "test",
payload: {
updates: [
{
isDynamic: true,
propertyPath: "isVisible",
},
],
widgetId: "test",
},
});
value.next(); // start
value.next(widget as any); // yield select
value.next({
...widget,
dynamicPropertyPathList: [
{
key: "isVisible",
},
],
} as any);
value.next({
test: widget,
} as any); // yield select
value.next(); //yield put
expect(updateAndSaveLayoutMock).toHaveBeenCalledWith({
test: {
...widget,
dynamicPropertyPathList: [
{
key: "isVisible",
},
],
},
});
});
it("should remove property from dynamicBindingList on js toggle off when calling batchUpdateWidgetDynamicPropertySaga", () => {
const value = batchUpdateWidgetDynamicPropertySaga({
type: "test",
payload: {
updates: [
{
isDynamic: false,
propertyPath: "isVisible",
},
],
widgetId: "test",
},
});
value.next(); // start
value.next(widget1 as any); // yield select
value.next({
...widget1,
dynamicPropertyPathList: [],
dynamicBindingPathList: [],
isVisible: 1,
} as any);
value.next({
test: widget1,
} as any); // yield select
value.next(); //yield put
expect(updateAndSaveLayoutMock).toHaveBeenCalledWith({
test: {
dynamicPropertyPathList: [],
dynamicBindingPathList: [],
isVisible: 1,
},
});
});
});
describe("test removeDynamicBindingList", () => {
it("should remove table derived binding properties", () => {
// table bindings with derived properties
const dynamicBindingList = [
{ key: "primaryColumns.step.computedValue" },
{ key: "primaryColumns.task.computedValue" },
{ key: "primaryColumns.status.computedValue" },
{ key: "primaryColumns.action.computedValue" },
{ key: "derivedColumns.customColumn1.isCellVisible" },
{ key: "primaryColumns.customColumn1.isCellVisible" },
];
const propertyPath = "primaryColumns.customColumn1.isCellVisible";
const dynamicProperties = removeDynamicBindingProperties(
propertyPath,
dynamicBindingList,
);
// should remove custom and derived properties for customColumn1.isCellVisible
expect(dynamicProperties).not.toEqual(
expect.arrayContaining([
expect.objectContaining({
key: "derivedColumns.customColumn1.isCellVisible",
}),
expect.objectContaining({
key: "primaryColumns.customColumn1.isCellVisible",
}),
]),
);
});
it("should remove table binding properties", () => {
// table bindings
const dynamicBindingList = [
{ key: "primaryColumns.step.computedValue" },
{ key: "primaryColumns.task.computedValue" },
{ key: "primaryColumns.status.computedValue" },
{ key: "primaryColumns.action.computedValue" },
{ key: "primaryColumns.action.buttonLabel" },
];
const propertyPath = "primaryColumns.action.buttonLabel";
const dynamicProperties = removeDynamicBindingProperties(
propertyPath,
dynamicBindingList,
);
// should remove primaryColumns.action.buttonLabel property
expect(dynamicProperties).not.toEqual(
expect.arrayContaining([
expect.objectContaining({
key: "primaryColumns.action.buttonLabel",
}),
]),
);
});
it("should remove widget properties", () => {
// button widget binding
const dynamicBindingList = [{ key: "isVisible" }];
const propertyPath = "isVisible";
const dynamicProperties = removeDynamicBindingProperties(
propertyPath,
dynamicBindingList,
);
// should remove the isVisible property
expect(dynamicProperties).not.toEqual(
expect.arrayContaining([
expect.objectContaining({
key: "isVisible",
}),
]),
);
});
});