2023-01-04 15:24:25 +00:00
|
|
|
import { RouterLinkStub, shallowMount } from '@vue/test-utils';
|
2023-01-04 22:55:53 +00:00
|
|
|
import { beforeEach, expect } from 'vitest';
|
2023-01-04 15:24:25 +00:00
|
|
|
import BreadcrumbItem from './BreadcrumbItem.vue';
|
|
|
|
|
|
|
|
let wrapper = null;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallowMount(BreadcrumbItem, {
|
|
|
|
global: {
|
|
|
|
mocks: {
|
|
|
|
$router: {
|
|
|
|
currentRoute: {
|
|
|
|
path: vi.fn()
|
|
|
|
},
|
|
|
|
navigate: () => true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
'router-link': RouterLinkStub
|
|
|
|
}
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
item: { label: 'Computer', visible: () => true },
|
2023-08-31 09:46:08 +00:00
|
|
|
templates: {
|
|
|
|
item: undefined
|
|
|
|
}
|
2023-01-04 15:24:25 +00:00
|
|
|
}
|
|
|
|
});
|
2023-01-04 22:55:53 +00:00
|
|
|
});
|
2023-01-04 15:24:25 +00:00
|
|
|
|
2023-01-04 22:55:53 +00:00
|
|
|
afterEach(() => {
|
|
|
|
vi.clearAllMocks();
|
2023-01-04 15:24:25 +00:00
|
|
|
});
|
2023-01-04 22:55:53 +00:00
|
|
|
|
2023-01-04 15:24:25 +00:00
|
|
|
describe('BreadcrumbItem', () => {
|
2023-08-31 09:46:08 +00:00
|
|
|
it('When component is mount and template.item equal to null, text should not be exists', () => {
|
|
|
|
expect(wrapper.find('.p-menuitem-text').exists()).toBe(false);
|
2023-01-04 15:24:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('When tag is triggered, onClick method should be called', async () => {
|
|
|
|
const onClickSpy = vi.spyOn(wrapper.vm, 'onClick');
|
|
|
|
const tag = wrapper.find('a');
|
|
|
|
|
|
|
|
tag.trigger('click');
|
|
|
|
expect(tag.exists()).toBe(true);
|
|
|
|
expect(onClickSpy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('When onClick method called and item has a command callback, callback should be triggered', async () => {
|
|
|
|
await wrapper.setProps({ item: { label: 'Computer', visible: () => false, command: vi.fn() } });
|
|
|
|
|
|
|
|
const spy = vi.spyOn(wrapper.vm.item, 'command');
|
|
|
|
|
|
|
|
wrapper.vm.onClick();
|
|
|
|
expect(spy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('When item prop has a visible, visible method should be return falsy', async () => {
|
|
|
|
await wrapper.setProps({ item: { label: 'Computer', visible: false, command: vi.fn() } });
|
|
|
|
|
|
|
|
expect(wrapper.vm.visible()).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('When item prop has a disabled function, disabled method should be return truthy', async () => {
|
|
|
|
await wrapper.setProps({ item: { disabled: () => true } });
|
|
|
|
|
|
|
|
expect(wrapper.vm.disabled()).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('When item prop has a label function, disabled method should be return truthy', async () => {
|
|
|
|
await wrapper.setProps({ item: { label: () => true } });
|
|
|
|
|
|
|
|
expect(wrapper.vm.label()).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('When item prop has a icon, icon element class should contain item prop icon', async () => {
|
|
|
|
await wrapper.setProps({ item: { icon: 'pi-discord' } });
|
|
|
|
|
|
|
|
expect(wrapper.find('a > span').classes()).toContain('pi-discord');
|
|
|
|
});
|
|
|
|
});
|