Skip to content

Commit

Permalink
Merge branch 'main' into cou-title-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
caritaou authored Aug 6, 2024
2 parents 5a0a98c + d1da473 commit 00e522b
Show file tree
Hide file tree
Showing 63 changed files with 1,854 additions and 1,400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ describe("CommonCanvas renders correctly", () => {
expect(wrapper.find(CanvasContents)).to.have.length(1);
});

it("should render one <PaletteDialog/> component when enablePaletteLayout is set to Modal", () => {
const config = { enablePaletteLayout: "Modal" };
it("should render one <PaletteDialog/> component when enablePaletteLayout is set to Dialog", () => {
const config = { enablePaletteLayout: "Dialog" };
const wrapper = createCommonCanvas(config, canvasController);
canvasController.openPalette();
wrapper.update();
expect(wrapper.find(PaletteDialog)).to.have.length(1);
});

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
* limitations under the License.
*/

import propertyUtils from "../../_utils_/property-utils";
import tableUtils from "./../../_utils_/table-utils";
import propertyUtilsRTL from "../../_utils_/property-utilsRTL";
import tableUtilsRTL from "./../../_utils_/table-utilsRTL";
import { expect } from "chai";
import structuretableParamDef from "../../test_resources/paramDefs/structuretable_paramDef.json";
import { fireEvent } from "@testing-library/react";


describe("Condition allow_change test cases", () => {
let wrapper;
let controller;
beforeEach(() => {
const renderedObject = propertyUtils.flyoutEditorForm(structuretableParamDef);
const renderedObject = propertyUtilsRTL.flyoutEditorForm(structuretableParamDef);
wrapper = renderedObject.wrapper;
controller = renderedObject.controller;
});
Expand All @@ -34,13 +35,14 @@ describe("Condition allow_change test cases", () => {


it("Test the not allow a change to a field.", () => {
let summaryPanel = propertyUtils.openSummaryPanel(wrapper, "ST_mse_table-summary-panel");
const { container } = wrapper;
let summaryPanel = propertyUtilsRTL.openSummaryPanel(wrapper, "ST_mse_table-summary-panel");

// select the first row in the table
const tableRows = tableUtils.getTableRows(summaryPanel);
const tableRows = tableUtilsRTL.getTableRows(summaryPanel);
expect(tableRows).to.have.length(4);
tableRows.at(0).simulate("click");
summaryPanel = propertyUtils.openSummaryPanel(wrapper, "ST_mse_table-summary-panel");
fireEvent.click(tableRows[0]);
summaryPanel = propertyUtilsRTL.openSummaryPanel(wrapper, "ST_mse_table-summary-panel");

const sportPropertyId = {
name: "ST_mse_table",
Expand All @@ -56,20 +58,22 @@ describe("Condition allow_change test cases", () => {
expect(controller.getPropertyValue(textPropertyId)).to.equal("European");

// attempt to change the sport field to "Football"
const toggleWrapper = wrapper.find("div[data-id='properties-ST_mse_table_0_2']");
const button = toggleWrapper.find("button");
button.simulate("click");
const toggleWrapper = container.querySelector("div[data-id='properties-ST_mse_table_0_2']");
const button = toggleWrapper.querySelector("button");
fireEvent.click(button);
// change is not allowed.
expect(controller.getPropertyValue(sportPropertyId)).to.equal("Soccer");
});
it("Test the allow a change to a field.", () => {
let summaryPanel = propertyUtils.openSummaryPanel(wrapper, "ST_mse_table-summary-panel");
const { container } = wrapper;
let summaryPanel = propertyUtilsRTL.openSummaryPanel(wrapper, "ST_mse_table-summary-panel");

// select the first row in the table
const tableRows = tableUtils.getTableRows(summaryPanel);
const tableRows = tableUtilsRTL.getTableRows(summaryPanel);
expect(tableRows).to.have.length(4);
tableRows.at(0).simulate("click");
summaryPanel = propertyUtils.openSummaryPanel(wrapper, "ST_mse_table-summary-panel");
fireEvent.click(tableRows[0]);
// tableRows.at(0).simulate("click");
summaryPanel = propertyUtilsRTL.openSummaryPanel(wrapper, "ST_mse_table-summary-panel");

const sportPropertyId = {
name: "ST_mse_table",
Expand All @@ -85,9 +89,9 @@ describe("Condition allow_change test cases", () => {
expect(controller.getPropertyValue(textPropertyId)).to.equal("Canadian");

// attempt to change the sport field to "Football"
const toggleWrapper = wrapper.find("div[data-id='properties-ST_mse_table_2_2']");
const button = toggleWrapper.find("button");
button.simulate("click");
const toggleWrapper = container.querySelector("div[data-id='properties-ST_mse_table_2_2']");
const button = toggleWrapper.querySelector("button");
fireEvent.click(button);
// change is allowed.
expect(controller.getPropertyValue(sportPropertyId)).to.equal("Football");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

import { expect } from "chai";
import { validateInput } from "./../../../src/common-properties/ui-conditions/conditions-utils.js";
import propertyUtils from "./../../_utils_/property-utils";
import propertyUtilsRTL from "./../../_utils_/property-utilsRTL";
import readOnlyParamDef from "./../../test_resources/paramDefs/readonly_paramDef.json";
import { fireEvent } from "@testing-library/react";


describe("validateInput validates input and updates controller correctly", () => {
let wrapper;
let controller;
beforeEach(() => {
const renderedObject = propertyUtils.flyoutEditorForm(readOnlyParamDef);
const renderedObject = propertyUtilsRTL.flyoutEditorForm(readOnlyParamDef);
wrapper = renderedObject.wrapper;
controller = renderedObject.controller;
controller.setErrorMessages({});
Expand All @@ -35,14 +36,14 @@ describe("validateInput validates input and updates controller correctly", () =>
});

it("validateInput will update controller error messages when multiple error messages are present in a validation set", () => {
const summaryPanelTable = propertyUtils.openSummaryPanel(wrapper, "readonly-table-summary");
const summaryPanelTable = propertyUtilsRTL.openSummaryPanel(wrapper, "readonly-table-summary");
let messages = controller.getErrorMessages();
expect(JSON.stringify(messages)).to.equal(JSON.stringify({}));
const propId = { name: "readonly_table_cond", row: 0, col: 0 };
const control = controller.getControl(propId);
const rowOneCheckbox = summaryPanelTable.find("input[type='checkbox']").at(5);
rowOneCheckbox.getDOMNode().checked = false;
rowOneCheckbox.simulate("change");
const rowOneCheckbox = summaryPanelTable.querySelectorAll("input[type='checkbox']")[5];
rowOneCheckbox.setAttribute("checked", false);
fireEvent.click(rowOneCheckbox);
validateInput(propId, controller, control);
let expected =
{
Expand All @@ -63,11 +64,11 @@ describe("validateInput validates input and updates controller correctly", () =>
};
messages = controller.getErrorMessages();
expect(JSON.stringify(messages.readonly_table_cond)).to.eql(JSON.stringify(expected));
const rowTwoCheckbox = summaryPanelTable.find("input[type='checkbox']").at(7);
rowTwoCheckbox.getDOMNode().checked = true;
rowTwoCheckbox.simulate("change");
rowTwoCheckbox.getDOMNode().checked = false;
rowTwoCheckbox.simulate("change");
const rowTwoCheckbox = summaryPanelTable.querySelectorAll("input[type='checkbox']")[7];
rowTwoCheckbox.setAttribute("checked", true);
fireEvent.click(rowTwoCheckbox);
rowTwoCheckbox.setAttribute("checked", false);
fireEvent.click(rowTwoCheckbox);
validateInput(propId, controller, control);
expected =
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import propertyUtils from "./../../_utils_/property-utils";
import propertyUtilsRTL from "./../../_utils_/property-utilsRTL";
import defaultsParamDef from "./../../test_resources/paramDefs/defaults_paramDef.json";
import { expect } from "chai";

describe("Condition default_value test cases", () => {
let wrapper;
let controller;
beforeEach(() => {
const renderedObject = propertyUtils.flyoutEditorForm(defaultsParamDef);
const renderedObject = propertyUtilsRTL.flyoutEditorForm(defaultsParamDef);
wrapper = renderedObject.wrapper;
controller = renderedObject.controller;
});
Expand All @@ -32,77 +32,85 @@ describe("Condition default_value test cases", () => {
it("If default value is defined in current_parameters, use default value from current_parameters", () => {
// current_parameters_default has default value defined in current_parameters and default_value condition.
// Higher preference is given to the value in current_parameters
const field2 = wrapper.find("div[data-id='properties-current_parameters_default'] input");
const { container } = wrapper;
const field2 = container.querySelectorAll("div[data-id='properties-current_parameters_default'] input");
expect(field2).to.have.length(1);
expect(field2.prop("value")).to.equal(defaultsParamDef.current_parameters.current_parameters_default);
expect(field2[0].value).to.equal(defaultsParamDef.current_parameters.current_parameters_default);
});

it("If default value is defined in current_ui_parameters, use default value from current_ui_parameters", () => {
// current_ui_parameters_default has default value defined in current_ui_parameters and default_value condition.
// Higher preference is given to the value in current_ui_parameters
const uiField2 = wrapper.find("div[data-id='properties-current_ui_parameters_default'] input");
const { container } = wrapper;
const uiField2 = container.querySelectorAll("div[data-id='properties-current_ui_parameters_default'] input");
expect(uiField2).to.have.length(1);
expect(uiField2.prop("value")).to.equal(defaultsParamDef.current_ui_parameters.current_ui_parameters_default);
expect(uiField2[0].value).to.equal(defaultsParamDef.current_ui_parameters.current_ui_parameters_default);
});

it(`If default value is NOT defined in current_parameters and default_value condition is defined,
use value from default_value condition if the condition evaluate to true`, () => {
// conditional_default has default value defined in default_value condition
// Verify "mode" is "Include"
const { container } = wrapper;
expect(controller.getPropertyValue({ name: "mode" })).to.equal("Include");

// default_value condition evaluate to true when mode is Include.
const field1 = wrapper.find("div[data-id='properties-conditional_default'] textarea");
const field1 = container.querySelectorAll("div[data-id='properties-conditional_default'] textarea");
expect(field1).to.have.length(1);
const defaultValueConditions = defaultsParamDef.conditions.filter((cond) => cond.default_value.parameter_ref === "conditional_default");
expect(field1.text()).to.equal(defaultValueConditions[0].default_value.value.join());
expect(field1[0].textContent).to.equal(defaultValueConditions[0].default_value.value.join());
});

it(`If default value is NOT defined in current_parameters and default_value condition is defined,
use default value from parameters if the condition evaluate to false`, () => {
// default_value condition for ui_conditional_default evaluate to false
// Verify "mode" is "Include"
const { container } = wrapper;
expect(controller.getPropertyValue({ name: "mode" })).to.equal("Include");

// default_value condition evaluate to false because mode is NOT Discard
const uiField1 = wrapper.find("div[data-id='properties-ui_conditional_default'] textarea");
const uiField1 = container.querySelectorAll("div[data-id='properties-ui_conditional_default'] textarea");
expect(uiField1).to.have.length(1);
const uiParameterDefinition = defaultsParamDef.uihints.ui_parameters.filter((param) => param.id === "ui_conditional_default");
expect(uiField1.text()).to.equal(uiParameterDefinition[0].default.join());
expect(uiField1.text()).to.not.equal(defaultsParamDef.conditions[0].default_value.value.join());
expect(uiField1[0].textContent).to.equal(uiParameterDefinition[0].default.join());
expect(uiField1[0].textContent).to.not.equal(defaultsParamDef.conditions[0].default_value.value.join());
});

it("If default value is NOT defined in current_parameters and default_value condition, use default value from parameters", () => {
// parameters_default has default value defined ONLY in parameters
const field3 = wrapper.find("div[data-id='properties-parameters_default'] input");
const { container } = wrapper;
const field3 = container.querySelectorAll("div[data-id='properties-parameters_default'] input");
expect(field3).to.have.length(1);
const parameterDefinition = defaultsParamDef.parameters.filter((param) => param.id === "parameters_default");
expect(field3.prop("value")).to.equal(parameterDefinition[0].default);
expect(field3[0].value).to.equal(parameterDefinition[0].default);
});

it("If default value is NOT defined in current_ui_parameters and default_value condition, use default value from ui_parameters", () => {
// ui_parameters_default has default value defined ONLY in ui_parameters
const uiField3 = wrapper.find("div[data-id='properties-ui_parameters_default'] input");
const { container } = wrapper;
const uiField3 = container.querySelectorAll("div[data-id='properties-ui_parameters_default'] input");
expect(uiField3).to.have.length(1);
const uiParameterDefinition = defaultsParamDef.uihints.ui_parameters.filter((param) => param.id === "ui_parameters_default");
expect(uiField3.prop("value")).to.equal(uiParameterDefinition[0].default);
expect(uiField3[0].value).to.equal(uiParameterDefinition[0].default);
});

it("If multiple default_value conditions evaluate to true, only first one is used.", () => {
// 2 default_value conditions evaluate to true for conditional_default control
const { container } = wrapper;
const defaultValueConditions = defaultsParamDef.conditions.filter((cond) => cond.default_value.parameter_ref === "conditional_default");
expect(defaultValueConditions).to.have.length(2);
const field1 = wrapper.find("div[data-id='properties-conditional_default'] textarea");
const field1 = container.querySelector("div[data-id='properties-conditional_default'] textarea");
// Verify value from 1st condition is used
expect(field1.text()).to.equal(defaultValueConditions[0].default_value.value.join());
expect(field1.textContent).to.equal(defaultValueConditions[0].default_value.value.join());
// Verify value from 2nd condition is NOT used
expect(field1.text()).to.not.equal(defaultValueConditions[1].default_value.value.join());
expect(field1.textContent).to.not.equal(defaultValueConditions[1].default_value.value.join());
});

it("If default value is NOT defined in current_parameters, default_value condition and parameters default, don't set any default value", () => {
// no_default doesn't have any default value
const field4 = wrapper.find("div[data-id='properties-no_default'] input");
const { container } = wrapper;
const field4 = container.querySelectorAll("div[data-id='properties-no_default'] input");
expect(field4).to.have.length(1);
expect(field4.prop("value")).to.equal("");
expect(field4[0].value).to.equal("");
});
});
Loading

0 comments on commit 00e522b

Please sign in to comment.