feat: add testid (#2434)

Co-authored-by: Rain <958414905@qq.com>
This commit is contained in:
chenos 2023-09-21 14:54:27 +08:00 committed by GitHub
parent de849b267c
commit 945bcb194e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 1 deletions

View File

@ -14,6 +14,7 @@ export const PluginManagerLink = () => {
return ( return (
<Tooltip title={t('Plugin manager')}> <Tooltip title={t('Plugin manager')}>
<Button <Button
data-testid={'pm-button'}
icon={<ApiOutlined />} icon={<ApiOutlined />}
title={t('Plugin manager')} title={t('Plugin manager')}
onClick={() => { onClick={() => {

View File

@ -77,6 +77,7 @@ export const Action: ComposedAction = observer(
} }
return ( return (
<SortableItem <SortableItem
data-testid={`${fieldSchema['x-action'] || fieldSchema.name}-action`}
{...others} {...others}
loading={field?.data?.loading} loading={field?.data?.loading}
icon={icon ? <Icon type={icon} /> : null} icon={icon ? <Icon type={icon} /> : null}

View File

@ -1,14 +1,29 @@
import { css } from '@emotion/css'; import { css } from '@emotion/css';
import { useFieldSchema } from '@formily/react';
import cls from 'classnames'; import cls from 'classnames';
import React from 'react'; import React from 'react';
import { SortableItem } from '../../common'; import { SortableItem } from '../../common';
import { useDesigner, useProps } from '../../hooks'; import { useDesigner, useProps } from '../../hooks';
const getTestId = (schema) => {
const resource = schema?.['x-decorator-props']?.['resource'];
if (resource) {
return `${resource}-resource`;
}
const field = schema['x-collection-field'];
if (field) {
return `${field}-field`;
}
return `${schema.name}-item`;
};
export const BlockItem: React.FC<any> = (props) => { export const BlockItem: React.FC<any> = (props) => {
const { className, children } = useProps(props); const { className, children } = useProps(props);
const Designer = useDesigner(); const Designer = useDesigner();
const schema = useFieldSchema();
return ( return (
<SortableItem <SortableItem
data-testid={getTestId(schema)}
className={cls( className={cls(
'nb-block-item', 'nb-block-item',
className, className,

View File

@ -196,7 +196,7 @@ const HeaderMenu = ({
key: 'x-designer-button', key: 'x-designer-button',
disabled: true, disabled: true,
style: { padding: '0 8px', order: 9999 }, style: { padding: '0 8px', order: 9999 },
label: render({ style: { background: 'none' } }), label: render({ 'data-testid': 'add-menu-item-button-in-header', style: { background: 'none' } }),
notdelete: true, notdelete: true,
}; };
const result = getMenuItems(() => { const result = getMenuItems(() => {
@ -281,6 +281,7 @@ const SideMenu = ({
key: 'x-designer-button', key: 'x-designer-button',
disabled: true, disabled: true,
label: render({ label: render({
'data-testid': 'add-menu-item-button-in-side',
insert: (s) => { insert: (s) => {
const dn = createDesignable({ const dn = createDesignable({
t, t,

View File

@ -19,6 +19,7 @@ export const DesignableSwitch = () => {
return ( return (
<Tooltip title={t('UI Editor')}> <Tooltip title={t('UI Editor')}>
<Button <Button
data-testid={'ui-editor-button'}
// selected={designable} // selected={designable}
icon={<HighlightOutlined />} icon={<HighlightOutlined />}
title={t('UI Editor')} title={t('UI Editor')}

View File

@ -123,6 +123,7 @@ export const DuplicateAction = observer((props: any) => {
</a> </a>
) : ( ) : (
<Button <Button
data-testid={'duplicate-action'}
disabled={disabled} disabled={disabled}
style={{ style={{
opacity: designable && field?.data?.hidden && 0.1, opacity: designable && field?.data?.hidden && 0.1,