primevue-mirror/components/lib/blockui/BlockUI.spec.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

import { mount } from '@vue/test-utils';
2022-12-29 09:39:06 +00:00
import { beforeEach, expect } from 'vitest';
2022-09-06 12:03:37 +00:00
import BlockUI from './BlockUI.vue';
2022-12-29 09:39:06 +00:00
vi.mock('primevue/utils');
let wrapper = null;
2022-12-08 11:04:25 +00:00
2022-09-06 12:03:37 +00:00
describe('BlockUI.vue', () => {
2022-12-29 09:39:06 +00:00
beforeEach(() => {
wrapper = mount(BlockUI);
});
afterEach(() => {
vi.clearAllMocks();
});
it('When blocked props is true, block method should be triggered on mounted hook', async () => {
const blockUiSpy = vi.spyOn(BlockUI.methods, 'block');
wrapper = mount(BlockUI, {
props: {
blocked: true
2022-09-06 12:03:37 +00:00
}
});
2022-12-29 09:39:06 +00:00
expect(blockUiSpy).toHaveBeenCalled();
});
it('When blocked props value is changed, block or unblock method should be triggered', async () => {
const blockSpy = vi.spyOn(wrapper.vm, 'block');
const unblockSpy = vi.spyOn(wrapper.vm, 'unblock');
2022-09-06 12:03:37 +00:00
2022-12-29 09:39:06 +00:00
await wrapper.setProps({ blocked: true });
2022-09-06 12:03:37 +00:00
2022-12-29 09:39:06 +00:00
expect(blockSpy).toHaveBeenCalled();
2022-09-06 12:03:37 +00:00
2022-12-29 09:39:06 +00:00
await wrapper.setProps({ blocked: false });
2022-09-06 12:03:37 +00:00
2022-12-29 09:39:06 +00:00
expect(unblockSpy).toHaveBeenCalled();
});
it('When block method triggered, mask should be added on DOM', async () => {
await wrapper.setProps({ fullScreen: true });
await wrapper.vm.block();
expect(document.querySelector('.p-blockui')).not.toBe(null);
});
it('When removeMask method triggered, isBlocked should be false and emitted', async () => {
wrapper = mount(BlockUI, {
props: {
blocked: true
},
slots: {
default: 'test'
}
});
await wrapper.vm.removeMask();
2022-09-06 12:03:37 +00:00
2022-12-29 09:39:06 +00:00
expect(wrapper.vm.isBlocked).toBe(false);
expect(wrapper.emitted().unblock.length).toBe(1);
2022-09-06 12:03:37 +00:00
});
});