Sidebar unit test changed
parent
af15e851e9
commit
22757dbb5b
|
@ -1,11 +1,12 @@
|
||||||
import { mount } from '@vue/test-utils';
|
import { mount } from '@vue/test-utils';
|
||||||
import PrimeVue from 'primevue/config';
|
import PrimeVue from 'primevue/config';
|
||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import DomHandler from '../utils/DomHandler';
|
||||||
import Sidebar from './Sidebar.vue';
|
import Sidebar from './Sidebar.vue';
|
||||||
describe('Sidebar.vue', () => {
|
describe('Sidebar.vue', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
wrapper = mount(Sidebar, {
|
wrapper = mount(Sidebar, {
|
||||||
global: {
|
global: {
|
||||||
plugins: [PrimeVue],
|
plugins: [PrimeVue],
|
||||||
|
@ -14,7 +15,7 @@ describe('Sidebar.vue', () => {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
visible: false,
|
visible: true,
|
||||||
bazeZIndex: 1000
|
bazeZIndex: 1000
|
||||||
},
|
},
|
||||||
slots: {
|
slots: {
|
||||||
|
@ -22,15 +23,14 @@ describe('Sidebar.vue', () => {
|
||||||
header: `<span class="header">Header Template</span>`
|
header: `<span class="header">Header Template</span>`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
wrapper.setProps({ visible: true });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('When component is mounted, sidebar should be exist', () => {
|
it('When component is mounted, sidebar should be exist', async () => {
|
||||||
expect(wrapper.find('.p-sidebar.p-component').exists()).toBe(true);
|
expect(wrapper.find('.p-sidebar-mask').exists()).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('When mask element triggered, sidebar should be hide', async () => {
|
it('When mask element triggered, sidebar should be hide', async () => {
|
||||||
|
@ -48,7 +48,7 @@ describe('Sidebar.vue', () => {
|
||||||
await wrapper.vm.onEnter();
|
await wrapper.vm.onEnter();
|
||||||
|
|
||||||
expect(wrapper.emitted().show.length).toBe(1);
|
expect(wrapper.emitted().show.length).toBe(1);
|
||||||
expect(wrapper.vm.maskVisible).toBeTruthy();
|
expect(wrapper.vm.containerVisible).toBeTruthy();
|
||||||
expect(focusSpy).toHaveBeenCalled();
|
expect(focusSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -93,4 +93,37 @@ describe('Sidebar.vue', () => {
|
||||||
expect(unbindOutsideClickListenerSpy).toHaveBeenCalled();
|
expect(unbindOutsideClickListenerSpy).toHaveBeenCalled();
|
||||||
expect(Sidebar.container).toBe(null);
|
expect(Sidebar.container).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('When hide is triggered , removeClass util should be called', async () => {
|
||||||
|
const removeClassSpy = vi.spyOn(DomHandler, 'removeClass');
|
||||||
|
|
||||||
|
await wrapper.setProps({ blockScroll: true });
|
||||||
|
wrapper.vm.hide();
|
||||||
|
|
||||||
|
expect(removeClassSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('When onEnter is triggered , addClass util should be called', async () => {
|
||||||
|
const addClassSpy = vi.spyOn(DomHandler, 'addClass');
|
||||||
|
|
||||||
|
await wrapper.setProps({ blockScroll: true });
|
||||||
|
wrapper.vm.onEnter();
|
||||||
|
|
||||||
|
expect(addClassSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('When onBeforeLeave is triggered , addClass util should be called', async () => {
|
||||||
|
const addClassSpy = vi.spyOn(DomHandler, 'addClass');
|
||||||
|
|
||||||
|
await wrapper.setProps({ modal: true });
|
||||||
|
wrapper.vm.onBeforeLeave();
|
||||||
|
|
||||||
|
expect(addClassSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('When onAfterLeave is triggered , containerVisible should be false', async () => {
|
||||||
|
wrapper.vm.onAfterLeave();
|
||||||
|
|
||||||
|
expect(wrapper.vm.containerVisible).toBeFalsy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue