Skip to content

Commit

Permalink
merge e2e into master
Browse files Browse the repository at this point in the history
  • Loading branch information
yupeng12 committed Mar 5, 2024
2 parents c3a7faf + 693fbbe commit a7c550a
Show file tree
Hide file tree
Showing 100 changed files with 1,056 additions and 366 deletions.
1 change: 1 addition & 0 deletions examples/components/SchemaRender.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export default function (schema, schemaProps, showCode, envOverrides) {
};
});
},
enableTestid: true,
...envOverrides
};

Expand Down
12 changes: 9 additions & 3 deletions packages/amis-core/src/SchemaRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {IScopedContext, ScopedContext} from './Scoped';
import {Schema, SchemaNode} from './types';
import {DebugWrapper} from './utils/debug';
import getExprProperties from './utils/filter-schema';
import {anyChanged, chainEvents, autobind} from './utils/helper';
import {anyChanged, chainEvents, autobind, TestIdBuilder} from './utils/helper';
import {SimpleMap} from './utils/SimpleMap';
import {bindEvent, dispatchEvent, RendererEvent} from './utils/renderer-event';
import {isAlive} from 'mobx-state-tree';
Expand Down Expand Up @@ -476,8 +476,14 @@ 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;
// 优先使用组件自己的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
);
}
}

