Skip to content

Commit

Permalink
#2296 Use React Testing Library for common-properties tests - Part 2-…
Browse files Browse the repository at this point in the history
…final-implementing

Signed-off-by: Jerin George <[email protected]>
  • Loading branch information
Jerinjk14 committed Jan 10, 2025
1 parent 637e7ea commit f7e8a7c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { expect } from "chai";
import Controller from "../../../src/common-properties/properties-controller";
import dataset from "../../test_resources/json/deriveDatasetMetadata.json";
import structuretableParamDef from "../../test_resources/paramDefs/structuretable_paramDef.json";
import propertyUtils from "../../_utils_/property-utils";
import propertyUtilsRTL from "../../_utils_/property-utilsRTL";
import { cleanup } from "@testing-library/react";

describe("validating colNotExists operator works correctly", () => {
const controller = new Controller();
Expand All @@ -41,16 +42,14 @@ describe("validating colNotExists operator works correctly", () => {
});

describe("validating colNotExists operator works correctly in a table", () => {
let wrapper;
let renderedController;
beforeEach(() => {
const renderedObject = propertyUtils.flyoutEditorForm(structuretableParamDef);
wrapper = renderedObject.wrapper;
const renderedObject = propertyUtilsRTL.flyoutEditorForm(structuretableParamDef);
renderedController = renderedObject.controller;
});

afterEach(() => {
wrapper.unmount();
cleanup();
});

it("colNotExists works correctly when in a table cell", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@
*/


import propertyUtils from "../../_utils_/property-utils";
import propertyUtilsRTL from "../../_utils_/property-utilsRTL";
import { expect } from "chai";
import customControlParamDef from "../../test_resources/paramDefs/custom-ctrl-op_paramDef.json";
import { cleanup } from "@testing-library/react";

describe("validating custom operators work correctly", () => {
var wrapper;
var controller;
let controller;
beforeEach(() => {
const renderedObject = propertyUtils.flyoutEditorForm(customControlParamDef);
wrapper = renderedObject.wrapper;
const renderedObject = propertyUtilsRTL.flyoutEditorForm(customControlParamDef);
controller = renderedObject.controller;
});

afterEach(() => {
wrapper.unmount();
cleanup();
});
it("custom_op_num parameter should have error when greater than 100 using a custom op", () => {
const propertyId = { name: "custom_op_num" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,102 +15,105 @@
*/


import propertyUtils from "../../_utils_/property-utils";
import propertyUtilsRTL from "../../_utils_/property-utilsRTL";
import { expect } from "chai";
import conditionOpParamDef from "../../test_resources/paramDefs/dmConditionOp_paramDef.json";
import { cleanup, fireEvent } from "@testing-library/react";

describe("dm condition operators work correctly", () => {
var wrapper;
var controller;
describe.only("dm condition operators work correctly", () => {
let wrapper;
let controller;
beforeEach(() => {
const renderedObject = propertyUtils.flyoutEditorForm(conditionOpParamDef);
const renderedObject = propertyUtilsRTL.flyoutEditorForm(conditionOpParamDef);
wrapper = renderedObject.wrapper;
controller = renderedObject.controller;
});

afterEach(() => {
wrapper.unmount();
cleanup();
});
it("checkbox control become enabled if selected item has a dmType equal to string", () => {
const { container } = wrapper;
expect(controller.getControlState({ name: "checkbox" })).to.equal("disabled");
const dropDown = wrapper.find("div[data-id='properties-ctrl-dmTypeEqualList']");
const dropdownButton = dropDown.find("button").at(0);
dropdownButton.simulate("click");
const dropdownList = wrapper.find("li.cds--list-box__menu-item");
dropdownList.at(3).simulate("click");
wrapper.update();
const dropDown = container.querySelector("div[data-id='properties-ctrl-dmTypeEqualList']");
const dropdownButton = dropDown.querySelectorAll("button")[0];
fireEvent.click(dropdownButton);
const dropdownList = container.querySelectorAll("li.cds--list-box__menu-item");
fireEvent.click(dropdownList[3]);
expect(dropdownList).to.be.length(14);
expect(controller.getControlState({ name: "checkbox" })).to.equal("enabled");

});

it("checkbox control become visible if selected item does not have a dmType equal to string", () => {
const { container } = wrapper;
expect(controller.getControlState({ name: "checkbox1" })).to.equal("hidden");
const dropDown = wrapper.find("div[data-id='properties-ctrl-dmTypeNotEqualList']");
const dropdownButton = dropDown.find("button").at(0);
dropdownButton.simulate("click");
const dropdownList = wrapper.find("li.cds--list-box__menu-item");
const dropDown = container.querySelector("div[data-id='properties-ctrl-dmTypeNotEqualList']");
const dropdownButton = dropDown.querySelectorAll("button")[0];
fireEvent.click(dropdownButton);
const dropdownList = container.querySelectorAll("li.cds--list-box__menu-item");
expect(dropdownList).to.be.length(14);
dropdownList.at(1).simulate("click");
wrapper.update();
fireEvent.click(dropdownList[1]);
expect(controller.getControlState({ name: "checkbox1" })).to.equal("visible");
});

it("checkbox control becomes enabled if selected item has a dmRole equal to input", () => {
const { container } = wrapper;
expect(controller.getControlState({ name: "checkbox2" })).to.equal("disabled");
const dropDown = wrapper.find("div[data-id='properties-ctrl-dmRoleEqualList']");
const dropdownButton = dropDown.find("button").at(0);
dropdownButton.simulate("click");
const dropdownList = wrapper.find("li.cds--list-box__menu-item");
const dropDown = container.querySelector("div[data-id='properties-ctrl-dmRoleEqualList']");
const dropdownButton = dropDown.querySelectorAll("button")[0];
fireEvent.click(dropdownButton);
const dropdownList = container.querySelectorAll("li.cds--list-box__menu-item");
expect(dropdownList).to.be.length(14);
dropdownList.at(1).simulate("click");
wrapper.update();
fireEvent.click(dropdownList[1]);
expect(controller.getControlState({ name: "checkbox2" })).to.equal("enabled");
});

it("checkbox control become visible if selected item does not have a dmRole equal to input", () => {
const { container } = wrapper;
expect(controller.getControlState({ name: "checkbox3" })).to.equal("hidden");
const dropDown = wrapper.find("div[data-id='properties-ctrl-dmRoleNotEqualList']");
const dropdownButton = dropDown.find("button").at(0);
dropdownButton.simulate("click");
const dropdownList = wrapper.find("li.cds--list-box__menu-item");
const dropDown = container.querySelector("div[data-id='properties-ctrl-dmRoleNotEqualList']");
const dropdownButton = dropDown.querySelectorAll("button")[0];
fireEvent.click(dropdownButton);
const dropdownList = container.querySelectorAll("li.cds--list-box__menu-item");
expect(dropdownList).to.be.length(14);
dropdownList.at(2).simulate("click");
wrapper.update();
fireEvent.click(dropdownList[2]);
expect(controller.getControlState({ name: "checkbox3" })).to.equal("visible");
});

// This works in the UI but errorMessages is not updated in test
it.skip("selectColumn control becomes validated if selected item has a dmRole equal to discrete", () => {
const dropDown = wrapper.find("div[data-id='properties-dmMeasurementEqualList']");
const dropdownButton = dropDown.find("button").at(0);
dropdownButton.simulate("click");
const dropdownList = wrapper.find("li.cds--list-box__menu-item");
const { container } = wrapper;
const dropDown = container.querySelector("div[data-id='properties-dmMeasurementEqualList']");
const dropdownButton = dropDown.querySelectorAll("button")[0];
fireEvent.click(dropdownButton);
const dropdownList = container.querySelectorAll("li.cds--list-box__menu-item");
expect(dropdownList).to.be.length(14);
dropdownList.at(0).simulate("click"); // Trigger Error Message
fireEvent.click(dropdownList[0]);// Trigger Error Message
let errorMessages = controller.getErrorMessages();
expect(errorMessages).to.not.equal({});
expect(errorMessages.dmMeasurementEqualList.type).to.equal("error");
dropdownButton.simulate("click");
dropdownList.at(3).simulate("click"); // Fulfill Condition by selecting item with dmRole discrete
fireEvent.click(dropdownButton);
fireEvent.click(dropdownList[3]); // Fulfill Condition by selecting item with dmRole discrete
errorMessages = controller.getErrorMessages();
expect(controller.getErrorMessages()).to.deep.equal({});
expect(errorMessages).to.deep.equal({});
});

// This works in the UI but errorMessages is not updated in test
it.skip("selectColumn control become validated if selected item does not have a dmRole equal to discrete", () => {
const dropDown = wrapper.find("div[data-id='properties-dmMeasurementNotEqualList']");
const dropdownButton = dropDown.find("button").at(0);
dropdownButton.simulate("click");
const dropdownList = wrapper.find("li.cds--list-box__menu-item");
const { container } = wrapper;
const dropDown = container.querySelector("div[data-id='properties-dmMeasurementNotEqualList']");
const dropdownButton = dropDown.querySelectorAll("button")[0];
fireEvent.click(dropdownButton);
const dropdownList = container.querySelectorAll("li.cds--list-box__menu-item");
expect(dropdownList).to.be.length(14);
dropdownList.at(3).simulate("click"); // Trigger Error Message by selecting item with dmRole discrete
fireEvent.click(dropdownList[3]); // Trigger Error Message by selecting item with dmRole discrete
let errorMessages = controller.getErrorMessages();
expect(errorMessages).to.not.equal({});
expect(errorMessages.dmMeasurementNotEqualList.type).to.equal("error");
dropdownButton.simulate("click");
dropdownList.at(1).simulate("click"); // Fulfill Condition by selecting item with dmRole input
fireEvent.click(dropdownButton);
fireEvent.click(dropdownList[2]); // Fulfill Condition by selecting item with dmRole input
errorMessages = controller.getErrorMessages();
expect(errorMessages).to.deep.equal({});
});
});

Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import { expect } from "chai";
import { propertyOf } from "lodash";
import * as PropertyUtils from "./../../../src/common-properties/util/property-utils.js";
import testUtils from "./../../_utils_/property-utils";
import testUtils from "./../../_utils_/property-utilsRTL.js";
import Controller from "./../../../src/common-properties/properties-controller";
import propertyUtils from "./../../_utils_/property-utils";
import propertyUtilsRTL from "./../../_utils_/property-utilsRTL.js";
import structureTableParamDef from "./../../test_resources/paramDefs/structuretable_paramDef.json";
import convertValuesDataTypesParamDef from "./../../test_resources/paramDefs/convertValueDataTypes_paramDef.json";
import { cleanup } from "@testing-library/react";

describe("dynamic text with expressions", () => {
const controller = new Controller();
Expand Down Expand Up @@ -102,16 +103,14 @@ describe("dynamic text with expressions", () => {
});

describe("getDMFieldIcon retrieves correct icon type for each measurement level ", () => {
var wrapper;
var controller;
let controller;
beforeEach(() => {
const renderedObject = propertyUtils.flyoutEditorForm(structureTableParamDef);
wrapper = renderedObject.wrapper;
const renderedObject = propertyUtilsRTL.flyoutEditorForm(structureTableParamDef);
controller = renderedObject.controller;
});

afterEach(() => {
wrapper.unmount();
cleanup();
});

it("measure level of range should return measurement-scale icon", () => {
Expand Down Expand Up @@ -369,7 +368,7 @@ describe("convertValueDataTypestests", () => {
});

it("convertValueDataTypes correctly converts currentParameters data types when setting form", () => {
const renderedObject = propertyUtils.flyoutEditorForm(convertValuesDataTypesParamDef, { convertValueDataTypes: true });
const renderedObject = propertyUtilsRTL.flyoutEditorForm(convertValuesDataTypesParamDef, { convertValueDataTypes: true });
const controller2 = renderedObject.controller;

const expected = Object.assign({}, expectedValues);
Expand Down

0 comments on commit f7e8a7c

Please sign in to comment.