Skip to content

feat(tooltip): add test file #25

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

Merged
merged 1 commit into from
Dec 17, 2021
Merged
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
163 changes: 163 additions & 0 deletions packages/devui-vue/devui/tooltip/__tests__/tooltip.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import { mount } from '@vue/test-utils';
import Tooltip from '../src/tooltip';
import DButton from '../../button/src/button';
import { Loading } from '../../loading/index'
import { nextTick } from 'vue';

let tooltipElement: HTMLElement;
const globalOption = {
directives: {
dLoading: Loading
}
}
const defaultslot = {
default: '<d-button btnStyle="common">tooltip</d-button>'
}

describe('tooltip', () => {
beforeEach(() => {
jest.useFakeTimers();
})
describe('basic', () => {
it('should be create', async() => {
const wrapper = mount(Tooltip, {
props: {
content: 'content'
},
slots: defaultslot,
global: globalOption
})
await nextTick();
tooltipElement = wrapper.element.querySelector('.tooltip') as HTMLElement;
expect(wrapper.find('.tooltip').exists()).toBe(true);
expect(wrapper.find('.tooltipcontent').text()).toBe('content');
await wrapper.findComponent(DButton).trigger('mouseenter');
jest.advanceTimersByTime(150);
await nextTick();
tooltipElement = wrapper.element.querySelector('.tooltip') as HTMLElement;
expect(tooltipElement.style.opacity).toBe('1');
await wrapper.findComponent(DButton).trigger('mouseleave');
jest.advanceTimersByTime(150);
await nextTick();
tooltipElement = wrapper.element.querySelector('.tooltip') as HTMLElement;
expect(tooltipElement.style.opacity).toBe('0');
})
it('position should be left', async() => {
const wrapper = mount(Tooltip, {
props: {
content: 'content',
position: 'left'
},
slots: defaultslot,
global: globalOption
})
await nextTick();
await wrapper.findComponent(DButton).trigger('mouseenter');
jest.advanceTimersByTime(150);
await nextTick();
const tooltipArrowElement = wrapper.element.querySelector('.arrow') as HTMLElement;
console.log(tooltipArrowElement.style);
expect(tooltipArrowElement.style.borderLeft).toBe('5px solid rgb(70, 77, 110)');
})
it('position should be top', async() => {
const wrapper = mount(Tooltip, {
props: {
content: 'content',
position: 'top'
},
slots: defaultslot,
global: globalOption
})
await nextTick();
await wrapper.findComponent(DButton).trigger('mouseenter');
jest.advanceTimersByTime(150);
await nextTick();
const tooltipArrowElement = wrapper.element.querySelector('.arrow') as HTMLElement;
console.log(tooltipArrowElement.style);
expect(tooltipArrowElement.style.borderTop).toBe('5px solid rgb(70, 77, 110)');
})
it('position should be right', async() => {
const wrapper = mount(Tooltip, {
props: {
content: 'content',
position: 'right'
},
slots: defaultslot,
global: globalOption
})
await nextTick();
await wrapper.findComponent(DButton).trigger('mouseenter');
jest.advanceTimersByTime(150);
await nextTick();
const tooltipArrowElement = wrapper.element.querySelector('.arrow') as HTMLElement;
console.log(tooltipArrowElement.style);
expect(tooltipArrowElement.style.borderRight).toBe('5px solid rgb(70, 77, 110)');
})
it('position should be bottom', async() => {
const wrapper = mount(Tooltip, {
props: {
content: 'content',
position: 'bottom'
},
slots: defaultslot,
global: globalOption
})
await nextTick();
await wrapper.findComponent(DButton).trigger('mouseenter');
jest.advanceTimersByTime(150);
await nextTick();
const tooltipArrowElement = wrapper.element.querySelector('.arrow') as HTMLElement;
console.log(tooltipArrowElement.style);
expect(tooltipArrowElement.style.borderBottom).toBe('5px solid rgb(70, 77, 110)');
})
})
describe('delay time', () => {
it('test mouseEnterDelay', async() => {
const wrapper = mount(Tooltip, {
props: {
content: 'content',
mouseEnterDelay: 500
},
slots: defaultslot,
global: globalOption
})
await nextTick();
await wrapper.findComponent(DButton).trigger('mouseenter');
jest.advanceTimersByTime(200);
await nextTick();
tooltipElement = wrapper.element.querySelector('.tooltip') as HTMLElement;
expect(tooltipElement.style.opacity).toBe('0');
jest.advanceTimersByTime(300);
await nextTick();
tooltipElement = wrapper.element.querySelector('.tooltip') as HTMLElement;
expect(tooltipElement.style.opacity).toBe('1');
})
it('test mouseLeaveDelay', async() => {
const wrapper = mount(Tooltip, {
props: {
content: 'content',
mouseLeaveDelay: 1000
},
slots: defaultslot,
global: globalOption
})
await nextTick();
await wrapper.findComponent(DButton).trigger('mouseenter');
jest.advanceTimersByTime(150);
await nextTick();
tooltipElement = wrapper.element.querySelector('.tooltip') as HTMLElement;
expect(tooltipElement.style.opacity).toBe('1');
await wrapper.findComponent(DButton).trigger('mouseleave');
jest.advanceTimersByTime(500);
await nextTick();
tooltipElement = wrapper.element.querySelector('.tooltip') as HTMLElement;
expect(tooltipElement.style.opacity).toBe('1');
jest.advanceTimersByTime(500);
await nextTick();
tooltipElement = wrapper.element.querySelector('.tooltip') as HTMLElement;
expect(tooltipElement.style.opacity).toBe('0');
})

})

})