-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(utils): add ut to package/utils
- Loading branch information
Showing
74 changed files
with
2,621 additions
and
439 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@testing-library/jest-dom'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { IPublicTypeActionContentObject } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isActionContentObject(obj: any): obj is IPublicTypeActionContentObject { | ||
return obj && typeof obj === 'object'; | ||
return isObject(obj); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { IPublicEnumDragObjectType } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isDragAnyObject(obj: any): boolean { | ||
return obj && obj.type !== IPublicEnumDragObjectType.NodeData && obj.type !== IPublicEnumDragObjectType.Node; | ||
if (!isObject(obj)) { | ||
return false; | ||
} | ||
return obj.type !== IPublicEnumDragObjectType.NodeData && obj.type !== IPublicEnumDragObjectType.Node; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { IPublicEnumDragObjectType, IPublicTypeDragNodeDataObject } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isDragNodeDataObject(obj: any): obj is IPublicTypeDragNodeDataObject { | ||
return obj && obj.type === IPublicEnumDragObjectType.NodeData; | ||
if (!isObject(obj)) { | ||
return false; | ||
} | ||
return obj.type === IPublicEnumDragObjectType.NodeData; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { IPublicEnumDragObjectType, IPublicModelNode, IPublicTypeDragNodeObject } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isDragNodeObject<Node = IPublicModelNode>(obj: any): obj is IPublicTypeDragNodeObject<Node> { | ||
return obj && obj.type === IPublicEnumDragObjectType.Node; | ||
if (!isObject(obj)) { | ||
return false; | ||
} | ||
return obj.type === IPublicEnumDragObjectType.Node; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { isFunction } from '../is-function'; | ||
import { isReactClass } from '../is-react'; | ||
import { IPublicTypeDynamicSetter } from '@alilc/lowcode-types'; | ||
|
||
|
||
export function isDynamicSetter(obj: any): obj is IPublicTypeDynamicSetter { | ||
return obj && typeof obj === 'function' && !isReactClass(obj); | ||
if (!isFunction(obj)) { | ||
return false; | ||
} | ||
return !isReactClass(obj); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function isFunction(obj: any): obj is Function { | ||
return obj && typeof obj === 'function'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
|
||
// type checks | ||
|
||
import { IPublicTypeI18nData } from "@alilc/lowcode-types"; | ||
import { IPublicTypeI18nData } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isI18nData(obj: any): obj is IPublicTypeI18nData { | ||
return obj && obj.type === 'i18n'; | ||
if (!isObject(obj)) { | ||
return false; | ||
} | ||
return obj.type === 'i18n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
import { IPublicTypeJSFunction } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
interface InnerJsFunction { | ||
type: 'JSExpression'; | ||
source: string; | ||
value: string; | ||
extType: 'function'; | ||
} | ||
|
||
/** | ||
* 内部版本 的 { type: 'JSExpression', source: '', value: '', extType: 'function' } 能力上等同于 JSFunction | ||
*/ | ||
export function isInnerJsFunction(data: any) { | ||
return data && data.type === 'JSExpression' && data.extType === 'function'; | ||
export function isInnerJsFunction(data: any): data is InnerJsFunction { | ||
if (!isObject(data)) { | ||
return false; | ||
} | ||
return data.type === 'JSExpression' && data.extType === 'function'; | ||
} | ||
|
||
export function isJSFunction(data: any): boolean { | ||
return typeof data === 'object' && data && data.type === 'JSFunction' || isInnerJsFunction(data); | ||
export function isJSFunction(data: any): data is IPublicTypeJSFunction { | ||
if (!isObject(data)) { | ||
return false; | ||
} | ||
return data.type === 'JSFunction' || isInnerJsFunction(data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
import { IPublicTypeJSBlock } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isJSBlock(data: any): boolean { | ||
return data && data.type === 'JSBlock'; | ||
export function isJSBlock(data: any): data is IPublicTypeJSBlock { | ||
if (!isObject(data)) { | ||
return false; | ||
} | ||
return data.type === 'JSBlock'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { IPublicTypeJSSlot } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isJSSlot(data: any): data is IPublicTypeJSSlot { | ||
return data && data.type === 'JSSlot'; | ||
if (!isObject(data)) { | ||
return false; | ||
} | ||
return data.type === 'JSSlot'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { IPublicTypeLocationChildrenDetail, IPublicTypeLocationDetailType } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isLocationChildrenDetail(obj: any): obj is IPublicTypeLocationChildrenDetail { | ||
return obj && obj.type === IPublicTypeLocationDetailType.Children; | ||
if (!isObject(obj)) { | ||
return false; | ||
} | ||
return obj.type === IPublicTypeLocationDetailType.Children; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { IPublicTypeLocationData } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isLocationData(obj: any): obj is IPublicTypeLocationData { | ||
return obj && obj.target && obj.detail; | ||
if (!isObject(obj)) { | ||
return false; | ||
} | ||
return 'target' in obj && 'detail' in obj; | ||
} |
15 changes: 12 additions & 3 deletions
15
packages/utils/src/check-types/is-lowcode-project-schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
import { IPublicTypeComponentSchema, IPublicTypeProjectSchema } from "@alilc/lowcode-types"; | ||
import { isComponentSchema } from "./is-component-schema"; | ||
import { IPublicTypeComponentSchema, IPublicTypeProjectSchema } from '@alilc/lowcode-types'; | ||
import { isComponentSchema } from './is-component-schema'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isLowcodeProjectSchema(data: any): data is IPublicTypeProjectSchema<IPublicTypeComponentSchema> { | ||
return data && data.componentsTree && data.componentsTree.length && isComponentSchema(data.componentsTree[0]); | ||
if (!isObject(data)) { | ||
return false; | ||
} | ||
|
||
if (!('componentsTree' in data) || data.componentsTree.length === 0) { | ||
return false; | ||
} | ||
|
||
return isComponentSchema(data.componentsTree[0]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { IPublicTypeNodeSchema } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isNodeSchema(data: any): data is IPublicTypeNodeSchema { | ||
return data && data.componentName && !data.isNode; | ||
if (!isObject(data)) { | ||
return false; | ||
} | ||
return 'componentName' in data && !data.isNode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { IPublicModelNode } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isNode<Node = IPublicModelNode>(node: any): node is Node { | ||
return node && node.isNode; | ||
if (!isObject(node)) { | ||
return false; | ||
} | ||
return node.isNode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function isObject(obj: any): boolean { | ||
return obj && typeof obj === 'object'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import { IPublicTypeComponentMap, IPublicTypeProCodeComponent } from '@alilc/lowcode-types'; | ||
|
||
import { isObject } from '../is-object'; | ||
|
||
export function isProCodeComponentType(desc: IPublicTypeComponentMap): desc is IPublicTypeProCodeComponent { | ||
if (!isObject(desc)) { | ||
return false; | ||
} | ||
|
||
return 'package' in desc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { IPublicTypeProjectSchema } from "@alilc/lowcode-types"; | ||
import { IPublicTypeProjectSchema } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isProjectSchema(data: any): data is IPublicTypeProjectSchema { | ||
return data && data.componentsTree; | ||
if (!isObject(data)) { | ||
return false; | ||
} | ||
return 'componentsTree' in data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { IPublicTypeSetterConfig } from '@alilc/lowcode-types'; | ||
import { isCustomView } from './is-custom-view'; | ||
|
||
import { isObject } from '../is-object'; | ||
|
||
export function isSetterConfig(obj: any): obj is IPublicTypeSetterConfig { | ||
return obj && typeof obj === 'object' && 'componentName' in obj && !isCustomView(obj); | ||
if (!isObject(obj)) { | ||
return false; | ||
} | ||
return 'componentName' in obj && !isCustomView(obj); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import { IPublicModelSettingField } from "@alilc/lowcode-types"; | ||
import { IPublicModelSettingField } from '@alilc/lowcode-types'; | ||
import { isObject } from '../is-object'; | ||
|
||
export function isSettingField(obj: any): obj is IPublicModelSettingField { | ||
return obj && obj.isSettingField; | ||
if (!isObject(obj)) { | ||
return false; | ||
} | ||
|
||
return 'isSettingField' in obj && obj.isSettingField; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.