Skip to content

Commit

Permalink
feat: 增加input-number inputExcel service tpl 的部分testid (baidu#9526)
Browse files Browse the repository at this point in the history
  • Loading branch information
allenve committed Jan 25, 2024
1 parent 0d3563d commit da01d47
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 16 deletions.
10 changes: 10 additions & 0 deletions packages/amis-ui/scss/components/form/_excel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
color: #bdbdbd;
outline: none;
transition: border 0.24s ease-in-out;
position: relative;
> input {
display: block !important;
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
opacity: 0;
}
}

&-dropzone:focus {
Expand Down
15 changes: 13 additions & 2 deletions packages/amis-ui/src/components/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import getMiniDecimal, {
} from '@rc-component/mini-decimal';

import {Icon} from './icons';
import {ThemeProps, themeable, isNumeric, autobind, ucFirst} from 'amis-core';
import {
ThemeProps,
themeable,
isNumeric,
autobind,
ucFirst,
TestIdBuilder
} from 'amis-core';

export type ValueType = string | number;

Expand Down Expand Up @@ -74,6 +81,8 @@ export interface NumberProps extends ThemeProps {
* 数字输入框类名
*/
inputControlClassName?: string;

testIdBuilder?: TestIdBuilder;
}

export interface NumberState {
Expand Down Expand Up @@ -317,7 +326,8 @@ export class NumberInput extends React.Component<NumberProps, NumberState> {
inputRef,
keyboard,
inputControlClassName,
mobileUI
mobileUI,
testIdBuilder
} = this.props;
const precisionProps: any = {
precision: NumberInput.normalizePrecision(precision, step)
Expand Down Expand Up @@ -356,6 +366,7 @@ export class NumberInput extends React.Component<NumberProps, NumberState> {
stringMode={this.isBig ? true : false}
keyboard={keyboard}
{...precisionProps}
{...testIdBuilder?.getTestId()}
/>
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/amis-ui/src/components/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ export class Select extends React.Component<SelectProps, SelectState> {
<span
className={cx('Select-option-content')}
title={typeof label === 'string' ? label : ''}
{...optTestIdBudr?.getChild('content').getTestId()}
>
{item.disabled
? label
Expand Down
18 changes: 14 additions & 4 deletions packages/amis/src/renderers/Form/InputExcel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
autobind,
isObject,
resolveEventData,
dataMapping
dataMapping,
TestIdBuilder
} from 'amis-core';
import {FormBaseControlSchema, SchemaTokenizeableString} from '../../Schema';
import type {CellValue, CellRichTextValue} from 'exceljs';
Expand Down Expand Up @@ -64,6 +65,8 @@ export interface InputExcelControlSchema extends FormBaseControlSchema {
autoFill?: {
[propName: string]: SchemaTokenizeableString;
};

testIdBuilder?: TestIdBuilder;
}

export interface ExcelProps
Expand Down Expand Up @@ -401,7 +404,8 @@ export default class ExcelControl extends React.PureComponent<
classPrefix: ns,
disabled,
translate: __,
placeholder
placeholder,
testIdBuilder
} = this.props;

return (
Expand All @@ -415,8 +419,14 @@ export default class ExcelControl extends React.PureComponent<
>
{({getRootProps, getInputProps}) => (
<section className={cx('ExcelControl-container', className)}>
<div {...getRootProps({className: cx('ExcelControl-dropzone')})}>
<input {...getInputProps()} />
<div
{...getRootProps({className: cx('ExcelControl-dropzone')})}
{...testIdBuilder?.getTestId()}
>
<input
{...getInputProps()}
{...testIdBuilder?.getChild('input').getTestId()}
/>
{this.state.filename ? (
__('Excel.parsed', {
filename: this.state.filename
Expand Down
9 changes: 7 additions & 2 deletions packages/amis/src/renderers/Form/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
resolveEventData,
CustomStyle,
formatInputThemeCss,
setThemeClassName
setThemeClassName,
TestIdBuilder
} from 'amis-core';
import cx from 'classnames';
import {NumberInput, Select} from 'amis-ui';
Expand Down Expand Up @@ -158,6 +159,8 @@ export interface NumberProps extends FormControlProps {
* 是否在清空内容时从数据域中删除该表单项对应的值
*/
clearValueOnEmpty?: boolean;

testIdBuilder?: TestIdBuilder;
}

interface NumberState {
Expand Down Expand Up @@ -445,7 +448,8 @@ export default class NumberControl extends React.Component<
themeCss,
inputControlClassName,
id,
env
env,
testIdBuilder
} = this.props;
const {unit} = this.state;
const finalPrecision = this.filterNum(precision);
Expand Down Expand Up @@ -523,6 +527,7 @@ export default class NumberControl extends React.Component<
displayMode={displayMode}
big={big}
clearValueOnEmpty={clearValueOnEmpty}
testIdBuilder={testIdBuilder}
/>
{Array.isArray(unitOptions) && unitOptions.length !== 0 ? (
unitOptions.length > 1 ? (
Expand Down
10 changes: 7 additions & 3 deletions packages/amis/src/renderers/Form/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
isEffectiveApi,
isApiOutdated,
createObject,
autobind
autobind,
TestIdBuilder
} from 'amis-core';
import {TransferDropDown, Spinner, Select, SpinnerExtraProps} from 'amis-ui';
import {FormOptionsSchema, SchemaApi} from '../../Schema';
Expand Down Expand Up @@ -155,6 +156,8 @@ export interface SelectControlSchema
*/
filterOption?: 'string';
};

testIdBuilder?: TestIdBuilder;
}

export interface SelectProps extends OptionsControlProps, SpinnerExtraProps {
Expand Down Expand Up @@ -409,12 +412,13 @@ export default class SelectControl extends React.Component<SelectProps, any> {

@autobind
renderMenu(option: Option, state: any) {
const {menuTpl, render, data, optionClassName} = this.props;
const {menuTpl, render, data, optionClassName, testIdBuilder} = this.props;

return render(`menu/${state.index}`, menuTpl, {
showNativeTitle: true,
className: cx('Select-option-content', optionClassName),
data: createObject(createObject(data, state), option)
data: createObject(createObject(data, state), option),
testIdBuilder: testIdBuilder?.getChild('option-' + state.index)
});
}

Expand Down
13 changes: 10 additions & 3 deletions packages/amis/src/renderers/Service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
isVisible,
qsstringify,
createObject,
extendObject
extendObject,
TestIdBuilder
} from 'amis-core';
import {
BaseSchema,
Expand Down Expand Up @@ -151,6 +152,7 @@ export interface ServiceProps
Omit<ServiceSchema, 'type' | 'className'> {
store: IServiceStore;
messages: SchemaMessage;
testIdBuilder?: TestIdBuilder;
}
export default class Service extends React.Component<ServiceProps> {
timer: ReturnType<typeof setTimeout>;
Expand Down Expand Up @@ -797,11 +799,16 @@ export default class Service extends React.Component<ServiceProps> {
classPrefix: ns,
classnames: cx,
loadingConfig,
showErrorMsg
showErrorMsg,
testIdBuilder
} = this.props;

return (
<div className={cx(`${ns}Service`, className)} style={style}>
<div
className={cx(`${ns}Service`, className)}
style={style}
{...testIdBuilder?.getTestId()}
>
{!env.forceSilenceInsideError &&
store.error &&
showErrorMsg !== false ? (
Expand Down
8 changes: 6 additions & 2 deletions packages/amis/src/renderers/Tpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CustomStyle,
setThemeClassName
} from 'amis-core';
import {filter, asyncFilter} from 'amis-core';
import {filter, asyncFilter, TestIdBuilder} from 'amis-core';
import isEmpty from 'lodash/isEmpty';
import {anyChanged, getPropValue} from 'amis-core';
import {escapeHtml} from 'amis-core';
Expand Down Expand Up @@ -52,6 +52,8 @@ export interface TplSchema extends BaseSchema {
* 角标
*/
badge?: BadgeObject;

testidBuilder?: TestIdBuilder;
}

export interface TplProps extends RendererProps, TplSchema {
Expand Down Expand Up @@ -200,7 +202,8 @@ export class Tpl extends React.Component<TplProps, TplState> {
id,
wrapperCustomStyle,
env,
themeCss
themeCss,
testIdBuilder
} = this.props;
const Component = wrapperComponent || (inline ? 'span' : 'div');
const {content} = this.state;
Expand Down Expand Up @@ -236,6 +239,7 @@ export class Tpl extends React.Component<TplProps, TplState> {
onClick={this.handleClick}
onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave}
{...testIdBuilder?.getChild('tpl')?.getTestId()}
>
<span
className={cln ? cx(cln) : undefined}
Expand Down

0 comments on commit da01d47

Please sign in to comment.