Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2296 Use React Testing Library for common-properties tests - Part 2-… #2331

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the extra lines at beginning and end of file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed extra spaces.

/*
* Copyright 2017-2023 Elyra Authors
*
Expand All @@ -18,7 +19,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 +43,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 All @@ -76,3 +76,4 @@ describe("validating colNotExists operator works correctly in a table", () => {
});

});

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,101 +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", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove .only

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

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");
it("selectColumn control becomes validated if selected item has a dmRole equal to discrete", () => {
let errorMessages;
const { container } = wrapper;
const dropDown = container.querySelector("div[data-id='properties-dmMeasurementEqualList']");
const dropdownButton = dropDown.querySelectorAll("button")[0];
fireEvent.click(dropdownButton);
let dropdownList = container.querySelectorAll("li.cds--list-box__menu-item");
expect(dropdownList).to.be.length(14);
dropdownList.at(0).simulate("click"); // Trigger Error Message
let errorMessages = controller.getErrorMessages();
expect(errorMessages).to.not.equal({});
fireEvent.click(dropdownList[0]); // Trigger Error Message
errorMessages = controller.getErrorMessages();
expect(errorMessages).to.not.deep.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);
dropdownList = container.querySelectorAll("li.cds--list-box__menu-item");
fireEvent.click(dropdownList[3]); // Fulfill condition
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");
it("selectColumn control become validated if selected item does not have a dmRole equal to discrete", () => {
const { container } = wrapper;
const dropDown = container.querySelector("div[data-id='properties-dmMeasurementNotEqualList']");
const dropdownButton = dropDown.querySelectorAll("button")[0];
fireEvent.click(dropdownButton);
let 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);
dropdownList = container.querySelectorAll("li.cds--list-box__menu-item");
fireEvent.click(dropdownList[1]); // Fulfill condition
errorMessages = controller.getErrorMessages();
expect(errorMessages).to.deep.equal({});
});
Expand Down
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