// 自动解析变量模式,主要是方便直接引入第三方组件库,无需为了支持变量封装一层
Expand Down
4 changes: 3 additions & 1 deletion packages/amis-core/src/factory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
qsparse,
string2regExp,
parseQuery,
isMobile
isMobile,
TestIdBuilder
} from './utils/helper';
import {
fetcherResult,
Expand Down Expand Up @@ -72,6 +73,7 @@ export interface RendererProps
env: RendererEnv;
$path: string; // 当前组件所在的层级信息
$schema: any; // 原始 schema 配置
testIdBuild: TestIdBuilder;
store?: IIRendererStore;
syncSuperStore?: boolean;
data: {
Expand Down
3 changes: 1 addition & 2 deletions packages/amis-core/src/renderers/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import LazyComponent from '../components/LazyComponent';
import {isAlive} from 'mobx-state-tree';

import type {LabelAlign} from './Item';
import {buildTestId, injectObjectChain} from '../utils';
import {injectObjectChain} from '../utils';
import {reaction} from 'mobx';
import groupBy from 'lodash/groupBy';

Expand Down Expand Up @@ -1860,7 +1860,6 @@ export default class Form extends React.Component<FormProps, object> {
)}
onSubmit={this.handleFormSubmit}
noValidate
{...buildTestId(testid)}
>
{/* 实现回车自动提交 */}
<input type="submit" style={{display: 'none'}} />
Expand Down
1 change: 0 additions & 1 deletion packages/amis-core/src/renderers/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ export interface FormItemProps extends RendererProps {
// error string
error?: string;
showErrorMsg?: boolean;
testid?: string;
}

// 下发下去的属性
Expand Down
3 changes: 3 additions & 0 deletions packages/amis-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type {JSONSchema7} from 'json-schema';
import {ListenerAction} from './actions/Action';
import {debounceConfig, trackConfig} from './utils/renderer-event';
import type {TestIdBuilder} from './utils/helper';

export interface Option {
/**
Expand Down Expand Up @@ -693,6 +694,8 @@ export interface BaseSchemaWithoutType {
* 可以组件级别用来关闭移动端样式
*/
useMobileUI?: boolean;

testIdBuilder?: TestIdBuilder;
}

export type OperatorType =
Expand Down
53 changes: 42 additions & 11 deletions packages/amis-core/src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2282,18 +2282,49 @@ export function replaceUrlParams(path: string, params: Record<string, any>) {

export const TEST_ID_KEY: 'data-testid' = 'data-testid';

export function buildTestId(testid?: string, data?: PlainObject) {
if (!testid) {
return {};
export class TestIdBuilder {
testId?: string;

static fast(testId: string) {
return {
[TEST_ID_KEY]: testId
};
}
return {
[TEST_ID_KEY]: filter(testid, data)
};
}

export function getTestId(testid?: string, data?: PlainObject) {
if (!testid) {
return undefined;
// 为空就表示没有启用testId,后续一直返回都将是空
constructor(testId?: string) {
this.testId = testId;
}

// 生成子区域的testid生成器
getChild(childPath: string | number, data?: object) {
if (this.testId == null) {
return new TestIdBuilder();
}

return new TestIdBuilder(
data
? filter(`${this.testId}-${childPath}`, data)
: `${this.testId}-${childPath}`
);
}

// 获取当前组件的testid
getTestId(data?: object) {
if (this.testId == null) {
return undefined;
}

return {
[TEST_ID_KEY]: data ? filter(this.testId, data) : this.testId
};
}

getTestIdValue(data?: object) {
if (this.testId == null) {
return undefined;
}

return data ? filter(this.testId, data) : this.testId;
}
return buildTestId(testid, data)[TEST_ID_KEY];
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Html, render, TooltipWrapper, buildTestId} from 'amis';
import {Html, render, TestIdBuilder, TooltipWrapper} from 'amis';
import {observer} from 'mobx-react';
import React from 'react';
import cx from 'classnames';
Expand All @@ -18,6 +18,7 @@ type PanelProps = {
};
searchRendererType: string;
className?: string;
testIdBuilder?: TestIdBuilder;
};

type PanelStates = {
Expand Down Expand Up @@ -98,7 +99,7 @@ export default class RenderersPanel extends React.Component<
}

render() {
const {store, searchRendererType, className} = this.props;
const {store, searchRendererType, className, testIdBuilder} = this.props;
const grouped = this.props.groupedRenderers || {};
const keys = Object.keys(grouped);

Expand Down Expand Up @@ -189,7 +190,7 @@ export default class RenderersPanel extends React.Component<
onDragStart={(e: React.DragEvent) =>
this.handleDragStart(e, item.name)
}
{...buildTestId(testid)}
{...testIdBuilder?.getChild(testid).getTestId()}
>
<div
className="icon-box"
Expand Down
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: var(--colors-neutral-text-6);
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
8 changes: 4 additions & 4 deletions packages/amis-ui/src/components/AsideNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import React from 'react';
import {mapTree} from 'amis-core';
import {ClassNamesFn, themeable, buildTestId} from 'amis-core';
import {TestIdBuilder, mapTree} from 'amis-core';
import {ClassNamesFn, themeable} from 'amis-core';

export type LinkItem = LinkItemProps;
interface LinkItemProps {
Expand All @@ -19,8 +19,8 @@ interface LinkItemProps {
children?: Array<LinkItem>;
path?: string;
icon?: string;
testid?: string;
component?: React.ElementType;
testIdBuilder?: TestIdBuilder;
}

export interface Navigation {
Expand Down Expand Up @@ -56,7 +56,7 @@ interface AsideNavState {
export class AsideNav extends React.Component<AsideNavProps, AsideNavState> {
static defaultProps = {
renderLink: (item: LinkItemProps) => (
<a {...buildTestId(item.testid, item)}>{item.label}</a>
<a {...item.testIdBuilder?.getTestId()}>{item.label}</a>
),
renderSubLinks: (
link: LinkItemProps,
Expand Down
9 changes: 8 additions & 1 deletion packages/amis-ui/src/components/AssociatedSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ export class AssociatedSelection extends BaseSelection<
loadingConfig,
checkAll,
checkAllLabel,
deferField = 'defer'
deferField = 'defer',
testIdBuilder
} = this.props;

const selectdOption = BaseSelection.resolveSelected(
Expand All @@ -152,6 +153,7 @@ export class AssociatedSelection extends BaseSelection<
virtualThreshold={virtualThreshold}
itemHeight={itemHeight}
loadingConfig={loadingConfig}
testIdBuilder={testIdBuilder?.getChild('left-selection')}
/>
) : (
<GroupedSelection
Expand All @@ -164,6 +166,7 @@ export class AssociatedSelection extends BaseSelection<
clearable={false}
virtualThreshold={virtualThreshold}
itemHeight={itemHeight}
testIdBuilder={testIdBuilder?.getChild('left-selection')}
/>
)}
</div>
Expand Down Expand Up @@ -204,6 +207,7 @@ export class AssociatedSelection extends BaseSelection<
multiple={multiple}
virtualThreshold={virtualThreshold}
itemHeight={itemHeight}
testIdBuilder={testIdBuilder?.getChild('right-selection')}
/>
) : rightMode === 'tree' ? (
<Tree
Expand All @@ -218,6 +222,7 @@ export class AssociatedSelection extends BaseSelection<
loadingConfig={loadingConfig}
checkAllLabel={checkAllLabel}
checkAll={checkAll}
testIdBuilder={testIdBuilder?.getChild('right-selection')}
/>
) : rightMode === 'chained' ? (
<ChainedSelection
Expand All @@ -234,6 +239,7 @@ export class AssociatedSelection extends BaseSelection<
loadingConfig={loadingConfig}
checkAllLabel={checkAllLabel}
checkAll={checkAll}
testIdBuilder={testIdBuilder?.getChild('right-selection')}
/>
) : (
<GroupedSelection
Expand All @@ -249,6 +255,7 @@ export class AssociatedSelection extends BaseSelection<
itemHeight={itemHeight}
checkAllLabel={checkAllLabel}
checkAll={checkAll}
testIdBuilder={testIdBuilder?.getChild('right-selection')}
/>
)
) : (
Expand Down
21 changes: 19 additions & 2 deletions packages/amis-ui/src/components/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {ClassNamesFn, themeable, ThemeProps} from 'amis-core';
import {RootClose} from 'amis-core';
import {removeHTMLTag} from 'amis-core';
import {Icon} from './icons';
import type {TestIdBuilder} from 'amis-core';

export type ItemPlace = 'start' | 'middle' | 'end';
export type TooltipPositionType = 'top' | 'bottom' | 'left' | 'right';
Expand All @@ -32,13 +33,15 @@ interface BreadcrumbItemProps {
tooltipContainer?: any;
tooltipPosition?: TooltipPositionType;
classnames: ClassNamesFn;
testIdBuilder?: TestIdBuilder;
[propName: string]: any;
}

interface BreadcrumbProps extends ThemeProps {
tooltipContainer?: any;
tooltipPosition?: TooltipPositionType;
items: Array<BreadcrumbBaseItem>;
testIdBuilder?: TestIdBuilder;
[propName: string]: any;
}

Expand All @@ -65,6 +68,7 @@ export class Breadcrumb extends React.Component<BreadcrumbProps> {
separatorClassName,
items,
separator,
testIdBuilder,
...restProps
} = this.props;

Expand All @@ -75,6 +79,9 @@ export class Breadcrumb extends React.Component<BreadcrumbProps> {

const crumbs = items
.map<React.ReactNode>((item, index) => {
const itemTestIdBuilder = testIdBuilder?.getChild(
`item-${item.label || index}`
);
let itemPlace: ItemPlace = 'middle';
if (index === 0) {
itemPlace = 'start';
Expand All @@ -88,6 +95,7 @@ export class Breadcrumb extends React.Component<BreadcrumbProps> {
item={item}
itemPlace={itemPlace}
key={index}
testIdBuilder={itemTestIdBuilder}
></BreadcrumbItem>
);
})
Expand Down Expand Up @@ -157,14 +165,20 @@ export class BreadcrumbItem extends React.Component<
item: BreadcrumbBaseItem,
label?: string
) {
const {itemClassName, dropdownItemClassName, classnames: cx} = this.props;
const {
itemClassName,
dropdownItemClassName,
classnames: cx,
testIdBuilder
} = this.props;
const baseItemClassName =
itemType === 'default' ? itemClassName : dropdownItemClassName;
if (showHref) {
return (
<a
href={item.href}
className={cx('Breadcrumb-item-' + itemType, baseItemClassName)}
{...testIdBuilder?.getTestId()}
>
{item.icon ? (
<Icon
Expand All @@ -179,7 +193,10 @@ export class BreadcrumbItem extends React.Component<
);
}
return (
<span className={cx('Breadcrumb-item-' + itemType, baseItemClassName)}>
<span
className={cx('Breadcrumb-item-' + itemType, baseItemClassName)}
{...testIdBuilder?.getTestId()}
>
{item.icon ? (
<Icon
cx={cx}
Expand Down

0 comments on commit a7c550a

Please sign in to comment.