feat: testid 支持通过环境变量控制是否开启

This commit is contained in:
yupeng12 2024-03-08 11:01:23 +08:00
parent 28ee659a2c
commit 0c8cfa58f8
6 changed files with 17 additions and 13 deletions

View File

@ -246,6 +246,8 @@ export default function (schema, schemaProps, showCode, envOverrides) {
};
});
},
// testid
// enableTestid: true,
...envOverrides
};

View File

@ -478,11 +478,11 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
// 优先使用组件自己的testid或者id这个解决不了table行内的一些子元素
// 每一行都会出现这个testid的元素只在测试工具中直接使用nth拿序号
if (props.testid || props.id || props.testIdBuilder == null) {
if (!(props.testIdBuilder instanceof TestIdBuilder)) {
props.testIdBuilder = new TestIdBuilder(
rest.env.enableTestid ? props.testid || props.id : null
);
if (rest.env.enableTestid) {
if (props.testid || props.id || props.testIdBuilder == null) {
if (!(props.testIdBuilder instanceof TestIdBuilder)) {
props.testIdBuilder = new TestIdBuilder(props.testid || props.id);
}
}
}

View File

@ -34,7 +34,7 @@ export interface ButtonGroupProps
| 'btnClassName'
> {
options: Array<Option>;
testIdBuilder: TestIdBuilder;
testIdBuilder?: TestIdBuilder;
}
export default class ButtonGroupControl extends React.Component<

View File

@ -60,12 +60,12 @@ export function AutoFilterForm({
type: 'input-text',
name: column.name,
label: column.label,
testIdBuilder: testIdBuilder.getChild(column.name)
testIdBuilder: testIdBuilder?.getChild(column.name)
}
: {
type: 'input-text',
name: column.name,
testIdBuilder: testIdBuilder.getChild(column.name),
testIdBuilder: testIdBuilder?.getChild(column.name),
...column.searchable
}),
name: column.searchable?.name ?? column.name,
@ -130,7 +130,9 @@ export function AutoFilterForm({
inputClassName: cx('Table-searchableForm-checkbox-inner'),
name: `__whatever_name`,
option: column.searchable?.label ?? column.label,
testIdBuilder: moreTestIdBuilder?.getChild(column.name),
testIdBuilder: moreTestIdBuilder?.getChild(
column.name + ''
),
badge: {
offset: [-10, 5],
visibleOn: `${

View File

@ -22,7 +22,7 @@ export interface TableContentProps extends LocaleProps {
className?: string;
tableClassName?: string;
classnames: ClassNamesFn;
testIdBuilder: TestIdBuilder;
testIdBuilder?: TestIdBuilder;
columns: Array<IColumn>;
columnsGroup: Array<{
label: string;

View File

@ -1697,7 +1697,7 @@ export default class Table extends React.Component<TableProps, object> {
onSearchableFromSubmit={onSearchableFromSubmit}
onSearchableFromInit={onSearchableFromInit}
popOverContainer={this.getPopOverContainer}
testIdBuilder={testIdBuilder.getChild('filter')}
testIdBuilder={testIdBuilder?.getChild('filter')}
/>
);
}
@ -2122,7 +2122,7 @@ export default class Table extends React.Component<TableProps, object> {
quickEditFormRef={this.subFormRef}
onImageEnlarge={this.handleImageEnlarge}
translate={translate}
testIdBuilder={testIdBuilder.getChild(
testIdBuilder={testIdBuilder?.getChild(
`cell-${props.rowPath}-${column.index}`
)}
/>
@ -2832,7 +2832,7 @@ export default class Table extends React.Component<TableProps, object> {
'Table--autoFillHeight': autoFillHeight
})}
style={store.buildStyles(style)}
{...testIdBuilder.getTestId()}
{...testIdBuilder?.getTestId()}
>
{autoGenerateFilter ? this.renderAutoFilterForm() : null}
{this.renderAffixHeader(tableClassName)}