Skip to content

Commit f2918b3

Browse files
authored
Merge pull request #145 from Groww/add/data-testid
add: data-testid for automation
2 parents 5bcfa47 + 08b17cd commit f2918b3

File tree

13 files changed

+66
-21
lines changed

13 files changed

+66
-21
lines changed

packages/ui-toolkit/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@groww-tech/ui-toolkit",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"description": "A lightning nature UI",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.js",

packages/ui-toolkit/src/components/atoms/Button/Button.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class Button extends React.PureComponent<Props> {
1919
isDisabled,
2020
iconPosition,
2121
showLoader,
22-
loadingText
22+
loadingText,
23+
dataTestId
2324
} = this.props;
2425

2526
const classname = cn({
@@ -34,9 +35,10 @@ class Button extends React.PureComponent<Props> {
3435
});
3536

3637
return (
37-
<div className={fixToBottom ? 'btn51BottomFixed' : ''}>
38+
<div className={fixToBottom ? 'btn51BottomFixed' : ''} >
3839
<div
3940
className={classname}
41+
data-test-id={dataTestId.length ? dataTestId : null}
4042
onClick={this.onButtonClick}
4143
style={this.getComputedStyle()}
4244
>
@@ -121,7 +123,8 @@ class Button extends React.PureComponent<Props> {
121123
loadingText: 'Loading...',
122124
fontSize: '',
123125
textColor: '',
124-
backgroundColor: ''
126+
backgroundColor: '',
127+
dataTestId: ''
125128
}
126129
}
127130

@@ -150,6 +153,7 @@ type DefaultProps = {
150153
loadingText: string;
151154
fontSize: string | number;
152155
textColor: string;
156+
dataTestId: string;
153157
/**
154158
* What background color to use
155159
*/

packages/ui-toolkit/src/components/atoms/CheckBox/CheckBox.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const CheckBox = (props: Props) => {
1616
labelComponent, isChecked,
1717
handleOnClick, value,
1818
disabled, checkBoxDirection,
19-
addParentClass
19+
addParentClass, dataTestId
2020
} = props;
2121

2222

@@ -67,7 +67,9 @@ const CheckBox = (props: Props) => {
6767
);
6868

6969
return (
70-
<div onClick={checkBoxClick}
70+
<div
71+
onClick={checkBoxClick}
72+
data-test-id={dataTestId.length ? dataTestId : null}
7173
className={`c11AlignCenter c11Pointer ${addParentClass} ${checkBoxDirection === CHECKBOX_DIRECTION.RIGHT ? 'c11checkOnRight' : ''}`}
7274
>
7375
{isChecked ? active_svg : inactive_svg}
@@ -89,6 +91,7 @@ type DefaultProps = {
8991
addParentClass: string;
9092
labelComponent: () => React.ReactNode;
9193
checkBoxDirection: ValueOf<typeof CHECKBOX_DIRECTION>;
94+
dataTestId: string;
9295
}
9396

9497

@@ -106,7 +109,8 @@ CheckBox.defaultProps = {
106109
activeColor: 'var(--secondaryClr)',
107110
inActiveColor: 'var(--text)',
108111
labelComponent: () => null,
109-
checkBoxDirection: CHECKBOX_DIRECTION.LEFT
112+
checkBoxDirection: CHECKBOX_DIRECTION.LEFT,
113+
dataTestId: ''
110114
} as DefaultProps;
111115

112116
export type Props = DefaultProps & RequiredProps;

packages/ui-toolkit/src/components/atoms/InformationBoard/InformationBox.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ const InformationBox = (props: Props) => {
3333
iconComponent,
3434
outlined,
3535
informationBoxClass,
36-
informationBoxStyle
36+
informationBoxStyle,
37+
dataTestId
3738
} = props;
3839

3940
const parentDivClass = cn({
@@ -57,9 +58,11 @@ const InformationBox = (props: Props) => {
5758
className: 'clrText infbd45InfoIcon'
5859
};
5960

61+
6062
return (
6163
<div style={parentDivStyle}
6264
className={parentDivClass}
65+
data-test-id={dataTestId.length ? dataTestId : null}
6366
>
6467
{
6568
showIcon
@@ -73,7 +76,6 @@ const InformationBox = (props: Props) => {
7376
);
7477
};
7578

76-
7779
const defaultProps: DefaultProps = {
7880
showIcon: true,
7981
iconComponent: (props: ReactIconProps) => <Info {...props} />,
@@ -82,7 +84,8 @@ const defaultProps: DefaultProps = {
8284
outlined: false,
8385
type: 'DEFAULT',
8486
informationBoxClass: '',
85-
informationBoxStyle: {}
87+
informationBoxStyle: {},
88+
dataTestId: ''
8689
};
8790

8891

@@ -102,6 +105,7 @@ type DefaultProps = {
102105
height: number | 'auto';
103106
informationBoxClass: string;
104107
informationBoxStyle: React.CSSProperties;
108+
dataTestId: string;
105109
type: 'DEFAULT' | 'POSITIVE' | 'NEUTRAL' | 'ERROR' | 'WARNING';
106110
}
107111

packages/ui-toolkit/src/components/atoms/Popup/Rodal/Rodal.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class Rodal extends React.Component<Props, State> {
104104
} = this.props;
105105

106106
const CloseButton = showCloseButton ? <span className="rodal-close"
107+
data-test-id='rodal-close-icon'
107108
onClick={onClose}
108109
/> : null;
109110

packages/ui-toolkit/src/components/atoms/RadioButton/RadioButton.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const RadioButton = (props: Props) => {
2020
labelClassName,
2121
parentClassName,
2222
iconClassName,
23-
radioDirection
23+
radioDirection,
24+
dataTestId
2425
} = props;
2526

2627
const labelParentClassName = cn({
@@ -33,6 +34,7 @@ const RadioButton = (props: Props) => {
3334
return (
3435
<div
3536
onClick={onSelect}
37+
data-test-id={dataTestId.length ? dataTestId : null}
3638
className={`radioCo11Box ${parentClassName} ${radioDirection === RADIO_DIRECTION.RIGHT ? 'radioCo11BoxReverse' : ''}`}
3739
>
3840
{
@@ -62,6 +64,7 @@ const defaultProps: DefaultProps = {
6264
iconClassName: '',
6365
labelClassName: '',
6466
parentClassName: 'bas11RadioParent',
67+
dataTestId: '',
6568
radioDirection: RADIO_DIRECTION.LEFT
6669
};
6770

@@ -71,6 +74,7 @@ type DefaultProps = {
7174
parentClassName: string;
7275
radioDirection: ValueOf<typeof RADIO_DIRECTION>;
7376
iconClassName: string;
77+
dataTestId: string;
7478
}
7579

7680

packages/ui-toolkit/src/components/atoms/Select/Select.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class Select extends React.PureComponent<Props> {
6161
optionClass,
6262
optionsParentClass,
6363
activeOptionBoxClass,
64-
activeIndex
64+
activeIndex,
65+
dataTestId
6566
} = this.props;
6667

6768
let selectedOption = null;
@@ -78,7 +79,9 @@ class Select extends React.PureComponent<Props> {
7879
>
7980
<DropdownTrigger>
8081
<div className="width100 pos-rel">
81-
<div className={`pos-rel valign-wrapper se55SelectBox clrText ${activeOptionBoxClass}`}>
82+
<div
83+
className={`pos-rel valign-wrapper se55SelectBox clrText ${activeOptionBoxClass}`}
84+
>
8285
<div>
8386
{selectedOption ? selectedOption.label : placeholder}
8487
</div>
@@ -93,6 +96,7 @@ class Select extends React.PureComponent<Props> {
9396
aria-hidden="true"
9497
tabIndex={-1}
9598
className="se55Input"
99+
data-test-id={dataTestId.length ? dataTestId : null}
96100
/>
97101
</div>
98102

@@ -106,6 +110,7 @@ class Select extends React.PureComponent<Props> {
106110
<div
107111
key={`selectOption-${index}`}
108112
ref={this.optionsRefArr[index]}
113+
data-test-id={dataTestId.length ? index + '-' + dataTestId : null}
109114
className={
110115
cn('se55DropdownPara', {
111116
'se55DropdownParaHover': activeIndex === index,
@@ -193,7 +198,8 @@ Select.defaultProps = {
193198
optionClass: '',
194199
optionsParentClass: '',
195200
activeOptionBoxClass: '',
196-
onChange: () => {}
201+
onChange: () => {},
202+
dataTestId: ''
197203
} as DefaultProps;
198204

199205

@@ -216,6 +222,7 @@ type DefaultProps = {
216222
/* class for a box in which selected values is shown */
217223
activeOptionBoxClass: string;
218224
onChange:(e:React.ChangeEvent<HTMLInputElement>)=> void;
225+
dataTestId: string;
219226
}
220227

221228
export type Props = RequiredProps & DefaultProps;

packages/ui-toolkit/src/components/atoms/TextInputV1/BaseTextInputV1.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const BaseTextInputV1 = React.forwardRef<HTMLInputElement, TextInputProps>((prop
1515
variant = 'default',
1616
size = 'medium',
1717
label,
18+
inputDataTestId = '',
19+
errorDataTestId = '',
1820
PrefixComponent,
1921
SuffixComponent,
2022
...rest
@@ -23,7 +25,9 @@ const BaseTextInputV1 = React.forwardRef<HTMLInputElement, TextInputProps>((prop
2325
//switch for size
2426
return (
2527
<>
26-
{label && <Label className='fs14 fw400'>{label}</Label>}
28+
{
29+
label && <Label className='fs14 fw400'>{label}</Label>
30+
}
2731
<Container
2832
error={error ? true : false}
2933
variant={variant}
@@ -32,6 +36,7 @@ const BaseTextInputV1 = React.forwardRef<HTMLInputElement, TextInputProps>((prop
3236
{PrefixComponent && <TrailingVisContainer variant={variant}>{PrefixComponent()}</TrailingVisContainer>}
3337
<PrimaryInput
3438
ref={ref}
39+
data-test-id={inputDataTestId.length ? inputDataTestId : null}
3540
className={calculateInputClass(size)}
3641
onCopy={onCopy}
3742
onPaste={onPaste}
@@ -49,6 +54,7 @@ const BaseTextInputV1 = React.forwardRef<HTMLInputElement, TextInputProps>((prop
4954

5055
<ErrorLabel
5156
className='fs14 fw400'
57+
data-test-id={errorDataTestId.length ? errorDataTestId : null}
5258
error={error ? true : false}
5359
>
5460
{error}
@@ -59,6 +65,7 @@ const BaseTextInputV1 = React.forwardRef<HTMLInputElement, TextInputProps>((prop
5965
<ErrorLabel
6066
className='fs14 fw400'
6167
error={error ? true : false}
68+
data-test-id={errorDataTestId.length ? errorDataTestId : null}
6269
>
6370
{error}
6471
</ErrorLabel>

packages/ui-toolkit/src/components/atoms/TextInputV1/PaswordTextInputV1.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const PasswordTrailingVisual = ({ type, setType }:{type:string | undefined; setT
3636
return (
3737
<Visibility
3838
onClick={setType}
39+
data-test-id='visibility-icon'
3940
size={18}
4041
/>
4142
);
@@ -44,6 +45,7 @@ const PasswordTrailingVisual = ({ type, setType }:{type:string | undefined; setT
4445
return (
4546
<VisibilityOff
4647
onClick={setType}
48+
data-test-id='visibility-off-icon'
4749
size={18}
4850
/>
4951
);

packages/ui-toolkit/src/components/atoms/TextInputV1/TextInputV1.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ type _TextInputProps = {
4545
onChange: React.FormEventHandler<HTMLInputElement>;
4646
clearable?: boolean;
4747
size?: 'small' | 'medium'| 'large';
48+
inputDataTestId?: string;
49+
errorDataTestId?: string;
4850
};
4951

5052
export default TextInputV1;

packages/ui-toolkit/src/components/atoms/Toastify/Toastify.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ class Toastify extends React.PureComponent<Props, State> {
4646

4747
render() {
4848
const { open, msg } = this.state;
49-
const { msgType, position, showCloseBtn } = this.props;
49+
const { msgType, position, showCloseBtn, dataTestId } = this.props;
5050

5151
return (
5252
<div
53+
data-test-id={dataTestId?.length ? dataTestId : null}
5354
className={
5455
cn('sb10Toastify', {
5556
'sb10ToastifyShow': open,
@@ -110,6 +111,7 @@ type Props = {
110111
position?: string;
111112
showCloseBtn?: boolean;
112113
autoClose?: boolean;
114+
dataTestId?: string;
113115
};
114116

115117

@@ -124,7 +126,8 @@ Toastify.defaultProps = {
124126
msgType: TOASTIFY_TYPE.INFO,
125127
position: TOASTIFY_POSITION.BOTTOM,
126128
showCloseBtn: false,
127-
autoClose: true
129+
autoClose: true,
130+
dataTestId: ''
128131
};
129132

130133
export default Toastify;

packages/ui-toolkit/src/components/atoms/ToggleSwitch/ToggleSwitch.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const ToggleSwitch = (props: Props) => {
77
const {
88
switchCircleColor, activeBackgroundColor, width,
99
inactiveBackgroundColor, onChange, height,
10-
isActive, leftText, rightText
10+
isActive, leftText, rightText, dataTestId
1111
} = props;
1212

1313
// circleDiameter is the diameter of the circular slider which should be smaller than the size of the parent component so as to provide offset between the slider and it's parent
@@ -41,6 +41,7 @@ const ToggleSwitch = (props: Props) => {
4141
{leftText}
4242
<div style={switchDivStyle}
4343
className='sw348reactSwitchDivision'
44+
data-test-id={dataTestId.length ? dataTestId : null}
4445
onClick={(e) => onChange(e)}
4546
>
4647
<input
@@ -74,7 +75,8 @@ const defaultProps: DefaultProps = {
7475
rightText: '',
7576
inactiveBackgroundColor: 'var(--subText)',
7677
switchCircleColor: 'var(--constantWhite)',
77-
activeBackgroundColor: 'var(--primaryClr)'
78+
activeBackgroundColor: 'var(--primaryClr)',
79+
dataTestId: ''
7880
};
7981

8082

@@ -92,6 +94,7 @@ type DefaultProps = {
9294
leftText: React.ReactNode;
9395
rightText: React.ReactNode;
9496
inactiveBackgroundColor: string;
97+
dataTestId: string;
9598
}
9699

97100

packages/ui-toolkit/src/components/molecules/RadioButtonGroup/RadioButtonGroup.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import './radioButtonGroup.css';
88

99
const RadioButtonGroup = (props: Props) => {
1010

11-
const { radioButtons, containerClassName, onSelect, selected, ...restProps } = props;
11+
const { radioButtons, containerClassName,
12+
dataTestId, onSelect, selected, ...restProps } = props;
1213

1314
return (
1415
<div id="container"
@@ -27,6 +28,7 @@ const RadioButtonGroup = (props: Props) => {
2728
labelClassName={item.labelClassName}
2829
parentClassName={item.parentClassName}
2930
radioDirection={item.radioDirection}
31+
dataTestId= {dataTestId ? index + '-' + dataTestId + '-radio-button' : ''}
3032
/>
3133
</div>
3234
);
@@ -38,12 +40,14 @@ const RadioButtonGroup = (props: Props) => {
3840

3941

4042
const defaultProps: DefaultProps = {
41-
containerClassName: ''
43+
containerClassName: '',
44+
dataTestId: ''
4245
};
4346

4447

4548
type DefaultProps = {
4649
containerClassName: string;
50+
dataTestId: string;
4751
}
4852

4953

0 commit comments

Comments
 (0)