2022-05-25 09:46:14 +00:00
|
|
|
import metaReducer, { initialState } from "./index";
|
|
|
|
|
import { updateMetaState } from "actions/metaActions";
|
2024-08-06 14:52:22 +00:00
|
|
|
import type { ReduxAction } from "ee/constants/ReduxActionConstants";
|
|
|
|
|
import { ReduxActionTypes } from "ee/constants/ReduxActionConstants";
|
2022-05-25 09:46:14 +00:00
|
|
|
|
2022-06-25 05:30:54 +00:00
|
|
|
let currentMetaState = initialState;
|
2022-05-25 09:46:14 +00:00
|
|
|
|
|
|
|
|
const inputWidget = {
|
|
|
|
|
widgetId: "incwlne",
|
|
|
|
|
propertyName: "selectedValues",
|
|
|
|
|
propertyValue: ["GREEN", "BLUE", "YELLOW"],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const noAction = (): ReduxAction<unknown> => {
|
|
|
|
|
return {
|
|
|
|
|
type: "NO_ACTION",
|
|
|
|
|
payload: {},
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
test("should return the initial state", () => {
|
2022-06-25 05:30:54 +00:00
|
|
|
expect(metaReducer(undefined, noAction())).toEqual(currentMetaState);
|
2022-05-25 09:46:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("Add a widget meta values", () => {
|
2022-06-25 05:30:54 +00:00
|
|
|
currentMetaState = initialState;
|
2022-05-25 09:46:14 +00:00
|
|
|
expect(
|
2022-06-25 05:30:54 +00:00
|
|
|
metaReducer(currentMetaState, {
|
2022-05-25 09:46:14 +00:00
|
|
|
type: ReduxActionTypes.SET_META_PROP,
|
|
|
|
|
payload: {
|
|
|
|
|
widgetId: inputWidget.widgetId,
|
|
|
|
|
propertyName: inputWidget.propertyName,
|
|
|
|
|
propertyValue: inputWidget.propertyValue,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
).toEqual({
|
|
|
|
|
incwlne: {
|
|
|
|
|
selectedValues: ["GREEN", "BLUE", "YELLOW"],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("Update widget meta state using evalMetaUpdates", () => {
|
|
|
|
|
const evalMetaUpdates = [
|
|
|
|
|
{ widgetId: "incwlne", metaPropertyPath: ["text"], value: "test123" },
|
|
|
|
|
{
|
|
|
|
|
widgetId: "incwlne",
|
|
|
|
|
metaPropertyPath: ["selectedValues"],
|
|
|
|
|
value: ["YELLOW"],
|
|
|
|
|
},
|
|
|
|
|
];
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2022-06-25 05:30:54 +00:00
|
|
|
currentMetaState = metaReducer(
|
|
|
|
|
currentMetaState,
|
2022-05-25 09:46:14 +00:00
|
|
|
updateMetaState(evalMetaUpdates),
|
|
|
|
|
);
|
2022-06-25 05:30:54 +00:00
|
|
|
expect(currentMetaState).toEqual({
|
2022-05-25 09:46:14 +00:00
|
|
|
incwlne: {
|
|
|
|
|
text: "test123",
|
|
|
|
|
selectedValues: ["YELLOW"],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2022-06-25 05:30:54 +00:00
|
|
|
describe("Reset widget meta action", () => {
|
|
|
|
|
test("Reset widget with only widgetId", () => {
|
|
|
|
|
currentMetaState = metaReducer(currentMetaState, {
|
2022-05-25 09:46:14 +00:00
|
|
|
type: ReduxActionTypes.RESET_WIDGET_META,
|
|
|
|
|
payload: {
|
|
|
|
|
widgetId: inputWidget.widgetId,
|
|
|
|
|
},
|
2022-06-25 05:30:54 +00:00
|
|
|
});
|
|
|
|
|
expect(currentMetaState).toEqual({
|
|
|
|
|
incwlne: {},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
currentMetaState = initialState;
|
|
|
|
|
expect(
|
|
|
|
|
metaReducer(currentMetaState, {
|
|
|
|
|
type: ReduxActionTypes.SET_META_PROP,
|
|
|
|
|
payload: {
|
|
|
|
|
widgetId: inputWidget.widgetId,
|
|
|
|
|
propertyName: inputWidget.propertyName,
|
|
|
|
|
propertyValue: inputWidget.propertyValue,
|
|
|
|
|
},
|
2022-05-25 09:46:14 +00:00
|
|
|
}),
|
|
|
|
|
).toEqual({
|
2022-06-25 05:30:54 +00:00
|
|
|
incwlne: {
|
|
|
|
|
selectedValues: ["GREEN", "BLUE", "YELLOW"],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("Reset widget with evaluated values", () => {
|
|
|
|
|
expect(
|
|
|
|
|
metaReducer(currentMetaState, {
|
|
|
|
|
type: ReduxActionTypes.RESET_WIDGET_META,
|
|
|
|
|
payload: {
|
|
|
|
|
widgetId: inputWidget.widgetId,
|
|
|
|
|
evaluatedWidget: {
|
|
|
|
|
defaultSelectedValues: ["GREEN"],
|
|
|
|
|
selectedValues: ["GREEN", "BLUE", "YELLOW"],
|
|
|
|
|
widgetId: inputWidget.widgetId,
|
|
|
|
|
propertyOverrideDependency: {
|
|
|
|
|
selectedValues: {
|
|
|
|
|
DEFAULT: "defaultSelectedValues",
|
|
|
|
|
META: "meta.selectedValues",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-03-20 11:04:02 +00:00
|
|
|
evaluatedWidgetConfig: {
|
|
|
|
|
widgetId: inputWidget.widgetId,
|
|
|
|
|
propertyOverrideDependency: {
|
|
|
|
|
selectedValues: {
|
|
|
|
|
DEFAULT: "defaultSelectedValues",
|
|
|
|
|
META: "meta.selectedValues",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-06-25 05:30:54 +00:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
).toEqual({
|
|
|
|
|
incwlne: {
|
|
|
|
|
selectedValues: ["GREEN"],
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-05-25 09:46:14 +00:00
|
|
|
});
|
|
|
|
|
});
|