From 1516bb3e5624a17419b09907c72c448b328610c2 Mon Sep 17 00:00:00 2001 From: Andrii Kamaldinov <129040945+andriikamaldinov1@users.noreply.github.com> Date: Mon, 15 Jul 2024 18:42:23 +0300 Subject: [PATCH] fix(ref: no-ref): fix issues * fix(ref: no-ref): fix issues * fix(ref: no-ref): fix bugs * fix(ref: no-ref): fix bugs * feat(ref: no-ref): fix issue * feat(ref: no-ref): fix issue --- CHANGELOG.md | 8 ++ package.json | 2 +- projects/ngx-mask-lib/package.json | 2 +- .../src/lib/ngx-mask-applier.service.ts | 10 +-- .../ngx-mask-lib/src/test/separator.spec.ts | 87 +++++++++++++++++++ .../ngx-mask-lib/src/test/time-mask.spec.ts | 19 ++++ 6 files changed, 118 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce2bc9d8..98aa50c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# 17.1.2(2024-07-05) + +### Fix + +- Fix ([#1378](https://github.com/JsDaddy/ngx-mask/issues/1378)) +- Fix ([#1390](https://github.com/JsDaddy/ngx-mask/issues/1390)) + + # 17.1.1(2024-07-05) ### Fix diff --git a/package.json b/package.json index 5713bfee..ece6ff22 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "17.1.1", + "version": "17.1.2", "description": "Awesome ngx mask", "license": "MIT", "engines": { diff --git a/projects/ngx-mask-lib/package.json b/projects/ngx-mask-lib/package.json index 0b7b1605..5f83f1b8 100644 --- a/projects/ngx-mask-lib/package.json +++ b/projects/ngx-mask-lib/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "17.1.1", + "version": "17.1.2", "description": "awesome ngx mask", "keywords": [ "ng2-mask", diff --git a/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts b/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts index c55babf7..8110db1e 100644 --- a/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts +++ b/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts @@ -349,8 +349,7 @@ export class NgxMaskApplierService { result[position - 1] === this.decimalMarker || shiftStep === -4 || shiftStep === -3 || - result[position] === MaskExpression.COMMA || - result[position] === MaskExpression.WHITE_SPACE + result[position] === this.thousandSeparator ) { this._shift.clear(); this._shift.add(position - 1); @@ -485,7 +484,6 @@ export class NgxMaskApplierService { const inputValueCursorPlusTwo = inputValue[cursor + 2] as string; const inputValueCursorMinusOne = inputValue[cursor - 1] as string; const inputValueCursorMinusTwo = inputValue[cursor - 2] as string; - const inputValueCursorMinusThree = inputValue[cursor - 3] as string; const inputValueSliceMinusThreeMinusOne = inputValue.slice( cursor - 3, cursor - 1 @@ -541,11 +539,7 @@ export class NgxMaskApplierService { ((this.specialCharacters.includes(inputValueCursorMinusTwo) && Number(inputValueSliceMinusOnePlusOne) > monthsCount && !this.specialCharacters.includes(inputValueCursor)) || - this.specialCharacters.includes(inputValueCursor) || - (this.specialCharacters.includes(inputValueCursorMinusThree) && - Number(inputValueSliceMinusTwoCursor) > monthsCount && - !this.specialCharacters.includes(inputValueCursorMinusOne)) || - this.specialCharacters.includes(inputValueCursorMinusOne)); + this.specialCharacters.includes(inputValueCursor)); // month<12 && day<10 for input const day2monthInput: boolean = Number(inputValueSliceMinusThreeMinusOne) <= daysCount && diff --git a/projects/ngx-mask-lib/src/test/separator.spec.ts b/projects/ngx-mask-lib/src/test/separator.spec.ts index 0ff2d767..b0994ced 100644 --- a/projects/ngx-mask-lib/src/test/separator.spec.ts +++ b/projects/ngx-mask-lib/src/test/separator.spec.ts @@ -1710,4 +1710,91 @@ describe('Separator: Mask', () => { expect(inputElement.value).toBe('12.'); }); + + it('should change position when click backspace thousandSeparator = .', () => { + component.mask = 'separator.2'; + component.decimalMarker = ','; + component.thousandSeparator = '.'; + const inputElement = fixture.nativeElement.querySelector('input'); + inputElement.value = '1.234.567,89'; + + expect(inputElement.value).toBe('1.234.567,89'); + + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + inputElement.setSelectionRange(2, 2); + inputElement.selectionStart; + expect(inputElement.selectionStart).toBe(2); + + const backspaceEvent = new KeyboardEvent('keydown', { + key: 'Backspace', + code: 'Backspace', + }); + inputElement.dispatchEvent(backspaceEvent); + + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + expect(inputElement.value).toBe('1.234.567,89'); + expect(inputElement.selectionStart).toBe(1); + }); + + it('should change position when click backspace thousandSeparator = ,', () => { + component.mask = 'separator.2'; + component.decimalMarker = '.'; + component.thousandSeparator = ','; + const inputElement = fixture.nativeElement.querySelector('input'); + inputElement.value = '1,234,567.89'; + + expect(inputElement.value).toBe('1,234,567.89'); + + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + inputElement.setSelectionRange(2, 2); + inputElement.selectionStart; + expect(inputElement.selectionStart).toBe(2); + + const backspaceEvent = new KeyboardEvent('keydown', { + key: 'Backspace', + code: 'Backspace', + }); + inputElement.dispatchEvent(backspaceEvent); + + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + expect(inputElement.value).toBe('1,234,567.89'); + expect(inputElement.selectionStart).toBe(1); + }); + + it('should change position when click backspace thousandSeparator = ', () => { + component.mask = 'separator.2'; + component.decimalMarker = '.'; + component.thousandSeparator = ' '; + const inputElement = fixture.nativeElement.querySelector('input'); + inputElement.value = '1 234 567.89'; + + expect(inputElement.value).toBe('1 234 567.89'); + + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + inputElement.setSelectionRange(2, 2); + inputElement.selectionStart; + expect(inputElement.selectionStart).toBe(2); + + const backspaceEvent = new KeyboardEvent('keydown', { + key: 'Backspace', + code: 'Backspace', + }); + inputElement.dispatchEvent(backspaceEvent); + + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + expect(inputElement.value).toBe('1 234 567.89'); + expect(inputElement.selectionStart).toBe(1); + }); }); diff --git a/projects/ngx-mask-lib/src/test/time-mask.spec.ts b/projects/ngx-mask-lib/src/test/time-mask.spec.ts index 872c2737..42019a6b 100644 --- a/projects/ngx-mask-lib/src/test/time-mask.spec.ts +++ b/projects/ngx-mask-lib/src/test/time-mask.spec.ts @@ -484,4 +484,23 @@ describe('Directive: Mask (Time)', () => { equal('12341', '1234:1', fixture); equal('123412', '1234:12', fixture); }); + + it('Date d0/M0', () => { + component.mask = 'd0/M0'; + equal('1', '1', fixture); + equal('12', '12', fixture); + equal('123', '12/3', fixture); + equal('1234', '12/3', fixture); + equal('33', '3/3', fixture); + }); + + it('Date d0/M0 with v', () => { + component.mask = 'd0/M0'; + component.leadZeroDateTime = true; + equal('1', '1', fixture); + equal('12', '12', fixture); + equal('123', '12/03', fixture); + equal('1234', '12/03', fixture); + equal('44', '04/04', fixture); + }); });