primevue-mirror/components/lib/contextmenu/ContextMenu.spec.js

173 lines
6.5 KiB
JavaScript
Raw Normal View History

2022-09-06 12:03:37 +00:00
import { mount } from '@vue/test-utils';
2022-12-08 11:04:25 +00:00
import PrimeVue from 'primevue/config';
2022-09-06 12:03:37 +00:00
import ContextMenu from './ContextMenu.vue';
describe('ContextMenu.vue', () => {
let wrapper;
beforeEach(() => {
wrapper = mount(ContextMenu, {
global: {
plugins: [PrimeVue],
stubs: {
'router-link': true,
teleport: true
}
},
props: {
model: [
{
2022-09-14 11:26:01 +00:00
label: 'File',
icon: 'pi pi-fw pi-file',
items: [
2022-09-06 12:03:37 +00:00
{
2022-09-14 11:26:01 +00:00
label: 'New',
icon: 'pi pi-fw pi-plus',
items: [
2022-09-06 12:03:37 +00:00
{
2022-09-14 11:26:01 +00:00
label: 'Bookmark',
icon: 'pi pi-fw pi-bookmark'
2022-09-06 12:03:37 +00:00
},
{
2022-09-14 11:26:01 +00:00
label: 'Video',
icon: 'pi pi-fw pi-video'
}
]
2022-09-06 12:03:37 +00:00
},
{
2022-09-14 11:26:01 +00:00
label: 'Delete',
icon: 'pi pi-fw pi-trash'
2022-09-06 12:03:37 +00:00
},
{
2022-09-14 11:26:01 +00:00
separator: true
2022-09-06 12:03:37 +00:00
},
{
2022-09-14 11:26:01 +00:00
label: 'Export',
icon: 'pi pi-fw pi-external-link'
2022-09-06 12:03:37 +00:00
}
]
},
{
2022-09-14 11:26:01 +00:00
label: 'Edit',
icon: 'pi pi-fw pi-pencil',
items: [
2022-09-06 12:03:37 +00:00
{
2022-09-14 11:26:01 +00:00
label: 'Left',
icon: 'pi pi-fw pi-align-left'
2022-09-06 12:03:37 +00:00
},
{
2022-09-14 11:26:01 +00:00
label: 'Right',
icon: 'pi pi-fw pi-align-right'
2022-09-06 12:03:37 +00:00
},
{
2022-09-14 11:26:01 +00:00
label: 'Center',
icon: 'pi pi-fw pi-align-center'
2022-09-06 12:03:37 +00:00
},
{
2022-09-14 11:26:01 +00:00
label: 'Justify',
icon: 'pi pi-fw pi-align-justify'
}
2022-09-06 12:03:37 +00:00
]
},
{
2022-09-14 11:26:01 +00:00
label: 'Users',
icon: 'pi pi-fw pi-user',
items: [
2022-09-06 12:03:37 +00:00
{
2022-09-14 11:26:01 +00:00
label: 'New',
icon: 'pi pi-fw pi-user-plus'
2022-09-06 12:03:37 +00:00
},
{
2022-09-14 11:26:01 +00:00
label: 'Delete',
icon: 'pi pi-fw pi-user-minus'
2022-09-06 12:03:37 +00:00
},
{
2022-09-14 11:26:01 +00:00
label: 'Search',
icon: 'pi pi-fw pi-users',
items: [
2022-09-06 12:03:37 +00:00
{
2022-09-14 11:26:01 +00:00
label: 'Filter',
icon: 'pi pi-fw pi-filter',
items: [
2022-09-06 12:03:37 +00:00
{
2022-09-14 11:26:01 +00:00
label: 'Print',
icon: 'pi pi-fw pi-print'
2022-09-06 12:03:37 +00:00
}
]
},
{
2022-09-14 11:26:01 +00:00
icon: 'pi pi-fw pi-bars',
label: 'List'
2022-09-06 12:03:37 +00:00
}
]
}
]
},
{
2022-09-14 11:26:01 +00:00
label: 'Events',
icon: 'pi pi-fw pi-calendar',
items: [
2022-09-06 12:03:37 +00:00
{
2022-09-14 11:26:01 +00:00
label: 'Edit',
icon: 'pi pi-fw pi-pencil',
items: [
2022-09-06 12:03:37 +00:00
{
2022-09-14 11:26:01 +00:00
label: 'Save',
icon: 'pi pi-fw pi-calendar-plus'
2022-09-06 12:03:37 +00:00
},
{
2022-09-14 11:26:01 +00:00
label: 'Delete',
icon: 'pi pi-fw pi-calendar-minus'
}
2022-09-06 12:03:37 +00:00
]
},
{
2022-09-14 11:26:01 +00:00
label: 'Archieve',
icon: 'pi pi-fw pi-calendar-times',
items: [
2022-09-06 12:03:37 +00:00
{
2022-09-14 11:26:01 +00:00
label: 'Remove',
icon: 'pi pi-fw pi-calendar-minus'
2022-09-06 12:03:37 +00:00
}
]
}
]
},
{
2022-09-14 11:26:01 +00:00
separator: true
2022-09-06 12:03:37 +00:00
},
{
2022-09-14 11:26:01 +00:00
label: 'Quit',
icon: 'pi pi-fw pi-power-off'
2022-09-06 12:03:37 +00:00
}
]
}
});
});
2022-09-14 11:26:01 +00:00
it('should exist', async () => {
const event = { pageX: 100, pageY: 120, preventDefault: () => {}, stopPropagation: () => {} };
2022-12-08 14:13:16 +00:00
const show = vi.spyOn(wrapper.vm, 'show');
2022-09-06 12:03:37 +00:00
wrapper.vm.show(event);
await wrapper.setData({ visible: true });
2022-09-14 11:26:01 +00:00
2022-09-06 12:03:37 +00:00
expect(show).toHaveBeenCalled();
expect(wrapper.find('.p-contextmenu.p-component').exists()).toBe(true);
expect(wrapper.findAll('.p-menuitem').length).toBe(5);
expect(wrapper.findAll('.p-menuitem-text')[0].text()).toBe('File');
});
2022-09-14 11:26:01 +00:00
it('should hide menu', async () => {
2022-12-08 14:13:16 +00:00
const hide = vi.spyOn(wrapper.vm, 'hide');
2022-09-06 12:03:37 +00:00
await wrapper.setData({ visible: true });
wrapper.vm.hide();
await wrapper.setData({ visible: false });
expect(hide).toHaveBeenCalled();
expect(wrapper.find('.p-contextmenu.p-component').exists()).toBe(false);
});
2022-09-14 11:26:01 +00:00
});