Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
52 changes: 52 additions & 0 deletions app/client/src/widgets/BaseInputWidget/component/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from "react";
import { render } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import BaseInputComponent, { type BaseInputComponentProps } from "./index";
import { ThemeProvider } from "styled-components";
import { lightTheme } from "selectors/themeSelectors";

const renderBaseInputComponent = (
props: Partial<BaseInputComponentProps> = {},
) => {
const defaultProps: BaseInputComponentProps = {
value: "",
inputType: "TEXT",
inputHTMLType: "TEXT",
disabled: false,
isLoading: false,
compactMode: false,
isInvalid: false,
label: "Salary",
showError: false,
onValueChange: jest.fn(),
onFocusChange: jest.fn(),
widgetId: "test-widget",
rtl: true,
};

return render(
<ThemeProvider theme={lightTheme}>
<BaseInputComponent {...defaultProps} {...props} />
</ThemeProvider>,
);
};

describe("BaseInputComponent TestCases", () => {
test("1. Icon should be visible and aligned to the right when the input type is a number", () => {
const { container } = renderBaseInputComponent({
inputType: "NUMBER",
inputHTMLType: "NUMBER",
value: "123",
onStep: jest.fn(),
rtl: false,
shouldUseLocale: true,
iconName: "add",
iconAlign: "right",
});

const numericInputIcon = container.getElementsByClassName(
"bp3-icon bp3-icon-add",
)[0];
expect(numericInputIcon).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion app/client/src/widgets/BaseInputWidget/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ class BaseInputComponent extends React.Component<
const locale = this.props.shouldUseLocale ? getLocale() : undefined;
const leftIcon = this.getLeftIcon();
const conditionalProps: Record<string, number> = {};

if (!isNil(this.props.maxNum)) {
conditionalProps.max = this.props.maxNum;
}
Expand Down Expand Up @@ -558,6 +557,7 @@ class BaseInputComponent extends React.Component<
onKeyUp={this.onKeyUp}
onValueChange={this.onNumberChange}
placeholder={this.props.placeholder}
rightElement={this.getRightIcon()}
stepSize={this.props.stepSize}
value={this.props.value}
{...conditionalProps}
Expand Down