Skip to content

fix: tooltip test file #160

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
Jan 20, 2022
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
38 changes: 25 additions & 13 deletions packages/devui-vue/devui/tooltip/__tests__/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ describe('tooltip', () => {
position: 'left'
},
slots: defaultslot,
global: globalOption
global: globalOption,
attachTo: document.body
})
await nextTick();
await wrapper.findComponent(DButton).trigger('mouseenter');
jest.advanceTimersByTime(150);
jest.advanceTimersByTime(100);
await nextTick();
console.log(wrapper.element.childNodes);
const tooltipArrowElement = wrapper.element.querySelector('.arrow') as HTMLElement;
console.log(tooltipArrowElement.style);
console.log(tooltipArrowElement);
expect(tooltipArrowElement.style.borderLeft).toBe('5px solid rgb(70, 77, 110)');
wrapper.unmount();
})
it('position should be top', async () => {
const wrapper = mount(Tooltip, {
Expand All @@ -66,7 +69,8 @@ describe('tooltip', () => {
position: 'top'
},
slots: defaultslot,
global: globalOption
global: globalOption,
attachTo: document.body
})
await nextTick();
await wrapper.findComponent(DButton).trigger('mouseenter');
Expand All @@ -75,6 +79,7 @@ describe('tooltip', () => {
const tooltipArrowElement = wrapper.element.querySelector('.arrow') as HTMLElement;
console.log(tooltipArrowElement.style);
expect(tooltipArrowElement.style.borderTop).toBe('5px solid rgb(70, 77, 110)');
wrapper.unmount();
})
it('position should be right', async () => {
const wrapper = mount(Tooltip, {
Expand All @@ -83,7 +88,8 @@ describe('tooltip', () => {
position: 'right'
},
slots: defaultslot,
global: globalOption
global: globalOption,
attachTo: document.body
})
await nextTick();
await wrapper.findComponent(DButton).trigger('mouseenter');
Expand All @@ -92,6 +98,7 @@ describe('tooltip', () => {
const tooltipArrowElement = wrapper.element.querySelector('.arrow') as HTMLElement;
console.log(tooltipArrowElement.style);
expect(tooltipArrowElement.style.borderRight).toBe('5px solid rgb(70, 77, 110)');
wrapper.unmount();
})
it('position should be bottom', async () => {
const wrapper = mount(Tooltip, {
Expand All @@ -100,7 +107,8 @@ describe('tooltip', () => {
position: 'bottom'
},
slots: defaultslot,
global: globalOption
global: globalOption,
attachTo: document.body
})
await nextTick();
await wrapper.findComponent(DButton).trigger('mouseenter');
Expand All @@ -109,41 +117,45 @@ describe('tooltip', () => {
const tooltipArrowElement = wrapper.element.querySelector('.arrow') as HTMLElement;
console.log(tooltipArrowElement.style);
expect(tooltipArrowElement.style.borderBottom).toBe('5px solid rgb(70, 77, 110)');
wrapper.unmount()
})
})
describe('delay time', () => {
it('test mouseEnterDelay', async () => {
const wrapper = mount(Tooltip, {
props: {
content: 'content',
mouseEnterDelay: 500
mouseEnterDelay: '500'
},
slots: defaultslot,
global: globalOption
global: globalOption,
attachTo: document.body
})
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');
expect(tooltipElement).toBe(null);
jest.advanceTimersByTime(300);
await nextTick();
tooltipElement = wrapper.element.querySelector('.tooltip') as HTMLElement;
expect(tooltipElement.style.opacity).toBe('1');
wrapper.unmount();
})
it('test mouseLeaveDelay', async () => {
const wrapper = mount(Tooltip, {
props: {
content: 'content',
mouseLeaveDelay: 1000
mouseLeaveDelay: '1000'
},
slots: defaultslot,
global: globalOption
global: globalOption,
attachTo: document.body
})
await nextTick();
await wrapper.findComponent(DButton).trigger('mouseenter');
jest.advanceTimersByTime(150);
jest.advanceTimersByTime(100);
await nextTick();
tooltipElement = wrapper.element.querySelector('.tooltip') as HTMLElement;
expect(tooltipElement.style.opacity).toBe('1');
Expand All @@ -155,7 +167,7 @@ describe('tooltip', () => {
jest.advanceTimersByTime(500);
await nextTick();
tooltipElement = wrapper.element.querySelector('.tooltip') as HTMLElement;
expect(tooltipElement.style.opacity).toBe('0');
expect(tooltipElement).toBe(null);
})

})
Expand Down