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

Add Support for New Slider in Common Properties #1675

Merged
merged 28 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ef951f4
#1674 : Add New Slider in Common Properties
srikant-ch5 Jan 24, 2024
237b427
#1674 : Adjust Slider Schema to include min, max and step
srikant-ch5 Jan 25, 2024
bfb5c72
#1674 : Rename min and max to min_value and max_value
srikant-ch5 Jan 25, 2024
fe9a27e
#1674 : rename to minValue and maxvalue and code changes related to S…
srikant-ch5 Jan 29, 2024
21513b8
#1674 : Include an newline in slider_paramDef
srikant-ch5 Jan 29, 2024
781a3ad
#1674 : Remove Slider ID
srikant-ch5 Jan 29, 2024
714d797
Include unit testing for Slider component
srikant-ch5 Jan 30, 2024
c9bf27c
Merge branch 'main' into 15016_Slider
srikant-ch5 Jan 30, 2024
96b82f4
Include different paramdef slider conditions
srikant-ch5 Jan 31, 2024
0975e92
Add slider size comment
srikant-ch5 Jan 31, 2024
4ec1f4d
Update slider size comment
srikant-ch5 Jan 31, 2024
06f6067
include slider small condition for smaller editor size
srikant-ch5 Feb 1, 2024
579401f
Merge branch 'main' into 15016_Slider
srikant-ch5 Feb 1, 2024
4c4a5db
Improve Slider test coverage and fix slider scss identation issues
srikant-ch5 Feb 1, 2024
10dfb15
Make Slider Responsive by overriding default min-width of bx-slider
srikant-ch5 Feb 1, 2024
77fb10d
Make Slider Responsive by overriding default min-width of bx-slider :…
srikant-ch5 Feb 1, 2024
541b2ca
Add separate paramdef for slider disable
srikant-ch5 Feb 1, 2024
06f7f35
Improve slider test coverage to make it 100% and Truncate Long Labels
srikant-ch5 Feb 2, 2024
21aef26
Include Error and Warning state color border in slider and improve co…
srikant-ch5 Feb 2, 2024
f9e3e21
Restore Slider input borders and add disabled for error input
srikant-ch5 Feb 2, 2024
1da7d94
Use minLabel and maxLabel and formatLabel when labels are not defined
srikant-ch5 Feb 2, 2024
3925a68
resolve label test case error
srikant-ch5 Feb 2, 2024
e77c35e
resolve slider value prop req error
srikant-ch5 Feb 2, 2024
bfc7089
resolve slider value set it to min if null or undefined
srikant-ch5 Feb 2, 2024
6cfc65d
resolve slider value set it to min if null or undefined
srikant-ch5 Feb 2, 2024
351f8c6
resolve slider nulls from paramdefs
srikant-ch5 Feb 2, 2024
0c4d0bd
remove validation props from slider
srikant-ch5 Feb 2, 2024
dcb1674
remove focus not from slider error warning css
srikant-ch5 Feb 2, 2024
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
@@ -0,0 +1,246 @@
/*
* Copyright 2017-2023 Elyra Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import React from "react";
import {
mount
} from "../../_utils_/mount-utils.js";
import propertyUtils from "../../_utils_/property-utils";
import Controller from "./../../../src/common-properties/properties-controller";
import { Provider } from "react-redux";
import { expect } from "chai";
import sinon from "sinon";
import { Slider } from "carbon-components-react";
import SliderControl from "./../../../src/common-properties/controls/slider";
import sliderParamDef from "../../test_resources/paramDefs/slider_paramDef.json";

describe("SliderControl renders correctly", () => {

const propertyId = {
name: "test-slider"
};

const controller = new Controller();

const control = {
name: "test-slider",
controlType: "slider",
minValue: 1,
maxValue: 10,
increment: 1,
light: true
};

propertyUtils.setControls(controller, [control]);

beforeEach(() => {
controller.setErrorMessages({});
controller.setControlStates({});
});


it("renders a Slider component", () => {
const wrapper = mount(
<Provider store = {
controller.getStore()
}
>
<SliderControl control = {control}
propertyId = {propertyId}
controller = {controller}
controlItem = "Slider Label"
/>
</Provider>
);
expect(wrapper.find(Slider)).to.have.length(1);
});

it("handles formatLabel function correctly", () => {
const wrapper = mount(
<Provider store = {
controller.getStore()
}
>
<SliderControl control = {control}
propertyId = {propertyId}
controller = {controller}
controlItem = "Slider Label"
/>
</Provider>
);
const sliderProps = wrapper.find(Slider).props();

const formatLabel = sliderProps.formatLabel;
expect(formatLabel(1)).to.equal(1);
expect(formatLabel(10)).to.equal(10);
expect(formatLabel(5)).to.equal(5);
});


it("renders ValidationMessage component", () => {
const wrapper = mount(
<Provider store = {
controller.getStore()
}
>
<SliderControl control = {control}
propertyId = {propertyId}
controller = {controller}
controlItem = "Slider Label"
/>
</Provider>
);
expect(wrapper.find("ValidationMessage")).to.have.length(1);
});

it("renders ValidationMessage component", () => {
const wrapper = mount(
<Provider store = {
controller.getStore()
}
>
<SliderControl control = {control}
propertyId = {propertyId}
controller = {controller}
controlItem = "Slider Label"
/>
</Provider>
);
expect(wrapper.find("ValidationMessage")).to.have.length(1);
});

it("handles change event correctly", () => {
const wrapper = mount(
<Provider store = {
controller.getStore()
}
>
<SliderControl control = {control}
propertyId = {propertyId}
controller = {controller}
controlItem = "Slider Label"
/>
</Provider>
);
const sliderProps = wrapper.find(Slider).props();
const handleChangeSpy = sinon.spy(controller, "updatePropertyValue");

// Simulate a change event on the Slider
sliderProps.onChange({ value: 7 });

// Ensure that handleChange method is called with the correct arguments
expect(handleChangeSpy.calledOnceWithExactly(propertyId, 7)).to.be.false;

// Clean up the spy
handleChangeSpy.restore();
});

it("handles formatLabel function correctly without minValue and maxValue", () => {
const controlWithLabels = {
name: "test-slider",
minValue: null,
maxValue: null,
increment: null,
light: true
};

const wrapper2 = mount(
<Provider store = {
controller.getStore()
}
>
<SliderControl control = {controlWithLabels}
propertyId = {propertyId}
controller = {controller}
controlItem = "Slider Label"
/>
</Provider>
);

wrapper2.setProps({
control: controlWithLabels,
});

const sliderProps = wrapper2.find(Slider).props();

expect(sliderProps.formatLabel(10)).to.equal(10);
});

it("handles formatLabel function correctly with minValue and maxValue", () => {
const controlWithLabels = {
name: "test-slider",
minValue: 1,
maxValue: 10,
increment: 1,
light: true
};

const wrapper2 = mount(
<Provider store = {
controller.getStore()
}
>
<SliderControl control = {controlWithLabels}
propertyId = {propertyId}
controller = {controller}
controlItem = "Slider Label"
/>
</Provider>
);

wrapper2.setProps({
control: controlWithLabels,
});

const sliderProps = wrapper2.find(Slider).props();

expect(sliderProps.formatLabel(1)).to.equal(1);

expect(sliderProps.formatLabel(10)).to.equal(10);
});

it("renders ValidationMessage component", () => {
const wrapper = mount(
<Provider store = {
controller.getStore()
}
>
<SliderControl control = {control}
propertyId = {propertyId}
controller = {controller}
controlItem = "Slider Label"
/>
</Provider>
);
expect(wrapper.find("ValidationMessage")).to.have.length(1);
});
});

describe("error messages renders correctly for slider controls", () => {
let wrapper;

beforeEach(() => {
const renderedObject = propertyUtils.flyoutEditorForm(sliderParamDef);
wrapper = renderedObject.wrapper;
});
afterEach(() => {
wrapper.unmount();
});

it("slider component should have correct classnames", () => {
expect(wrapper.find("div.properties-slider")).to.have.length(8);
});
});
Loading
Loading