Skip to content

Commit

Permalink
fix(components): data testid (#1661)
Browse files Browse the repository at this point in the history
  • Loading branch information
berber1016 committed Dec 10, 2021
1 parent 83fdc80 commit d4f0c15
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/legacy/filter-picker/FilterPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const FilterPicker = (props: FilterPickerProps) => {
onVisibleChange,
placement = 'bottomRight',
disabled,
...rest
} = props;

const localeTextObject: TextObject = useLocale('FilterPicker');
Expand Down Expand Up @@ -80,7 +81,12 @@ const FilterPicker = (props: FilterPickerProps) => {
disabled={disabled}
>
{children || (
<Button.IconButton size="small" type={!localVisible ? 'text' : 'secondary'}>
<Button.IconButton
data-testid="filter-picker"
{...rest}
size="small"
type={!localVisible ? 'text' : 'secondary'}
>
<FilterOutlined size="14px" />
</Button.IconButton>
)}
Expand Down
7 changes: 5 additions & 2 deletions src/list/inner/CascaderItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { DOMAttributes, useContext, useEffect, useMemo } from 'react';
import { isEmpty, noop } from 'lodash';
import classNames from 'classnames';
import { RightFilled } from '@gio-design/icons';
import Popover from '../../popover';
import { CascaderItemProps, OptionProps } from '../interfance';
Expand Down Expand Up @@ -48,7 +49,7 @@ const CascaderItem: React.ForwardRefRenderFunction<
<ListContext.Provider
value={{ ...context, disabled: mergedDisabled, model: 'cascader', selectParent: childSelectPrent }}
>
<List>
<List className={`${prefixCls}--list`}>
{childrens?.map((child) => (
<CascaderItem
{...child}
Expand All @@ -67,7 +68,9 @@ const CascaderItem: React.ForwardRefRenderFunction<
<ListContext.Provider
value={{ ...context, disabled: mergedDisabled, model: 'cascader', selectParent: childSelectPrent }}
>
{children}
{React.isValidElement(children)
? React.cloneElement(children, { className: classNames(children?.props?.className, `${prefixCls}--list`) })
: children}
</ListContext.Provider>
);
};
Expand Down
4 changes: 3 additions & 1 deletion src/past-time-picker/PastTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CalendarOutlined } from '@gio-design/icons';
import classnames from 'classnames';
import has from 'lodash/has';
import get from 'lodash/get';
import omit from 'lodash/omit';
import { format } from 'date-fns';
import Popover from '../popover';
import { InputButton } from '../input';
Expand Down Expand Up @@ -150,6 +151,7 @@ const PastTimePicker = (props: PastTimePickerProps) => {
return (
<InputButton
prefix={prefix || <CalendarOutlined />}
data-testid={restProps?.['data-testid'] ? restProps?.['data-testid'] : 'past-time-picker'}
placeholder={placeholder}
disabled={disabled}
allowClear={allowClear}
Expand All @@ -172,7 +174,7 @@ const PastTimePicker = (props: PastTimePickerProps) => {
overlayClassName={overlayCls}
onVisibleChange={handleVisibleChange}
disabled={disabled}
{...restProps}
{...omit(restProps, 'data-testid')}
>
{renderTrigger()}
</Popover>
Expand Down
1 change: 1 addition & 0 deletions src/past-time-picker/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export interface PastTimePickerProps
* 选择的时间范围
*/
value?: string;
'data-testid'?: string;
}
5 changes: 3 additions & 2 deletions src/select/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useMemo, useRef } from 'react';
import classNames from 'classnames';
import { omit } from 'lodash';
import { SelectProps } from './interface';
import Popover from '../popover';
import Trigger from '../list-picker/Trigger';
Expand Down Expand Up @@ -107,6 +108,7 @@ const Select: React.FC<SelectProps> & { isSelect?: boolean } = (props) => {
hidePrefix={hidePrefix}
title={title}
onClick={triggerClick}
data-testid={rest?.['data-testid'] ? rest?.['data-testid'] : 'select'}
/>
);
};
Expand All @@ -121,8 +123,7 @@ const Select: React.FC<SelectProps> & { isSelect?: boolean } = (props) => {
suffix={suffix}
options={mergedOptions}
disabled={disabled}
data-testid="select"
{...rest}
{...omit({ ...rest }, 'data-testid')}
/>
);

Expand Down
1 change: 1 addition & 0 deletions src/select/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface SelectProps extends Omit<ListProps, 'isMultiple' | 'onChange' |
* content 跟随 trigger宽度
*/
autoWidth?: boolean;
'data-testid'?: string;
}

export interface TriggerProps extends Omit<InputButtonProps, 'value' | 'active'> {
Expand Down

1 comment on commit d4f0c15

@vercel
Copy link

@vercel vercel bot commented on d4f0c15 Dec 10, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.