fix: fix composeTitle returns redundant icons

This commit is contained in:
liujuping 2023-04-04 11:07:42 +08:00 committed by 林熠
parent e1864fdf71
commit ed252fa135
7 changed files with 121 additions and 2 deletions

View File

@ -41,4 +41,20 @@ jobs:
run: npm i && npm run setup:skip-build
- name: test
run: cd packages/designer && npm test
run: cd packages/designer && npm test
editor-skeleton:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
- name: install
run: npm i && npm run setup:skip-build
- name: test
run: cd packages/editor-skeleton && npm test

View File

@ -0,0 +1,9 @@
{
"plugins": [
"build-plugin-component",
"@alilc/lowcode-test-mate/plugin/index.ts"
],
"babelPlugins": [
["@babel/plugin-proposal-private-property-in-object", { "loose": true }]
]
}

View File

@ -0,0 +1,29 @@
const fs = require('fs');
const { join } = require('path');
const esModules = [].join('|');
const pkgNames = fs.readdirSync(join('..')).filter(pkgName => !pkgName.startsWith('.'));
const jestConfig = {
// transform: {
// '^.+\\.[jt]sx?$': 'babel-jest',
// // '^.+\\.(ts|tsx)$': 'ts-jest',
// // '^.+\\.(js|jsx)$': 'babel-jest',
// },
transformIgnorePatterns: [
`/node_modules/(?!${esModules})/`,
],
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
collectCoverage: false,
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!**/node_modules/**',
'!**/vendor/**',
],
};
// 只对本仓库内的 pkg 做 mapping
jestConfig.moduleNameMapper = {};
jestConfig.moduleNameMapper[`^@alilc/lowcode\\-(${pkgNames.join('|')})$`] = '<rootDir>/../$1/src';
module.exports = jestConfig;

View File

@ -10,6 +10,7 @@
"es"
],
"scripts": {
"test": "build-scripts test --config build.test.json",
"build": "build-scripts build --skip-demo"
},
"keywords": [

View File

@ -45,7 +45,7 @@ export function composeTitle(title?: IPublicTypeTitleContent, icon?: IPublicType
}
}
if (isTitleConfig(_title) && noIcon) {
if (!isValidElement(title)) {
if (!isValidElement(_title)) {
_title.icon = undefined;
}
}

View File

@ -0,0 +1,54 @@
import { composeTitle } from '../../src/widget/utils';
import * as React from 'react';
const label = React.createElement('div');
describe('composeTitle 测试', () => {
it('基础能力测试', () => {
expect(composeTitle(undefined)).toEqual({
label: undefined,
});
expect(composeTitle(undefined, undefined, 'tips', true, true)).toEqual({
icon: undefined,
label: 'tips',
});
expect(composeTitle(undefined, undefined, label, true, true)).toEqual({
icon: undefined,
label,
});
expect(composeTitle({
icon: undefined,
label,
}, undefined, '')).toEqual({
icon: undefined,
label,
});
expect(composeTitle('settingsPane')).toEqual('settingsPane');
expect(composeTitle(label, undefined, '物料面板', true, true)).toEqual({
icon: undefined,
label,
tip: '物料面板',
});
expect(composeTitle(label, undefined, label, true, true)).toEqual({
icon: undefined,
label,
tip: label,
});
expect(composeTitle({
label: "物料面板",
icon: undefined,
tip: null,
})).toEqual({
label: "物料面板",
icon: undefined,
tip: null,
})
});
})

View File

@ -23,6 +23,9 @@ export interface IPublicTypePanelDockConfig extends IPublicTypeWidgetBaseConfig
panelProps?: IPublicTypePanelDockPanelProps;
props?: IPublicTypePanelDockProps;
/** 面板 name, 当没有 props.title 时, 会使用 name 作为标题 */
name?: string;
}
export interface IPublicTypePanelDockProps {
@ -32,12 +35,19 @@ export interface IPublicTypePanelDockProps {
className?: string;
/** 详细描述hover 时在标题上方显示的 tips 内容 */
description?: TipContent;
onClick?: () => void;
/**
* icon
*/
icon?: IPublicTypeIconType;
/**
*
*/
title?: IPublicTypeTitleContent;
}