Skip to content

Commit

Permalink
feat(ref: no-ref): fix issue
Browse files Browse the repository at this point in the history
* feat(ref: no-ref): fix issue

* feat(ref: no-ref): fix issue

* feat(ref: no-ref): fix issue
  • Loading branch information
andriikamaldinov1 authored Jul 16, 2024
1 parent 1516bb3 commit a4a1791
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 11 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# 17.1.2(2024-07-05)
# 17.1.3(2024-07-16)

### Fix

- Fix ([#1386](https://github.com/JsDaddy/ngx-mask/issues/1386))
- Fix ([#1370](https://github.com/JsDaddy/ngx-mask/issues/1370))

# 17.1.2(2024-07-15)

### 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.2",
"version": "17.1.3",
"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.2",
"version": "17.1.3",
"description": "awesome ngx mask",
"keywords": [
"ng2-mask",
Expand Down
7 changes: 3 additions & 4 deletions projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,8 @@ export class NgxMaskApplierService {
result += inputSymbol;
cursor++;
} else if (
(inputSymbol === MaskExpression.WHITE_SPACE &&
maskExpression[cursor] === MaskExpression.WHITE_SPACE) ||
(inputSymbol === MaskExpression.SLASH &&
maskExpression[cursor] === MaskExpression.SLASH)
this.specialCharacters.includes(inputSymbol) &&
maskExpression[cursor] === inputSymbol
) {
result += inputSymbol;
cursor++;
Expand Down Expand Up @@ -642,6 +640,7 @@ export class NgxMaskApplierService {
) {
cursor++;
}

cursor++;
i--;
} else if (
Expand Down
34 changes: 33 additions & 1 deletion projects/ngx-mask-lib/src/test/basic-logic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ describe('Directive: Mask', () => {
equal('(', '(', fixture);
equal('(1', '(1', fixture);
equal('(12', '(12', fixture);
equal('(12)', '(12) ', fixture);
equal('(12)', '(12)', fixture);
equal('(12) 3', '(12) 3', fixture);
equal('(12) 34', '(12) 34', fixture);
equal('(12) 345', '(12) 345', fixture);
Expand Down Expand Up @@ -896,4 +896,36 @@ describe('Directive: Mask', () => {
equal(']', '', fixture);
equal('=', '', fixture);
});

it('optional mask should work correct 99-99', () => {
component.mask = '99-99';
equal('1', '1', fixture);
equal('12', '12', fixture);
equal('123', '12-3', fixture);
equal('1234', '12-34', fixture);
equal('1-2', '1-2', fixture);
equal('1-23', '1-23', fixture);
});

it('custom mask with optional symbol should work correct mask=999-999-999', () => {
component.mask = '999-999-999';
equal('1', '1', fixture);
equal('12', '12', fixture);
equal('123', '123', fixture);
equal('1234', '123-4', fixture);
equal('12345', '123-45', fixture);
equal('123456', '123-456', fixture);
equal('1234567', '123-456-7', fixture);
equal('12345678', '123-456-78', fixture);
equal('123456789', '123-456-789', fixture);
equal('1-', '1-', fixture);
equal('1-2', '1-2', fixture);
equal('1-2-3', '1-2-3', fixture);
equal('1-2-345', '1-2-345', fixture);
equal('12-3-45', '12-3-45', fixture);
equal('12-34-56', '12-34-56', fixture);
equal('12-34-567', '12-34-567', fixture);
equal('123-4-5', '123-4-5', fixture);
equal('123-45-6', '123-45-6', fixture);
});
});
4 changes: 2 additions & 2 deletions projects/ngx-mask-lib/src/test/cursor.cy-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ describe('Test Date Hh:m0', () => {

.should('have.value', '(123) 4')
.type('{backspace}'.repeat(2))
.should('have.prop', 'selectionStart', 4);
.should('have.prop', 'selectionStart', 5);
});

it('dynamic mask after backspace should have right cursor position (00) 00000000||+00 (00) 00000000', () => {
Expand All @@ -365,6 +365,6 @@ describe('Test Date Hh:m0', () => {

.should('have.value', '(12) 3')
.type('{backspace}'.repeat(2))
.should('have.prop', 'selectionStart', 3);
.should('have.prop', 'selectionStart', 4);
});
});
72 changes: 72 additions & 0 deletions projects/ngx-mask-lib/src/test/custom-patterns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,75 @@ describe('Directive: Mask (Provide custom patterns with symbol f and F)', () =>
});
});
});

describe('Directive: Mask (Provide custom patterns with symbol B optional)', () => {
let fixture: ComponentFixture<TestMaskComponent>;
let component: TestMaskComponent;
const ngxMaskCustomPatterns = {
'0': { pattern: new RegExp('\\d') },
A: { pattern: new RegExp('[0-9,;]'), optional: false },
B: { pattern: new RegExp('[0-9,;]'), optional: true },
};

const ngxMaskConfigValue: Partial<IConfig> = {
patterns: { ...initialConfig.patterns, ...ngxMaskCustomPatterns },
};

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestMaskComponent],
imports: [ReactiveFormsModule, NgxMaskDirective],
providers: [provideNgxMask(ngxMaskConfigValue)],
});
fixture = TestBed.createComponent(TestMaskComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('custom mask with optional symbol should work correct mask=(000) 000-0000 x BBBBBBBBBB', () => {
component.mask = '(000) 000-0000 x BBBBBBBBBB';
component.specialCharacters = ['(', ')', ' ', '-', 'x'];
equal('1', '(1', fixture);
equal('12', '(12', fixture);
equal('123', '(123', fixture);
equal('1234', '(123) 4', fixture);
equal('12345', '(123) 45', fixture);
equal('123456', '(123) 456', fixture);
equal('1234567', '(123) 456-7', fixture);
equal('12345678', '(123) 456-78', fixture);
equal('123456789', '(123) 456-789', fixture);
equal('1234567890', '(123) 456-7890', fixture);
equal('1234567890 1', '(123) 456-7890 x 1', fixture);
equal('1234567890 12', '(123) 456-7890 x 12', fixture);
equal('1234567890 123', '(123) 456-7890 x 123', fixture);
equal('1234567890 1234', '(123) 456-7890 x 1234', fixture);
equal('1234567890 12345', '(123) 456-7890 x 12345', fixture);
equal('1234567890 123456', '(123) 456-7890 x 123456', fixture);
equal('1234567890 1234567', '(123) 456-7890 x 1234567', fixture);
equal('1234567890 12345678', '(123) 456-7890 x 12345678', fixture);
equal('1234567890 123456789', '(123) 456-7890 x 123456789', fixture);
equal('1234567890 1234567890', '(123) 456-7890 x 1234567890', fixture);
});

it('custom mask with optional symbol should work correct mask=BBB-BBB-BBB', () => {
component.mask = 'BBB-BBB-BBB';
equal('1', '1', fixture);
equal('12', '12', fixture);
equal('123', '123', fixture);
equal('1234', '123-4', fixture);
equal('12345', '123-45', fixture);
equal('123456', '123-456', fixture);
equal('1234567', '123-456-7', fixture);
equal('12345678', '123-456-78', fixture);
equal('123456789', '123-456-789', fixture);
equal('1-', '1-', fixture);
equal('1-2', '1-2', fixture);
equal('1-2-3', '1-2-3', fixture);
equal('1-2-345', '1-2-345', fixture);
equal('12-3-45', '12-3-45', fixture);
equal('12-34-56', '12-34-56', fixture);
equal('12-34-567', '12-34-567', fixture);
equal('123-4-5', '123-4-5', fixture);
equal('123-45-6', '123-45-6', fixture);
});
});
2 changes: 1 addition & 1 deletion projects/ngx-mask-lib/src/test/delete.cy-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('Directive: Mask (Delete)', () => {
.should('have.value', '(12) ')
.type('{rightArrow}')
.type('{backspace}')
.should('have.prop', 'selectionStart', 3);
.should('have.prop', 'selectionStart', 4);
});

it('should return value from ctrl+V', () => {
Expand Down

0 comments on commit a4a1791

Please sign in to comment.