From 812b68ca4d12f8ff54d226004655733bf9ca4c1d Mon Sep 17 00:00:00 2001 From: andriikamaldinov1 Date: Fri, 20 Dec 2024 15:35:37 +0200 Subject: [PATCH] fix(ref: no-ref): fix issues --- CHANGELOG.md | 8 +- package.json | 2 +- projects/ngx-mask-lib/package.json | 2 +- .../src/lib/ngx-mask-applier.service.ts | 19 +++-- .../src/test/separator.cy-spec.ts | 79 +++++++++++++++++++ 5 files changed, 100 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23168c07..b8eceb98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,14 @@ -# 19.0.5(2024-12-17) +# 19.0.6(2024-12-20) ### Fix - Fix ([#1481](https://github.com/JsDaddy/ngx-mask/issues/1481)) + + +# 19.0.5(2024-12-20) + +### Fix + - Fix ([#1411](https://github.com/JsDaddy/ngx-mask/issues/1411)) # 19.0.4(2024-12-13) diff --git a/package.json b/package.json index 947bed2f..6865e3b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "19.0.5", + "version": "19.0.6", "description": "Awesome ngx mask", "license": "MIT", "engines": { diff --git a/projects/ngx-mask-lib/package.json b/projects/ngx-mask-lib/package.json index 7ce1935b..ecc4f2f2 100644 --- a/projects/ngx-mask-lib/package.json +++ b/projects/ngx-mask-lib/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "19.0.5", + "version": "19.0.6", "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 b5ab3521..d2a8a3f4 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 @@ -200,13 +200,18 @@ export class NgxMaskApplierService { let decimalMarker = this.decimalMarker; if (Array.isArray(this.decimalMarker)) { - const marker = this.decimalMarker.find((dm) => dm !== this.thousandSeparator); - - decimalMarker = marker - ? marker - : this.actualValue.includes(this.decimalMarker[0]) - ? this.decimalMarker[0] - : this.decimalMarker[1]; + if ( + this.actualValue.includes(this.decimalMarker[0]) || + this.actualValue.includes(this.decimalMarker[1]) + ) { + decimalMarker = this.actualValue.includes(this.decimalMarker[0]) + ? this.decimalMarker[0] + : this.decimalMarker[1]; + } else { + decimalMarker = this.decimalMarker.find( + (dm) => dm !== this.thousandSeparator + ) as '.' | ','; + } } if (backspaced) { diff --git a/projects/ngx-mask-lib/src/test/separator.cy-spec.ts b/projects/ngx-mask-lib/src/test/separator.cy-spec.ts index a373041d..9669d26f 100644 --- a/projects/ngx-mask-lib/src/test/separator.cy-spec.ts +++ b/projects/ngx-mask-lib/src/test/separator.cy-spec.ts @@ -1,5 +1,6 @@ import { CypressTestMaskComponent } from './utils/cypress-test-component.component'; import { signal } from '@angular/core'; +import type { NgxMaskConfig } from 'ngx-mask'; describe('Test Date Hh:m0', () => { it('Mask separator.2 check cursor with value 100.0', () => { @@ -506,4 +507,82 @@ describe('Test Date Hh:m0', () => { .type('{backspace}') .should('have.value', '0.05'); }); + + it('should correct work after backspace separator.2 with default values', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: signal('separator.2'), + decimalMarker: signal(['.', ','] as NgxMaskConfig['decimalMarker']), + thousandSeparator: signal(' '), + }, + }); + + cy.get('#masked') + .type('1000000,35') + .should('have.value', '1 000 000,35') + .type('{leftArrow}'.repeat(11)) + .type('{backspace}') + .should('have.value', '0,35'); + + cy.get('#masked').clear(); + + cy.get('#masked') + .type('1000000.35') + .should('have.value', '1 000 000.35') + .type('{leftArrow}'.repeat(11)) + .type('{backspace}') + .should('have.value', '0.35'); + }); + + it('should correct work after backspace separator.2 with default values', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: signal('separator.2'), + decimalMarker: signal(['.', ','] as NgxMaskConfig['decimalMarker']), + thousandSeparator: signal(' '), + }, + }); + + cy.get('#masked') + .type('60,35') + .should('have.value', '60,35') + .type('{leftArrow}'.repeat(4)) + .type('{backspace}') + .should('have.value', '0,35'); + + cy.get('#masked').clear(); + + cy.get('#masked') + .type('60.35') + .should('have.value', '60.35') + .type('{leftArrow}'.repeat(4)) + .type('{backspace}') + .should('have.value', '0.35'); + }); + + it('should correct work after backspace separator.2 with default values', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: signal('separator.2'), + decimalMarker: signal(['.', ','] as NgxMaskConfig['decimalMarker']), + thousandSeparator: signal(' '), + }, + }); + + cy.get('#masked') + .type('200,35') + .should('have.value', '200,35') + .type('{leftArrow}'.repeat(5)) + .type('{backspace}') + .should('have.value', '0,35'); + + cy.get('#masked').clear(); + + cy.get('#masked') + .type('200.35') + .should('have.value', '200.35') + .type('{leftArrow}'.repeat(5)) + .type('{backspace}') + .should('have.value', '0.35'); + }); });