Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Tooltip): 补充Tooltip单元测试&优化文档格式 #468

Merged
merged 1 commit into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 0 additions & 170 deletions packages/devui-vue/devui/tooltip/__tests__/tooltip.spec.ts

This file was deleted.

51 changes: 51 additions & 0 deletions packages/devui-vue/devui/tooltip/__tests__/tooltip.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { mount } from '@vue/test-utils';
import Tooltip from '../src/tooltip';

describe('d-tooltip', () => {
it('should render correctly', async () => {
const wrapper = mount({
setup() {
return () => <Tooltip content="tips text">{{ default: () => <d-button>top</d-button> }}</Tooltip>;
},
});
const btn = wrapper.find('.devui-btn');
const reference = wrapper.find('.devui-tooltip-reference');
expect(reference.exists()).toBeTruthy();
expect(btn.exists()).toBeTruthy();

await reference.trigger('mouseenter');
await new Promise((resolve) => {
setTimeout(resolve, 150);
});
const tooltipContent = document.querySelector('.devui-tooltip');
expect(tooltipContent).toBeTruthy();
expect(tooltipContent?.innerHTML).toContain('tips text');
wrapper.unmount();
});

it('mouse enter delay & mouse leave delay', async () => {
const wrapper = mount({
setup() {
return () => (
<Tooltip content="tips text" mouse-enter-delay={500} mouse-leave-delay={500}>
{{ default: () => <d-button>top</d-button> }}
</Tooltip>
);
},
});
const reference = wrapper.find('.devui-tooltip-reference');
await reference.trigger('mouseenter');
await new Promise((resolve) => {
setTimeout(resolve, 500);
});
const tooltipContent = document.querySelector('.devui-tooltip');
expect(tooltipContent).toBeTruthy();

await reference.trigger('mouseleave');
await new Promise((resolve) => {
setTimeout(resolve, 500);
});
expect(document.querySelector('.devui-tooltip')).toBeFalsy();
wrapper.unmount();
});
});
34 changes: 17 additions & 17 deletions packages/devui-vue/docs/components/tooltip/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### 基本用法

:::demo
:::demo 默认在触发元素的上方展示提示信息,可通过`position`更改展示位置;`content`可设置提示信息;`show-animation`控制是否开启动画。

```vue
<template>
Expand Down Expand Up @@ -54,9 +54,7 @@ export default defineComponent({

### 延时触发

鼠标移入的时长超过 `mouse-enter-delay` 毫秒之后才会触发,以防止用户无意划过导致的闪现,默认值是 150 毫秒;鼠标移出之后,再经过`mouse-leave-delay`毫秒后,toolTip 组件才会隐藏,默认值是 100 毫秒。

:::demo
:::demo 鼠标移入的时长超过 `mouse-enter-delay` 毫秒之后才会触发,以防止用户无意划过导致的闪现,默认值是 150 毫秒;鼠标移出之后,再经过`mouse-leave-delay`毫秒后,Tooltip 组件才会隐藏,默认值是 100 毫秒。

```vue
<template>
Expand All @@ -73,24 +71,26 @@ export default defineComponent({

:::

### d-tooltip 参数
### Tooltip 参数

| 参数 | 类型 | 默认 | 说明 | 跳转 Demo |
| ----------------- | ---------------------------------- | ---- | ------------------------------------------------- | --------------------- |
| content | `string` | -- | 可选,Tooltip 显示内容 | [基本用法](#基本用法) |
| position | `BasePlacement \| BasePlacement[]` | top | 可选,Tooltip 显示位置 | [基本用法](#基本用法) |
| show-animation | `boolean` | true | 可选,是否显示动画 | [基本用法](#基本用法) |
| mouse-enter-delay | `number` | 150 | 可选,鼠标移入后延时多久才显示 Tooltip,单位是 ms | [延时触发](#延时触发) |
| mouse-leave-delay | `number` | 100 | 可选,鼠标移出后延时多久才隐藏 Tooltip,单位是 ms | [延时触发](#延时触发) |
| 参数名 | 类型 | 默认值 | 说明 | 跳转 Demo |
| :---------------- | :------------------------------------------------- | :----- | :------------------------------------------------ | :-------------------- |
| content | `string` | -- | 可选,Tooltip 显示内容 | [基本用法](#基本用法) |
| position | [BasePlacement \| BasePlacement[]](#baseplacement) | top | 可选,Tooltip 显示位置 | [基本用法](#基本用法) |
| show-animation | `boolean` | true | 可选,是否显示动画 | [基本用法](#基本用法) |
| mouse-enter-delay | `number` | 150 | 可选,鼠标移入后延时多久才显示 Tooltip,单位是 ms | [延时触发](#延时触发) |
| mouse-leave-delay | `number` | 100 | 可选,鼠标移出后延时多久才隐藏 Tooltip,单位是 ms | [延时触发](#延时触发) |

### d-tooltip 插槽
### Tooltip 插槽

| 名称 | 说明 |
| ------- | ---------------------- |
| 插槽名 | 说明 |
| :------ | :--------------------- |
| default | 默认插槽,设置触发元素 |

### BasePlacement 类型
### 类型定义

#### BasePlacement

```typescript
```ts
type BasePlacement = 'top' | 'right' | 'bottom' | 'left';
```