diff --git a/projects/ui/src/lib/components/po-field/po-input/po-mask.spec.ts b/projects/ui/src/lib/components/po-field/po-input/po-mask.spec.ts index 386c7b7eea..b334961db1 100644 --- a/projects/ui/src/lib/components/po-field/po-input/po-mask.spec.ts +++ b/projects/ui/src/lib/components/po-field/po-input/po-mask.spec.ts @@ -473,6 +473,40 @@ describe('PoMask', () => { expect(fakeThis.finalPosition).toBe(fakeThis.initialPosition); }); + it('resetPositions: should not call the function if the event does not have setSelectionRange', () => { + const mockEvent = { + target: {} + }; + + const fakeThis = mask; + + expect(() => fakeThis.setPositions(mockEvent)).not.toThrow(); + }); + + it('setSelectionRange: should not call the function if the event does not have setSelectionRange', () => { + const mockEvent = { + target: {} + }; + + const fakeThis = mask; + fakeThis.initialPosition = 2; + fakeThis.finalPosition = 1; + + expect(() => fakeThis.setSelectionRange(mockEvent)).not.toThrow(); + }); + + it('setSelectionRange: should not call the function if the event does not have setSelectionRange and final is larger than initial', () => { + const mockEvent = { + target: {} + }; + + const fakeThis = mask; + fakeThis.initialPosition = 1; + fakeThis.finalPosition = 2; + + expect(() => fakeThis.setSelectionRange(mockEvent)).not.toThrow(); + }); + it('should change the positions with a defined value', () => { const fakeThis = mask; fakeThis.initialPosition = 3; diff --git a/projects/ui/src/lib/components/po-field/po-input/po-mask.ts b/projects/ui/src/lib/components/po-field/po-input/po-mask.ts index 120f493279..77e1c8c520 100644 --- a/projects/ui/src/lib/components/po-field/po-input/po-mask.ts +++ b/projects/ui/src/lib/components/po-field/po-input/po-mask.ts @@ -100,9 +100,9 @@ export class PoMask { setSelectionRange($event: any) { if (this.initialPosition > this.finalPosition) { - $event.target.setSelectionRange(this.finalPosition, this.initialPosition); + $event.target.setSelectionRange?.(this.finalPosition, this.initialPosition); } else { - $event.target.setSelectionRange(this.initialPosition, this.finalPosition); + $event.target.setSelectionRange?.(this.initialPosition, this.finalPosition); } } @@ -237,7 +237,7 @@ export class PoMask { // posiciona o cursor de acordo com o controle de posição setPositions($event: any) { - $event.target.setSelectionRange(this.initialPosition, this.finalPosition); + $event.target.setSelectionRange?.(this.initialPosition, this.finalPosition); } // muda a posição do cursor e atualiza o controle de posição