Skip to content

Commit

Permalink
Merge pull request baidu#9484 from allenve/master
Browse files Browse the repository at this point in the history
feat: id 默认转testid && editor部分组件配置面板补充testid
  • Loading branch information
allenve committed Jan 23, 2024
2 parents e7fefaf + 5b231a5 commit 150818a
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/amis-core/src/SchemaRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
5 changes: 5 additions & 0 deletions packages/amis-core/src/env.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ export interface RendererEnv {
*/
enableAMISDebug?: boolean;

/**
* 是否开启 testid 定位
*/
enableTestid?: boolean;

/**
* 替换文本,用于实现 URL 替换、语言替换等
*/
Expand Down
1 change: 1 addition & 0 deletions packages/amis-core/src/renderers/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ export interface FormItemProps extends RendererProps {
// error string
error?: string;
showErrorMsg?: boolean;
testid?: string;
}

// 下发下去的属性
Expand Down
2 changes: 1 addition & 1 deletion packages/amis-core/src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion packages/amis-ui/src/components/InputBox.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {
Expand Down Expand Up @@ -84,6 +85,7 @@ export class InputBox extends React.Component<InputBoxProps, InputBoxState> {
borderMode,
onClick,
mobileUI,
testid,
...rest
} = this.props;
const isFocused = this.state.isFocused;
Expand Down Expand Up @@ -111,6 +113,7 @@ export class InputBox extends React.Component<InputBoxProps, InputBoxState> {
onBlur={this.handleBlur}
size={12}
disabled={disabled}
{...buildTestId(testid)}
/>

{children}
Expand Down
5 changes: 4 additions & 1 deletion packages/amis-ui/src/components/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -44,6 +44,7 @@ interface SwitchProps {
root?: string;
show?: boolean;
};
testid?: string;
}

export class Switch extends React.PureComponent<SwitchProps, any> {
Expand Down Expand Up @@ -87,6 +88,7 @@ export class Switch extends React.PureComponent<SwitchProps, any> {
classnames: cx,
loading,
loadingConfig,
testid,
...rest
} = this.props;

Expand All @@ -110,6 +112,7 @@ export class Switch extends React.PureComponent<SwitchProps, any> {
'is-disabled': isDisabled
})}
data-role="switch"
{...buildTestId(testid)}
>
<input
type="checkbox"
Expand Down
7 changes: 5 additions & 2 deletions packages/amis-ui/src/components/Textarea.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -58,6 +58,7 @@ export interface TextAreaProps extends ThemeProps, LocaleProps {
placeholder?: string;
name?: string;
disabled?: boolean;
testid?: string;

forwardRef?: {current: HTMLTextAreaElement | null};
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 ? (
Expand Down
2 changes: 2 additions & 0 deletions packages/amis/src/renderers/Form/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ export interface SelectControlSchema
* 检索函数
*/
filterOption?: 'string';

testid?: string;
};
}

Expand Down
6 changes: 5 additions & 1 deletion packages/amis/src/renderers/Form/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export interface SwitchControlSchema extends FormBaseControlSchema {

/** 是否处于加载状态 */
loading?: boolean;

testid?: string;
}

export interface SwitchProps extends FormControlProps, SpinnerExtraProps {
Expand Down Expand Up @@ -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();
Expand All @@ -164,6 +167,7 @@ export default class SwitchControl extends React.Component<SwitchProps, any> {
size={size as any}
loading={loading}
loadingConfig={loadingConfig}
testid={testid}
/>
)}
</div>
Expand Down
2 changes: 2 additions & 0 deletions packages/amis/src/renderers/Form/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export interface TextareaControlSchema extends FormBaseControlSchema {
* 重置值
*/
resetValue?: string;

testid?: string;
}

export type TextAreaRendererEvent = 'blur' | 'focus' | 'change';
Expand Down

0 comments on commit 150818a

Please sign in to comment.