2022-09-06 12:03:37 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import InputNumber from './InputNumber.vue';
|
|
|
|
|
|
|
|
describe('InputNumber.vue', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = mount(InputNumber, {
|
|
|
|
props: {
|
|
|
|
modelValue: 1
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is exist', () => {
|
|
|
|
expect(wrapper.find('.p-inputnumber.p-component').exists()).toBe(true);
|
|
|
|
expect(wrapper.find('input.p-inputnumber-input').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is keydown called when down and up keys pressed', async () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.vm.onInputKeyDown({ which: 38, target: { value: 1 }, preventDefault: () => {} });
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([2]);
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.vm.onInputKeyDown({ which: 40, target: { value: 2 }, preventDefault: () => {} });
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
expect(wrapper.emitted()['update:modelValue'][1]).toEqual([1]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is keydown called when tab key pressed', async () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.vm.onInputKeyDown({ which: 9, target: { value: '12' }, preventDefault: () => {} });
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([12]);
|
|
|
|
expect(wrapper.find('input.p-inputnumber-input').attributes()['aria-valuenow']).toBe('12');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is keydown called when enter key pressed', async () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.vm.onInputKeyDown({ which: 13, target: { value: '12' }, preventDefault: () => {} });
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([12]);
|
|
|
|
expect(wrapper.find('input.p-inputnumber-input').attributes()['aria-valuenow']).toBe('12');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is keypress called when pressed a number', async () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
wrapper.find('input.p-inputnumber-input').element.setSelectionRange(2, 2);
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.vm.onInputKeyPress({ which: 49, preventDefault: () => {} });
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
expect(wrapper.emitted().input[0][0].value).toBe(11);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is keypress called when pressed minus', async () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
wrapper.find('input.p-inputnumber-input').element.setSelectionRange(0, 0);
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.vm.onInputKeyPress({ keyCode: 45, preventDefault: () => {} });
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
expect(wrapper.emitted().input[0][0].value).toBe(-1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have min boundary', async () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.setProps({ modelValue: 95, min: 95 });
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.vm.onInputKeyDown({ which: 40, target: { value: 96 }, preventDefault: () => {} });
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([95]);
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.vm.onInputKeyDown({ which: 40, target: { value: 95 }, preventDefault: () => {} });
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
expect(wrapper.emitted()['update:modelValue'][1]).toEqual([95]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have max boundary', async () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.setProps({ modelValue: 99, max: 100 });
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.vm.onInputKeyDown({ which: 38, target: { value: 99 }, preventDefault: () => {} });
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([100]);
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.vm.onInputKeyDown({ which: 38, target: { value: 100 }, preventDefault: () => {} });
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
expect(wrapper.emitted()['update:modelValue'][1]).toEqual([100]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have currency', async () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.setProps({ modelValue: 12345, mode: 'currency', currency: 'USD', locale: 'en-US' });
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
expect(wrapper.find('input.p-inputnumber-input').element._value).toBe('$12,345.00');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have prefix', async () => {
|
|
|
|
await wrapper.setProps({ modelValue: 20, prefix: '%' });
|
|
|
|
|
|
|
|
expect(wrapper.find('input.p-inputnumber-input').element._value).toBe('%20');
|
|
|
|
});
|
2022-09-14 11:26:01 +00:00
|
|
|
});
|