feat: select switch textarea组件补充testid

This commit is contained in:
allenve 2024-01-23 10:11:32 +08:00
parent e7fefaf3d3
commit 5b231a565d
10 changed files with 33 additions and 6 deletions

View File

@ -475,6 +475,10 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
(props as any).static = isStatic;
}
if (rest.env.enableTestid && props.id && !props.testid) {
props.testid = props.id;
}
// 自动解析变量模式,主要是方便直接引入第三方组件库,无需为了支持变量封装一层
if (renderer.autoVar) {
for (const key of Object.keys(schema)) {

View File

@ -135,6 +135,11 @@ export interface RendererEnv {
*/
enableAMISDebug?: boolean;
/**
* testid
*/
enableTestid?: boolean;
/**
* URL
*/

View File

@ -471,6 +471,7 @@ export interface FormItemProps extends RendererProps {
// error string
error?: string;
showErrorMsg?: boolean;
testid?: string;
}
// 下发下去的属性

View File

@ -2286,7 +2286,7 @@ export function replaceUrlParams(path: string, params: Record<string, any>) {
return path;
}
const TEST_ID_KEY: 'data-testid' = 'data-testid';
export const TEST_ID_KEY: 'data-testid' = 'data-testid';
export function buildTestId(testid?: string, data?: PlainObject) {
if (!testid) {

View File

@ -1,5 +1,5 @@
import React from 'react';
import {ThemeProps, themeable} from 'amis-core';
import {ThemeProps, buildTestId, themeable} from 'amis-core';
import Input from './Input';
import {autobind, ucFirst} from 'amis-core';
import {Icon} from './icons';
@ -18,6 +18,7 @@ export interface InputBoxProps
prefix?: JSX.Element;
children?: React.ReactNode | Array<React.ReactNode>;
borderMode?: 'full' | 'half' | 'none';
testid?: string;
}
export interface InputBoxState {
@ -84,6 +85,7 @@ export class InputBox extends React.Component<InputBoxProps, InputBoxState> {
borderMode,
onClick,
mobileUI,
testid,
...rest
} = this.props;
const isFocused = this.state.isFocused;
@ -111,6 +113,7 @@ export class InputBox extends React.Component<InputBoxProps, InputBoxState> {
onBlur={this.handleBlur}
size={12}
disabled={disabled}
{...buildTestId(testid)}
/>
{children}

View File

@ -5,7 +5,7 @@
*/
import React from 'react';
import {ClassNamesFn, themeable} from 'amis-core';
import {ClassNamesFn, buildTestId, themeable} from 'amis-core';
import {Spinner} from './Spinner';
const sizeMap = {
@ -44,6 +44,7 @@ interface SwitchProps {
root?: string;
show?: boolean;
};
testid?: string;
}
export class Switch extends React.PureComponent<SwitchProps, any> {
@ -87,6 +88,7 @@ export class Switch extends React.PureComponent<SwitchProps, any> {
classnames: cx,
loading,
loadingConfig,
testid,
...rest
} = this.props;
@ -110,6 +112,7 @@ export class Switch extends React.PureComponent<SwitchProps, any> {
'is-disabled': isDisabled
})}
data-role="switch"
{...buildTestId(testid)}
>
<input
type="checkbox"

View File

@ -1,7 +1,7 @@
import React from 'react';
import {findDOMNode} from 'react-dom';
import BaseTextArea from 'react-textarea-autosize';
import {localeable, LocaleProps} from 'amis-core';
import {buildTestId, localeable, LocaleProps} from 'amis-core';
import {themeable, ThemeProps} from 'amis-core';
import {autobind, ucFirst} from 'amis-core';
import {Icon} from './icons';
@ -58,6 +58,7 @@ export interface TextAreaProps extends ThemeProps, LocaleProps {
placeholder?: string;
name?: string;
disabled?: boolean;
testid?: string;
forwardRef?: {current: HTMLTextAreaElement | null};
}
@ -183,7 +184,8 @@ export class Textarea extends React.Component<TextAreaProps, TextAreaState> {
classnames: cx,
maxLength,
showCounter,
clearable
clearable,
testid
} = this.props;
const counter = showCounter ? this.valueToString(value).length : 0;
@ -218,6 +220,7 @@ export class Textarea extends React.Component<TextAreaProps, TextAreaState> {
onChange={this.handleChange}
onFocus={this.handleFocus}
onBlur={this.handleBlur}
{...buildTestId(testid)}
/>
{clearable && !disabled && value ? (

View File

@ -154,6 +154,8 @@ export interface SelectControlSchema
*
*/
filterOption?: 'string';
testid?: string;
};
}

View File

@ -54,6 +54,8 @@ export interface SwitchControlSchema extends FormBaseControlSchema {
/** 是否处于加载状态 */
loading?: boolean;
testid?: string;
}
export interface SwitchProps extends FormControlProps, SpinnerExtraProps {
@ -144,7 +146,8 @@ export default class SwitchControl extends React.Component<SwitchProps, any> {
onChange,
disabled,
loading,
loadingConfig
loadingConfig,
testid
} = this.props;
const {on, off} = this.getResult();
@ -164,6 +167,7 @@ export default class SwitchControl extends React.Component<SwitchProps, any> {
size={size as any}
loading={loading}
loadingConfig={loadingConfig}
testid={testid}
/>
)}
</div>

View File

@ -59,6 +59,8 @@ export interface TextareaControlSchema extends FormBaseControlSchema {
*
*/
resetValue?: string;
testid?: string;
}
export type TextAreaRendererEvent = 'blur' | 'focus' | 'change';