Vitest unit test configs completed. All tests pass

pull/3420/head
Bahadir Sofuoglu 2022-09-14 16:17:12 +03:00
parent cb3e230f5f
commit eb2de5460c
33 changed files with 116 additions and 66 deletions

View File

@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils';
import Accordion from '@/components/accordion/Accordion.vue';
import AccordionTab from '@/components/accordiontab/AccordionTab.vue';
import Accordion from '../accordion/Accordion.vue';
import AccordionTab from '../accordiontab/AccordionTab.vue';
describe('Accordion.vue', () => {
let wrapper;

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils';
import AccordionTab from '@/components/accordiontab/AccordionTab.vue';
import AccordionTab from '../accordiontab/AccordionTab.vue';
describe('AccordionTab.vue', () => {
it('should exists', () => {

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils';
import PrimeVue from '@/components/config/PrimeVue';
import PrimeVue from '../config/PrimeVue';
import AutoComplete from './AutoComplete.vue';
describe('AutoComplete.vue', () => {

View File

@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils';
import AvatarGroup from './AvatarGroup.vue';
import Avatar from '@/components/avatar/Avatar.vue';
import Avatar from '../avatar/Avatar.vue';
describe('AvatarGroup.vue', () => {
it('should exist', () => {

View File

@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils';
import Badge from './Badge.vue';
import Button from '@/components/button/Button.vue';
import Button from '../button/Button.vue';
describe('Badge.vue', () => {
it('should exist', () => {

View File

@ -1,18 +1,27 @@
import { config, mount } from '@vue/test-utils';
import BlockUI from './BlockUI.vue';
import Panel from '@/components/panel/Panel.vue';
import Button from '@/components/button/Button.vue';
import Panel from '../panel/Panel.vue';
import Button from '../button/Button.vue';
config.global.mocks = {
$primevue: {
config: {
zIndex: {
modal: 1100
}
}
},
},
DomHandler: {
addClass: vi.fn(),
removeClass: vi.fn(),
},
ZIndexUtils: {
set: vi.fn(),
clear: vi.fn(),
},
}
};
describe('BlockUI.vue', () => {
it('should blocked and unblocked the panel', async () => {
const wrapper = mount({

View File

@ -1,6 +1,6 @@
import { h } from 'vue';
import { mount } from '@vue/test-utils';
import Button from '@/components/button/Button.vue';
import Button from '../button/Button.vue';
describe('Button.vue', () => {
it('is Button element exist', () => {

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils';
import PrimeVue from '@/components/config/PrimeVue';
import PrimeVue from '../config/PrimeVue';
import Calendar from './Calendar.vue';
describe('Calendar.vue', () => {
@ -37,7 +37,7 @@ describe('Calendar.vue', () => {
const event = { day: 8, month: 2, year: 2022, today: false, selectable: true };
const onDateSelect = jest.spyOn(wrapper.vm, 'onDateSelect');
const onDateSelect = vi.spyOn(wrapper.vm, 'onDateSelect');
await wrapper.vm.onDateSelect({ currentTarget: { focus: () => {} } }, event);
expect(onDateSelect).toHaveBeenCalled();

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils';
import PrimeVue from '@/components/config/PrimeVue';
import PrimeVue from '../config/PrimeVue';
import CascadeSelect from './CascadeSelect.vue';
describe('CascadeSelect.vue', () => {

View File

@ -19,7 +19,7 @@ describe('Chips.vue', () => {
});
it('should add item', async () => {
const addItem = jest.spyOn(wrapper.vm, 'addItem');
const addItem = vi.spyOn(wrapper.vm, 'addItem');
await wrapper.vm.addItem({}, 'PrimeVue', false);

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils';
import PrimeVue from '@/components/config/PrimeVue';
import PrimeVue from '../config/PrimeVue';
import ColorPicker from './ColorPicker.vue';
describe('ColorPicker.vue', () => {
@ -26,7 +26,7 @@ describe('ColorPicker.vue', () => {
it('should input click triggered', async () => {
const input = wrapper.find('.p-colorpicker-preview.p-inputtext');
const onInputClick = jest.spyOn(wrapper.vm, 'onInputClick');
const onInputClick = vi.spyOn(wrapper.vm, 'onInputClick');
await input.trigger('click');
@ -41,8 +41,8 @@ describe('ColorPicker.vue', () => {
await input.trigger('click');
const onColorMousedown = jest.spyOn(wrapper.vm, 'onColorMousedown');
const onHueMousedown = jest.spyOn(wrapper.vm, 'onHueMousedown');
const onColorMousedown = vi.spyOn(wrapper.vm, 'onColorMousedown');
const onHueMousedown = vi.spyOn(wrapper.vm, 'onHueMousedown');
const event = { pageX: 100, pageY: 120, preventDefault: () => {} };
const event2 = { pageX: 70, pageY: 20, preventDefault: () => {} };

View File

@ -1,4 +1,4 @@
import PrimeVue from '@/components/config/PrimeVue';
import PrimeVue from '../config/PrimeVue';
import { mount } from '@vue/test-utils';
import ConfirmDialog from './ConfirmDialog.vue';
@ -62,7 +62,7 @@ describe('ConfirmDialog', () => {
}
});
const acceptTriggered = jest.spyOn(wrapper.componentVM.confirmation, 'accept');
const acceptTriggered = vi.spyOn(wrapper.componentVM.confirmation, 'accept');
await wrapper.setData({ visible: true });
@ -101,7 +101,7 @@ describe('ConfirmDialog', () => {
}
});
const rejectTriggered = jest.spyOn(wrapper.componentVM.confirmation, 'reject');
const rejectTriggered = vi.spyOn(wrapper.componentVM.confirmation, 'reject');
await wrapper.setData({ visible: true });

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils';
import PrimeVue from '@/components/config/PrimeVue';
import PrimeVue from '../config/PrimeVue';
import ContextMenu from './ContextMenu.vue';
describe('ContextMenu.vue', () => {
@ -147,7 +147,7 @@ describe('ContextMenu.vue', () => {
it('should exist', async () => {
const event = { pageX: 100, pageY: 120, preventDefault: () => {}, stopPropagation: () => {} };
const show = jest.spyOn(wrapper.vm, 'show');
const show = vi.spyOn(wrapper.vm, 'show');
wrapper.vm.show(event);
await wrapper.setData({ visible: true });
@ -159,7 +159,7 @@ describe('ContextMenu.vue', () => {
});
it('should hide menu', async () => {
const hide = jest.spyOn(wrapper.vm, 'hide');
const hide = vi.spyOn(wrapper.vm, 'hide');
await wrapper.setData({ visible: true });

View File

@ -1,10 +1,10 @@
import { mount } from '@vue/test-utils';
import DataTable from './DataTable.vue';
import ColumnGroup from '@/components/columngroup/ColumnGroup.vue';
import Row from '@/components/row/Row.vue';
import Column from '@/components/column/Column.vue';
import Button from '@/components/button/Button.vue';
import InputText from '@/components/inputtext/InputText.vue';
import ColumnGroup from '../columngroup/ColumnGroup.vue';
import Row from '../row/Row.vue';
import Column from '../column/Column.vue';
import Button from '../button/Button.vue';
import InputText from '../inputtext/InputText.vue';
import { FilterMatchMode } from 'primevue/api';
window.URL.createObjectURL = function () {};
@ -301,7 +301,7 @@ describe('DataTable.vue', () => {
const sortableTH = wrapper.findAll('.p-sortable-column')[0];
const firstCellText = wrapper.findAll('.p-datatable-tbody > tr')[0].findAll('td')[1].text();
const headerClick = jest.spyOn(wrapper.vm, 'onColumnHeaderClick');
const headerClick = vi.spyOn(wrapper.vm, 'onColumnHeaderClick');
await sortableTH.trigger('click');
@ -333,7 +333,7 @@ describe('DataTable.vue', () => {
const sortableTHs = wrapper.findAll('.p-sortable-column');
const firstCellText = wrapper.findAll('.p-datatable-tbody > tr')[0].findAll('td')[1].text();
const headerClick = jest.spyOn(wrapper.vm, 'onColumnHeaderClick');
const headerClick = vi.spyOn(wrapper.vm, 'onColumnHeaderClick');
await sortableTHs[0].trigger('click');
@ -1338,7 +1338,7 @@ describe('DataTable.vue', () => {
// export
it('should export table', async () => {
const exportCSV = jest.spyOn(wrapper.vm, 'exportCSV');
const exportCSV = vi.spyOn(wrapper.vm, 'exportCSV');
await wrapper.vm.exportCSV();
@ -1355,8 +1355,8 @@ describe('DataTable.vue', () => {
});
it('should save session storage', async () => {
jest.spyOn(window.sessionStorage.__proto__, 'setItem');
window.sessionStorage.__proto__.setItem = jest.fn();
vi.spyOn(window.sessionStorage.__proto__, 'setItem');
window.sessionStorage.__proto__.setItem = vi.fn();
await wrapper.vm.saveState();
@ -1365,8 +1365,8 @@ describe('DataTable.vue', () => {
});
it('should save local storage', async () => {
jest.spyOn(window.localStorage.__proto__, 'setItem');
window.localStorage.__proto__.setItem = jest.fn();
vi.spyOn(window.localStorage.__proto__, 'setItem');
window.localStorage.__proto__.setItem = vi.fn();
await wrapper.vm.saveState();

View File

@ -1,4 +1,4 @@
import PrimeVue from '@/components/config/PrimeVue';
import PrimeVue from '../config/PrimeVue';
import { mount } from '@vue/test-utils';
import Dialog from './Dialog.vue';

View File

@ -1,7 +1,7 @@
import { h } from 'vue';
import { mount } from '@vue/test-utils';
import PrimeVue from '@/components/config/PrimeVue';
import Dropdown from '@/components/dropdown/Dropdown.vue';
import PrimeVue from '../config/PrimeVue';
import Dropdown from '../dropdown/Dropdown.vue';
describe('Dropdown.vue', () => {
let wrapper;
@ -22,10 +22,11 @@ describe('Dropdown.vue', () => {
it('should Dropdown exist', () => {
expect(wrapper.find('.p-dropdown.p-component').exists()).toBe(true);
expect(wrapper.find('.p-dropdown-panel').exists()).toBe(true);
expect(wrapper.find('.p-dropdown-empty-message').exists()).toBe(true);
expect(wrapper.find('.p-focus').exists()).toBe(true);
expect(wrapper.find('.p-focus').exists()).toBe(false);
expect(wrapper.find('.p-inputwrapper-filled').exists()).toBe(false);
expect(wrapper.find('.p-inputwrapper-focus').exists()).toBe(true);
expect(wrapper.find('.p-inputwrapper-focus').exists()).toBe(true);
});
});
@ -319,7 +320,7 @@ describe('filter checks', () => {
expect(filterInput.exists()).toBe(true);
const event = { target: { value: 'c' } };
const onFilterChange = jest.spyOn(wrapper.vm, 'onFilterChange');
const onFilterChange = vi.spyOn(wrapper.vm, 'onFilterChange');
wrapper.vm.onFilterChange(event);
await wrapper.vm.$nextTick();

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils';
import PrimeVue from '@/components/config/PrimeVue';
import PrimeVue from '../config/PrimeVue';
import Galleria from './Galleria.vue';
describe('Gallleria.vue', () => {

View File

@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils';
import Inplace from './Inplace.vue';
import InputText from '@/components/inputtext/InputText.vue';
import InputText from '../inputtext/InputText.vue';
describe('Inplace.vue', () => {
it('should exist', () => {

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils';
import PrimeVue from '@/components/config/PrimeVue';
import PrimeVue from '../config/PrimeVue';
import Menu from './Menu.vue';
describe('Menu.vue', () => {

View File

@ -46,7 +46,9 @@ describe('Message.vue', () => {
});
it('should sticky and life works', async () => {
jest.runTimersToTime(3001);
expect(wrapper.vm.visible).toBe(false);
setTimeout(() => {
expect(wrapper.vm.visible).toBe(false);
}, 3000);
});
});

View File

@ -1,4 +1,4 @@
import PrimeVue from '@/components/config/PrimeVue';
import PrimeVue from '../config/PrimeVue';
import { mount } from '@vue/test-utils';
import MultiSelect from './MultiSelect.vue';

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils';
import PrimeVue from '@/components/config/PrimeVue';
import PrimeVue from '../config/PrimeVue';
import OverlayPanel from './OverlayPanel.vue';
describe('OverlayPanel.vue', () => {

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils';
import PrimeVue from '@/components/config/PrimeVue';
import PrimeVue from '../config/PrimeVue';
import Sidebar from './Sidebar.vue';
describe('Sidebar.vue', () => {

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils';
import PrimeVue from '@/components/config/PrimeVue';
import PrimeVue from '../config/PrimeVue';
import SplitButton from './SplitButton.vue';
describe('SplitButton.vue', () => {

View File

@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils';
import Splitter from './Splitter.vue';
import SplitterPanel from '@/components/splitterpanel/SplitterPanel.vue';
import SplitterPanel from '../splitterpanel/SplitterPanel.vue';
describe('Splitter.vue', () => {
let wrapper;

View File

@ -1,7 +1,7 @@
import { config, mount } from '@vue/test-utils';
import StyleClass from './StyleClass';
import Button from '@/components/button/Button.vue';
import InputText from '@/components/inputtext/InputText.vue';
import Button from '../button/Button.vue';
import InputText from '../inputtext/InputText.vue';
config.global.directives = {
styleclass: StyleClass

View File

@ -1,4 +1,4 @@
import TabPanel from '@/components/tabpanel/TabPanel.vue';
import TabPanel from '../tabpanel/TabPanel.vue';
import { mount } from '@vue/test-utils';
import TabView from './TabView.vue';

View File

@ -1,6 +1,6 @@
import { h } from 'vue';
import { mount } from '@vue/test-utils';
import Tag from '@/components/tag/Tag.vue';
import Tag from '../tag/Tag.vue';
describe('Tag.vue', () => {
it('is Tag element exist', () => {

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils';
import TerminalService from '@/components/terminalservice/TerminalService';
import TerminalService from '../terminalservice/TerminalService';
import Terminal from './Terminal.vue';
describe('Terminal.vue', () => {

View File

@ -53,7 +53,7 @@ describe('TriStateCheckbox.vue', () => {
});
});
it('When onClick method triggered some methods effect', () => {
const mockUpdateModel = jest.fn();
const mockUpdateModel = vi.fn();
wrapper.vm.updateModel = mockUpdateModel;
@ -71,7 +71,7 @@ describe('TriStateCheckbox.vue', () => {
});
it('When event.code is equal Enter some methods should be triggered', async () => {
const mockUpdateModel = jest.fn();
const mockUpdateModel = vi.fn();
wrapper.vm.updateModel = mockUpdateModel;

2
package-lock.json generated
View File

@ -33,7 +33,7 @@
"rollup-plugin-vue": "^6.0.0-beta.9",
"sass": "^1.45.0",
"sass-loader": "^8.0.2",
"vitest": "^0.23.2"
"vitest": "^0.23.0"
}
},
"node_modules/@ampproject/remapping": {

View File

@ -1,5 +1,12 @@
{
"private": true,
"name": "primevue",
"version": "3.17.1-SNAPSHOT",
"homepage": "https://www.primefaces.org/primevue",
"repository": {
"type": "git",
"url": "https://github.com/primefaces/primevue.git"
},
"license": "MIT",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
@ -8,7 +15,7 @@
"postinstall": "nuxt prepare",
"testRollup": "rollup -c",
"testgulp": "gulp build-styles",
"test": "vitest"
"test:unit": "vitest"
},
"devDependencies": {
"@fullcalendar/core": "^5.11.0",
@ -38,6 +45,6 @@
"rollup-plugin-vue": "^6.0.0-beta.9",
"sass": "^1.45.0",
"sass-loader": "^8.0.2",
"vitest": "^0.23.2"
"vitest": "^0.23.0"
}
}

View File

@ -1,4 +1,5 @@
import vue from '@vitejs/plugin-vue';
import path from 'path'
export default {
plugins: [vue()],
@ -6,4 +7,34 @@ export default {
globals: true,
environment: 'jsdom',
},
resolve: {
alias: {
'primevue/ripple': path.resolve(__dirname, '/components/ripple/Ripple.js'),
'primevue/tooltip': path.resolve(__dirname, '/components/tooltip/Tooltip.js'),
'primevue/useconfirm': path.resolve(__dirname, '/components/useconfirm/UseConfirm.js'),
'primevue/usetoast': path.resolve(__dirname, '/components/usetoast/UseToast.js'),
'primevue/usedialog': path.resolve(__dirname, '/components/usedialog/UseDialog.js'),
'primevue/utils': path.resolve(__dirname, '/components/utils/Utils.js'),
'primevue/api': path.resolve(__dirname, '/components/api/Api.js'),
'primevue/portal': path.resolve(__dirname, '/components/portal/Portal.vue'),
'primevue/button': path.resolve(__dirname, '/components/button/Button.vue'),
'primevue/inputtext': path.resolve(__dirname, '/components/inputtext/InputText.vue'),
'primevue/dialog': path.resolve(__dirname, '/components/dialog/Dialog.vue'),
'primevue/menu': path.resolve(__dirname, '/components/menu/Menu.vue'),
'primevue/tieredmenu': path.resolve(__dirname, '/components/tieredmenu/TieredMenu.vue'),
'primevue/dropdown': path.resolve(__dirname, '/components/dropdown/Dropdown.vue'),
'primevue/inputnumber': path.resolve(__dirname, '/components/inputnumber/InputNumber.vue'),
'primevue/paginator': path.resolve(__dirname, '/components/paginator/Paginator.vue'),
'primevue/progressbar': path.resolve(__dirname, '/components/progressbar/ProgressBar.vue'),
'primevue/message': path.resolve(__dirname, '/components/message/Message.vue'),
'primevue/tree': path.resolve(__dirname, '/components/tree/Tree.vue'),
'primevue/confirmationeventbus': path.resolve(__dirname, '/components/confirmationeventbus/ConfirmationEventBus.js'),
'primevue/toasteventbus': path.resolve(__dirname, '/components/toasteventbus/ToastEventBus.js'),
'primevue/overlayeventbus': path.resolve(__dirname, '/components/overlayeventbus/OverlayEventBus.js'),
'primevue/terminalservice': path.resolve(__dirname, '/components/terminalservice/TerminalService.js'),
'primevue/dynamicdialogeventbus': path.resolve(__dirname, '/components/dynamicdialogeventbus/DynamicDialogEventBus.js'),
'primevue/virtualscroller': path.resolve(__dirname, '/components/virtualscroller/VirtualScroller.vue')
},
},
}