Skip to content

Commit

Permalink
fix: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
abdul-alhasany committed Apr 23, 2024
1 parent 12968d1 commit 4a4e920
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 45 deletions.
16 changes: 10 additions & 6 deletions src/test/__snapshots__/basic.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`VuePopper > should render correctly 1`] = `
"<div class=\\"popper-container\\">
<div aria-describedby=\\"tooltip\\" class=\\"trigger-element\\"></div>
<transition-stub name=\\"fade\\" appear=\\"false\\" persisted=\\"true\\" css=\\"true\\">
<div class=\\"popper-content\\" role=\\"tooltip\\" style=\\"display: none; position: absolute; left: 0px; top: 0px; margin: 0px;\\">
<div data-popper-arrow=\\"true\\" style=\\"position: absolute;\\"></div>
"<div class="popper-container">
<div class="trigger-element" ariadescribedby="tooltip"></div>
<transition-stub name="fade" appear="false" persisted="false" css="true">
<div class="popper-content-wrapper" style="display: none; position: absolute; left: 0px; top: 0px; margin: 0px;">
<transition-stub name="shift-in" appear="false" persisted="false" css="true" data-placement="top" data-name="shift-in">
<div class="popper-content" style="display: none;">
<div data-popper-arrow="true" style="display: block;"></div>
</div>
</transition-stub>
</div>
</transition-stub>
</div>"
Expand Down
48 changes: 9 additions & 39 deletions src/test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-lines-per-function */

import type { VueWrapper } from '@vue/test-utils';
import { mount } from '@vue/test-utils';
import { mount, flushPromises } from '@vue/test-utils';
import { describe, it, expect, vi } from 'vitest';
import VuePopper from '../VuePopper.vue';
const { fn } = vi;
Expand All @@ -20,17 +20,21 @@ describe('VuePopper', () => {
it('should change open status on click', async () => {
const wrapper: VueWrapper<any> = mount(VuePopper);
await wrapper.find('.trigger-element').trigger('click');
await flushPromises();
expect(wrapper.vm.isOpened).toBe(true);
});

it('should change open status on hover', async () => {
const wrapper: VueWrapper<any> = mount(VuePopper, {
props: {
hover: true,
openDelay: 0,
},
});

await wrapper.find('.trigger-element').trigger('mouseenter');
await flushPromises();

expect(wrapper.vm.isOpened).toBe(true);
});

Expand All @@ -42,6 +46,7 @@ describe('VuePopper', () => {
});

await wrapper.find('.trigger-element').trigger('mouseenter');
await flushPromises();
expect(wrapper.vm.isOpened).toBe(false);
});

Expand All @@ -61,51 +66,16 @@ describe('VuePopper', () => {
await wrapper.find('.trigger-element').trigger('click');
setTimeout(t, 2000);
vi.advanceTimersByTime(2000);
await flushPromises();
expect(wrapper.vm.isOpened).toBe(true);

// Test close delay
window.document.body.dispatchEvent(new Event('click'));

setTimeout(fn(), 5000);
vi.advanceTimersByTime(5000);

await flushPromises();
expect(wrapper.vm.isOpened).toBe(false);
vi.useRealTimers();
});

it('getOffset should return x,y object', () => {
const wrapper: VueWrapper<any> = mount(VuePopper, {
props: {
popperOptions: {
modifiers: [
{
name: 'offset',
options: {
offset: [10, 10],
},
},
],
},
},
});

expect(wrapper.vm.getOffset).toEqual({
x: 10,
y: 10,
});
});

it('getContainerStyle should return an object of border style', () => {
const wrapper: VueWrapper<any> = mount(VuePopper, {
props: {
hover: true,
interactive: true,
},
});

expect(wrapper.vm.getContainerStyle).toEqual({
border: '12px solid transparent',
margin: '-12px',
});
});
});

0 comments on commit 4a4e920

Please sign in to comment.