pull/5110/head
Cagatay Civici 2024-01-18 12:56:11 +03:00
commit db198275a4
13 changed files with 50 additions and 73 deletions

View File

@ -75,6 +75,10 @@ const MessageEvents = [
description: 'Browser event' description: 'Browser event'
} }
] ]
},
{
name: 'life-end',
description: "Callback to invoke when the message's timeout is over."
} }
]; ];

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

@ -140,11 +140,12 @@ export default {
}, },
onPaste(event) { onPaste(event) {
if (this.separator) { if (this.separator) {
let separator = this.separator.replace('\\n', '\n').replace('\\r', '\r').replace('\\t', '\t');
let pastedData = (event.clipboardData || window['clipboardData']).getData('Text'); let pastedData = (event.clipboardData || window['clipboardData']).getData('Text');
if (pastedData) { if (pastedData) {
let value = this.modelValue || []; let value = this.modelValue || [];
let pastedValues = pastedData.split(this.separator); let pastedValues = pastedData.split(separator);
pastedValues = pastedValues.filter((val) => this.allowDuplicate || value.indexOf(val) === -1); pastedValues = pastedValues.filter((val) => this.allowDuplicate || value.indexOf(val) === -1);
value = [...value, ...pastedValues]; value = [...value, ...pastedValues];

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

@ -877,9 +877,16 @@ export default {
selectionEnd = sRegex.lastIndex + tRegex.lastIndex; selectionEnd = sRegex.lastIndex + tRegex.lastIndex;
this.$refs.input.$el.setSelectionRange(selectionEnd, selectionEnd); this.$refs.input.$el.setSelectionRange(selectionEnd, selectionEnd);
} else if (newLength === currentLength) { } else if (newLength === currentLength) {
if (operation === 'insert' || operation === 'delete-back-single') this.$refs.input.$el.setSelectionRange(selectionEnd + 1, selectionEnd + 1); if (operation === 'insert' || operation === 'delete-back-single') {
else if (operation === 'delete-single') this.$refs.input.$el.setSelectionRange(selectionEnd - 1, selectionEnd - 1); const re = /[.,]/g;
else if (operation === 'delete-range' || operation === 'spin') this.$refs.input.$el.setSelectionRange(selectionEnd, selectionEnd); const newSelectionEnd = selectionEnd + Number(re.test(value) || re.test(insertedValueStr));
this.$refs.input.$el.setSelectionRange(newSelectionEnd, newSelectionEnd);
} else if (operation === 'delete-single') {
this.$refs.input.$el.setSelectionRange(selectionEnd - 1, selectionEnd - 1);
} else if (operation === 'delete-range' || operation === 'spin') {
this.$refs.input.$el.setSelectionRange(selectionEnd, selectionEnd);
}
} else if (operation === 'delete-back-single') { } else if (operation === 'delete-back-single') {
let prevChar = inputValue.charAt(selectionEnd - 1); let prevChar = inputValue.charAt(selectionEnd - 1);
let nextChar = inputValue.charAt(selectionEnd); let nextChar = inputValue.charAt(selectionEnd);

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

@ -218,6 +218,10 @@ export interface MessageEmits {
* @param {Event} event - Browser event. * @param {Event} event - Browser event.
*/ */
close(event: Event): void; close(event: Event): void;
/**
* Callback to invoke when the message's timeout is over.
*/
'life-end'(): void;
} }
/** /**

View File

@ -32,7 +32,7 @@ import BaseMessage from './BaseMessage.vue';
export default { export default {
name: 'Message', name: 'Message',
extends: BaseMessage, extends: BaseMessage,
emits: ['close'], emits: ['close', 'life-end'],
timeout: null, timeout: null,
data() { data() {
return { return {
@ -59,6 +59,7 @@ export default {
closeAfterDelay() { closeAfterDelay() {
setTimeout(() => { setTimeout(() => {
this.visible = false; this.visible = false;
this.$emit('life-end');
}, this.life); }, this.life);
} }
}, },

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', () => {

View File

@ -35239,6 +35239,12 @@
], ],
"returnType": "void", "returnType": "void",
"description": "Callback to invoke when a message is closed." "description": "Callback to invoke when a message is closed."
},
{
"name": "life-end",
"parameters": [],
"returnType": "void",
"description": "Callback to invoke when the message's timeout is over."
} }
] ]
} }