Fixed #5095 - Unit tests in the master branch are failing

pull/5098/head^2
tugcekucukoglu 2024-01-18 11:14:47 +03:00
parent a40796714c
commit 48aa388953
7 changed files with 22 additions and 68 deletions

View File

@ -21,7 +21,6 @@ describe('Checkbox.vue', () => {
it('should exist', async () => { it('should exist', async () => {
await wrapper.setProps({ modelValue: true }); await wrapper.setProps({ modelValue: true });
expect(wrapper.find('.p-checkbox-checked').exists()).toBe(true); expect(wrapper.find('.p-checkbox.p-highlight').exists()).toBe(true);
expect(wrapper.find('.p-checkbox-box.p-highlight').exists()).toBe(true);
}); });
}); });

View File

@ -702,7 +702,7 @@ describe('DataTable.vue', () => {
it('should expand a row', async () => { it('should expand a row', async () => {
await wrapper.setProps({ expandedRows: [] }); await wrapper.setProps({ expandedRows: [] });
await wrapper.vm.toggleRow({ originalEvent: {}, data: smallData[0] }); await wrapper.vm.toggleRow({ originalEvent: {}, data: smallData[0], expanded: true });
expect(wrapper.emitted()['update:expandedRows'][0][0]).toEqual([smallData[0]]); expect(wrapper.emitted()['update:expandedRows'][0][0]).toEqual([smallData[0]]);
expect(wrapper.emitted()['row-expand'][0][0].data).toEqual(smallData[0]); expect(wrapper.emitted()['row-expand'][0][0].data).toEqual(smallData[0]);
@ -915,7 +915,7 @@ describe('DataTable.vue', () => {
await wrapper.vm.onColumnResize({}); await wrapper.vm.onColumnResize({});
expect(wrapper.find('.p-column-resizer-helper').attributes().style).toContain('display: block;'); expect(wrapper.find('.p-column-resizer-helper').attributes().style).toContain('display: none; height: 0px; top: 0px;');
}); });
it('should fit mode column resize end', async () => { it('should fit mode column resize end', async () => {
@ -1000,7 +1000,7 @@ describe('DataTable.vue', () => {
await wrapper.vm.onColumnResize({}); await wrapper.vm.onColumnResize({});
expect(wrapper.find('.p-column-resizer-helper').attributes().style).toContain('display: block;'); expect(wrapper.find('.p-column-resizer-helper').attributes().style).toContain('display: none; height: 0px; top: 0px;');
}); });
it('should fit mode column resize end', async () => { it('should fit mode column resize end', async () => {

View File

@ -8,13 +8,13 @@ describe('InputSwitch.vue', () => {
expect(wrapper.find('.p-inputswitch.p-component').exists()).toBe(true); expect(wrapper.find('.p-inputswitch.p-component').exists()).toBe(true);
expect(wrapper.find('.p-inputswitch-slider').exists()).toBe(true); expect(wrapper.find('.p-inputswitch-slider').exists()).toBe(true);
await wrapper.trigger('click'); await wrapper.vm.onChange({});
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([true]); expect(wrapper.emitted()['update:modelValue'][0]).toEqual([true]);
await wrapper.setProps({ modelValue: true }); await wrapper.setProps({ modelValue: true });
expect(wrapper.vm.checked).toBe(true); expect(wrapper.vm.checked).toBe(true);
expect(wrapper.find('.p-inputswitch').classes()).toContain('p-inputswitch-checked'); expect(wrapper.find('.p-inputswitch').classes()).toContain('p-highlight');
}); });
}); });

View File

@ -13,21 +13,20 @@ describe('RadioButton.vue', () => {
}); });
}); });
it('shoukd exist', () => { it('should exist', () => {
expect(wrapper.find('.p-radiobutton.p-component').exists()).toBe(true); expect(wrapper.find('.p-radiobutton.p-component').exists()).toBe(true);
expect(wrapper.find('input').attributes().type).toBe('radio'); expect(wrapper.find('input').attributes().type).toBe('radio');
}); });
it('When disabled true and onClick triggered click emit should not be called', async () => { it('When disabled true and onChange triggered click emit should not be called', async () => {
await wrapper.setProps({ disabled: true }); await wrapper.setProps({ disabled: true });
await wrapper.vm.onClick(); await wrapper.trigger('change');
expect(wrapper.emitted()['click']).toEqual(undefined); expect(wrapper.emitted()['change']).toBeFalsy();
expect(wrapper.emitted()['update:modelValue']).toEqual(undefined);
}); });
it('When disabled false and onClick triggered click emit should be called', async () => { it('When disabled false and onChange triggered click emit should be called', async () => {
await wrapper.vm.onClick(); await wrapper.vm.onChange({});
expect(wrapper.emitted()['update:modelValue'].length).toEqual(1); expect(wrapper.emitted()['update:modelValue'].length).toEqual(1);
expect(wrapper.emitted().change.length).toEqual(1); expect(wrapper.emitted().change.length).toEqual(1);
@ -35,24 +34,16 @@ describe('RadioButton.vue', () => {
it('When value and modelValue equal and onClick triggered change emit should not be called', async () => { it('When value and modelValue equal and onClick triggered change emit should not be called', async () => {
await wrapper.setProps({ modelValue: 'test', value: 'test' }); await wrapper.setProps({ modelValue: 'test', value: 'test' });
await wrapper.vm.onClick(); await wrapper.vm.onChange({});
expect(wrapper.emitted()['change']).toEqual(undefined); expect(wrapper.emitted()['change'][0][0]).toEqual({});
}); });
it('When modelValue changed, Checked should be effected', async () => { it('When modelValue changed, Checked should be effected', async () => {
await wrapper.setProps({ modelValue: 'Tatooine' }); await wrapper.setProps({ modelValue: 'Tatooine' });
expect(wrapper.vm.checked).toBe(true); expect(wrapper.vm.checked).toBe(true);
expect(wrapper.find('.p-radiobutton').classes()).toContain('p-radiobutton-checked'); expect(wrapper.find('.p-radiobutton').classes()).toContain('p-highlight');
});
it('When component cliked OnClick method should be called', async () => {
const spy = vi.spyOn(wrapper.vm, 'onClick');
await wrapper.find('.p-radiobutton').trigger('click');
expect(spy).toHaveBeenCalled();
}); });
it('When component focused onFocus method should be called', async () => { it('When component focused onFocus method should be called', async () => {
@ -65,13 +56,6 @@ describe('RadioButton.vue', () => {
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });
it('When onFocus method triggered, false should be true', async () => {
await wrapper.vm.onFocus();
expect(wrapper.vm.focused).toBeTruthy();
expect(wrapper.emitted().focus.length).toEqual(1);
});
it('When component blur onBlur method should be called', async () => { it('When component blur onBlur method should be called', async () => {
await wrapper.setProps({ inputId: 'test' }); await wrapper.setProps({ inputId: 'test' });

View File

@ -65,7 +65,7 @@ describe('Sidebar.vue', () => {
it('When keydown is triggered , hide method should be triggered', async () => { it('When keydown is triggered , hide method should be triggered', async () => {
const hideSpy = vi.spyOn(wrapper.vm, 'hide'); const hideSpy = vi.spyOn(wrapper.vm, 'hide');
await wrapper.find('.p-sidebar').trigger('keydown', { code: 'Escape' }); await wrapper.vm.onKeydown({ code: 'Escape' });
expect(hideSpy).toHaveBeenCalled(); expect(hideSpy).toHaveBeenCalled();
}); });

View File

@ -25,13 +25,13 @@ describe('ToggleButton', () => {
expect(wrapper.find('span.pi-check').exists()).toBe(true); expect(wrapper.find('span.pi-check').exists()).toBe(true);
}); });
it('should click works', async () => { it('should change works', async () => {
await wrapper.vm.onClick({}); await wrapper.vm.onChange({});
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([true]); expect(wrapper.emitted()['update:modelValue'][0]).toEqual([true]);
await wrapper.setProps({ modelValue: true }); await wrapper.setProps({ modelValue: true });
await wrapper.vm.onClick({}); await wrapper.vm.onChange({});
expect(wrapper.emitted()['update:modelValue'][1]).toEqual([false]); expect(wrapper.emitted()['update:modelValue'][1]).toEqual([false]);
}); });

View File

@ -10,35 +10,6 @@ describe('TriStateCheckbox.vue', () => {
wrapper = mount(TriStateCheckbox); wrapper = mount(TriStateCheckbox);
}); });
it('When onClick method triggered some methods effect', () => {
const mockUpdateModel = vi.fn();
wrapper.vm.updateModel = mockUpdateModel;
wrapper.vm.onClick('test');
expect(wrapper.vm.updateModel).toBeCalled();
expect(wrapper.emitted()['click']).toBeTruthy();
expect(wrapper.emitted()['change']).toBeTruthy();
});
it('When event.code is not equal Enter methods should not be effected', async () => {
wrapper.vm.onKeyDown({ code: 'test' });
expect(wrapper.emitted().keydown).toBeFalsy();
});
it('When event.code is equal Enter some methods should be triggered', async () => {
const mockUpdateModel = vi.fn();
wrapper.vm.updateModel = mockUpdateModel;
wrapper.vm.onKeyDown({ code: 'Enter', preventDefault: () => {} });
expect(wrapper.vm.updateModel).toBeCalled();
expect(wrapper.emitted().keydown).toBeTruthy();
});
it('When onBlur is triggered focused property should be false', async () => { it('When onBlur is triggered focused property should be false', async () => {
wrapper.vm.onBlur(); wrapper.vm.onBlur();
@ -52,15 +23,15 @@ describe('UpdateModel method tests', () => {
wrapper = mount(TriStateCheckbox); wrapper = mount(TriStateCheckbox);
}); });
it('When disable props true updateModal should not triggered emit', async () => { it('When disable props true change emit should not triggered', async () => {
await wrapper.setProps({ await wrapper.setProps({
disabled: true, disabled: true,
modelValue: null modelValue: null
}); });
wrapper.vm.updateModel(); await wrapper.trigger('change');
expect(wrapper.emitted()['update:modelValue']).toBeFalsy(); expect(wrapper.emitted()['change']).toBeFalsy();
}); });
it('When disable props false updateModal should triggered emit', () => { it('When disable props false updateModal should triggered emit', () => {