Skip to content

Commit

Permalink
fix(ref: no-ref): fix issues
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
andriikamaldinov1 authored Jul 15, 2024
1 parent 0249c92 commit 1516bb3
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "17.1.1",
"version": "17.1.2",
"description": "Awesome ngx mask",
"license": "MIT",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-mask-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "17.1.1",
"version": "17.1.2",
"description": "awesome ngx mask",
"keywords": [
"ng2-mask",
Expand Down
10 changes: 2 additions & 8 deletions projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 &&
Expand Down
87 changes: 87 additions & 0 deletions projects/ngx-mask-lib/src/test/separator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
19 changes: 19 additions & 0 deletions projects/ngx-mask-lib/src/test/time-mask.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 1516bb3

Please sign in to comment.