diff --git a/.lintstagedrc b/.lintstagedrc index 118fbe6c..7e90d576 100644 --- a/.lintstagedrc +++ b/.lintstagedrc @@ -1,6 +1,6 @@ { "*.{ts,js,json}": [ - "eslint --report-unused-disable-directives --max-warnings 0 --fix", + "eslint --report-unused-disable-directives --max-warnings 0 --no-warn-ignored --fix", "prettier . --write" ], "*.scss": "stylelint --fix" diff --git a/.stylelintignore b/.stylelintignore index 8062b4f7..16108f10 100644 --- a/.stylelintignore +++ b/.stylelintignore @@ -6,7 +6,6 @@ /.angular /test-reports /src/coverage -/src/styles.scss /projects/ngx-mask-lib/coverage diff --git a/.stylelintrc.json b/.stylelintrc.json index 536ca0df..9f57209e 100644 --- a/.stylelintrc.json +++ b/.stylelintrc.json @@ -1,5 +1,6 @@ { "extends": ["stylelint-config-recommended-scss", "stylelint-prettier/recommended"], + "plugins": ["stylelint-scss", "stylelint-prettier"], "customSyntax": "postcss-scss", "rules": { "no-empty-source": null, @@ -10,6 +11,12 @@ { "ignoreTypes": ["/^mat-/", ":host", ":root"] } + ], + "scss/at-rule-no-unknown": [ + true, + { + "ignoreAtRules": ["tailwind"] + } ] } } diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b531147..0fe19938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,15 @@ +# 19.0.0(2024-11-22) + +### Feature + +- update ng 19.x + # 18.0.4(2024-11-11) ### Fix - Fix ([#1449](https://github.com/JsDaddy/ngx-mask/issues/1449)) - # 18.0.3(2024-11-05) ### Fix diff --git a/bun.lockb b/bun.lockb index de39f5a7..fea09b4a 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/cypress/support/component.ts b/cypress/support/component.ts index 8d983917..afafdf61 100644 --- a/cypress/support/component.ts +++ b/cypress/support/component.ts @@ -1,4 +1,4 @@ -import { mount } from 'cypress/angular'; +import { mount } from 'cypress/angular-signals'; declare global { // eslint-disable-next-line @typescript-eslint/no-namespace diff --git a/package.json b/package.json index ebfea910..ca1c284c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "18.0.4", + "version": "19.0.0", "description": "Awesome ngx mask", "license": "MIT", "engines": { @@ -60,47 +60,47 @@ "url": "https://github.com/JsDaddy/ngx-mask.git" }, "dependencies": { - "@angular/animations": "18.2.9", - "@angular/common": "18.2.9", - "@angular/compiler": "18.2.9", - "@angular/core": "18.2.9", - "@angular/forms": "18.2.9", - "@angular/platform-browser": "18.2.9", - "@angular/platform-browser-dynamic": "18.2.9", - "@angular/router": "18.2.9", + "@angular/animations": "19.0.0", + "@angular/common": "19.0.0", + "@angular/compiler": "19.0.0", + "@angular/core": "19.0.0", + "@angular/forms": "19.0.0", + "@angular/platform-browser": "19.0.0", + "@angular/platform-browser-dynamic": "19.0.0", + "@angular/router": "19.0.0", "@types/jest": "^29.5.14", - "@types/mocha": "^10.0.9", + "@types/mocha": "^10.0.10", "ajv": "^8.17.1", - "cypress": "^13.15.1", + "cypress": "^13.16.0", "highlight.js": "11.10.0", "ngx-highlightjs": "12.0.0", "rxjs": "7.8.1", "semantic-release": "24.2.0", "semantic-release-export-data": "^1.1.0", - "snyk": "^1.1294.0" + "snyk": "^1.1294.1" }, "devDependencies": { - "@angular-devkit/build-angular": "18.2.10", - "@angular-eslint/builder": "18.4.0", - "@angular-eslint/eslint-plugin": "18.4.0", - "@angular-eslint/eslint-plugin-template": "18.4.0", - "@angular-eslint/schematics": "18.4.0", - "@angular-eslint/template-parser": "18.4.0", - "@angular/cli": "18.2.10", - "@angular/compiler-cli": "18.2.9", - "@angular/language-service": "18.2.9", - "@commitlint/cli": "19.5.0", - "@commitlint/config-conventional": "19.5.0", + "@angular-devkit/build-angular": "19.0.1", + "@angular-eslint/builder": "18.4.1", + "@angular-eslint/eslint-plugin": "18.4.1", + "@angular-eslint/eslint-plugin-template": "18.4.1", + "@angular-eslint/schematics": "18.4.1", + "@angular-eslint/template-parser": "18.4.1", + "@angular/cli": "19.0.1", + "@angular/compiler-cli": "19.0.0", + "@angular/language-service": "19.0.0", + "@commitlint/cli": "19.6.0", + "@commitlint/config-conventional": "19.6.0", "@jscutlery/cypress-angular": "^0.9.22", "@types/highlight.js": "9.12.4", "@types/jasmine": "5.1.4", - "@types/node": "22.8.1", - "@typescript-eslint/eslint-plugin": "8.11.0", - "@typescript-eslint/parser": "8.11.0", + "@types/node": "22.9.1", + "@typescript-eslint/eslint-plugin": "8.15.0", + "@typescript-eslint/parser": "8.15.0", "@web/test-runner": "^0.19.0", "angular-cli-ghpages": "2.0.3", "angular-http-server": "1.12.0", - "eslint": "9.13.0", + "eslint": "9.15.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-json": "4.0.1", "eslint-plugin-prettier": "5.2.1", @@ -108,24 +108,27 @@ "jasmine-spec-reporter": "7.0.0", "lint-staged": "15.2.10", "markdownlint-cli": "0.42.0", - "ng-packagr": "18.2.1", - "npm-check-updates": "^17.1.8", - "postcss-scss": "4.0.9", + "ng-packagr": "19.0.0", + "npm-check-updates": "^17.1.11", "prettier": "3.3.3", - "puppeteer": "23.6.0", + "puppeteer": "23.9.0", "stylelint": "16.10.0", "stylelint-config-prettier": "9.0.5", "stylelint-config-recommended-scss": "14.1.0", "stylelint-prettier": "5.0.2", "type-coverage": "^2.29.7", - "typescript": "5.5.4", - "angular-eslint": "^18.4.0", - "typescript-eslint": "^8.11.0", - "tailwindcss": "^3.4.14", - "bun-types": "^1.1.33" + "typescript": "5.6.3", + "angular-eslint": "^18.4.1", + "typescript-eslint": "^8.15.0", + "tailwindcss": "^3.4.15", + "bun-types": "^1.1.36", + "postcss": "8.4.49", + "postcss-nesting": "13.0.1", + "cssnano": "7.0.6", + "postcss-scss": "4.0.9" }, "typeCoverage": { - "atLeast": 92, + "atLeast": 91, "ignoreObject": true, "ignoreAsAssertion": true, "ignoreTypeAssertion;": true, diff --git a/postcss.config.js b/postcss.config.js new file mode 100644 index 00000000..1c25a754 --- /dev/null +++ b/postcss.config.js @@ -0,0 +1,8 @@ +module.exports = { + plugins: { + 'postcss-nesting': {}, + tailwindcss: {}, + autoprefixer: {}, + cssnano: { preset: 'default' }, + }, +}; diff --git a/projects/ngx-mask-lib/package.json b/projects/ngx-mask-lib/package.json index 15381d26..ab7f5853 100644 --- a/projects/ngx-mask-lib/package.json +++ b/projects/ngx-mask-lib/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "18.0.4", + "version": "19.0.0", "description": "awesome ngx mask", "keywords": [ "ng2-mask", diff --git a/projects/ngx-mask-lib/src/test/add-prefix.spec.ts b/projects/ngx-mask-lib/src/test/add-prefix.spec.ts index 5694b87d..21b198c2 100644 --- a/projects/ngx-mask-lib/src/test/add-prefix.spec.ts +++ b/projects/ngx-mask-lib/src/test/add-prefix.spec.ts @@ -12,8 +12,7 @@ describe('Directive: Mask (Add prefix)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/add-suffix.spec.ts b/projects/ngx-mask-lib/src/test/add-suffix.spec.ts index 420767c8..1a3095b9 100644 --- a/projects/ngx-mask-lib/src/test/add-suffix.spec.ts +++ b/projects/ngx-mask-lib/src/test/add-suffix.spec.ts @@ -13,8 +13,7 @@ describe('Directive: Mask (Add suffix)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/allow-negative-numbers.spec.ts b/projects/ngx-mask-lib/src/test/allow-negative-numbers.spec.ts index 2e105b52..335845e6 100644 --- a/projects/ngx-mask-lib/src/test/allow-negative-numbers.spec.ts +++ b/projects/ngx-mask-lib/src/test/allow-negative-numbers.spec.ts @@ -13,8 +13,7 @@ describe('Directive: Mask (Allow negative numbers)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/basic-logic.spec.ts b/projects/ngx-mask-lib/src/test/basic-logic.spec.ts index 24cc97f6..667d8f3c 100644 --- a/projects/ngx-mask-lib/src/test/basic-logic.spec.ts +++ b/projects/ngx-mask-lib/src/test/basic-logic.spec.ts @@ -15,8 +15,7 @@ describe('Directive: Mask', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); @@ -944,9 +943,8 @@ describe('Directive: Mask', () => { equal('11/11/1111', '11/11/1111', fixture); component.form.setValue('22/22/2222'); fixture.detectChanges(); - requestAnimationFrame(() => { - expect(inputTarget.value).toBe('22/22/2222'); - }); + + equal('22/22/2222', '22/22/2222', fixture); }); it('mask sepator.0 after setValue should be dont dirty', () => { diff --git a/projects/ngx-mask-lib/src/test/clear-if-not-match-the-mask.spec.ts b/projects/ngx-mask-lib/src/test/clear-if-not-match-the-mask.spec.ts index bc318931..88794ac5 100644 --- a/projects/ngx-mask-lib/src/test/clear-if-not-match-the-mask.spec.ts +++ b/projects/ngx-mask-lib/src/test/clear-if-not-match-the-mask.spec.ts @@ -12,8 +12,7 @@ describe('Directive: Mask', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/complete-mask.spec.ts b/projects/ngx-mask-lib/src/test/complete-mask.spec.ts index 89cae0a4..c6de3d70 100644 --- a/projects/ngx-mask-lib/src/test/complete-mask.spec.ts +++ b/projects/ngx-mask-lib/src/test/complete-mask.spec.ts @@ -7,6 +7,8 @@ import { NgxMaskDirective } from '../lib/ngx-mask.directive'; @Component({ selector: 'jsdaddy-open-source-test', + standalone: true, + imports: [ReactiveFormsModule, NgxMaskDirective], template: ` `, }) class TestMaskComponent { @@ -26,8 +28,7 @@ describe('Directive: Mask (Function maskFilled)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/copy-paste.spec.ts b/projects/ngx-mask-lib/src/test/copy-paste.spec.ts index 45dd458f..59eb800b 100644 --- a/projects/ngx-mask-lib/src/test/copy-paste.spec.ts +++ b/projects/ngx-mask-lib/src/test/copy-paste.spec.ts @@ -13,8 +13,7 @@ describe('Event: paste', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/cursor.cy-spec.ts b/projects/ngx-mask-lib/src/test/cursor.cy-spec.ts index a83b43b1..c3757d19 100644 --- a/projects/ngx-mask-lib/src/test/cursor.cy-spec.ts +++ b/projects/ngx-mask-lib/src/test/cursor.cy-spec.ts @@ -1,13 +1,12 @@ -import { CypressTestMaskModule } from './utils/cypress-test.module'; import { CypressTestMaskComponent } from './utils/cypress-test-component.component'; +import { signal } from '@angular/core'; describe('Test Date Hh:m0', () => { it('Test value Hh:m0', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'Hh:m0', + mask: signal('Hh:m0'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('2020').should('have.value', '20:20'); @@ -22,9 +21,8 @@ describe('Test Date Hh:m0', () => { it('Mask Hh:m0 check cursor', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'Hh:m0', + mask: signal('Hh:m0'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('77').should('have.prop', 'selectionStart', 3); cy.get('#masked').clear(); @@ -34,9 +32,8 @@ describe('Test Date Hh:m0', () => { it('Mask Hh:m0:s0 check cursor', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'Hh:m0:s0', + mask: signal('Hh:m0:s0'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('77').should('have.prop', 'selectionStart', 3); cy.get('#masked').clear(); @@ -46,9 +43,8 @@ describe('Test Date Hh:m0', () => { it('Mask d0/m0/0000 check cursor', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'd0/m0/0000', + mask: signal('d0/m0/0000'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') .type('77') @@ -69,9 +65,8 @@ describe('Test Date Hh:m0', () => { it('Mask M0/d0/0000 check cursor', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'M0/d0/0000', + mask: signal('M0/d0/0000'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') .type('88') @@ -92,9 +87,8 @@ describe('Test Date Hh:m0', () => { it('Mask 0000/M0/d0 check cursor', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '0000/M0/d0', + mask: signal('0000/M0/d0'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('999999').should('have.prop', 'selectionStart', 8); cy.get('#masked').clear(); @@ -104,9 +98,8 @@ describe('Test Date Hh:m0', () => { it('Mask Hh:m0:s0 check cursor', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'Hh:m0:s0', + mask: signal('Hh:m0:s0'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') .type('910') @@ -122,9 +115,8 @@ describe('Test Date Hh:m0', () => { it('Mask (00) 90000-0000 check cursor and value', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '(00) 00009-0000', + mask: signal('(00) 00009-0000'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') .type('910') @@ -159,9 +151,8 @@ describe('Test Date Hh:m0', () => { it('Mask 099.09 check cursor and value', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '099.09', + mask: signal('099.09'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') .type('910') @@ -179,10 +170,9 @@ describe('Test Date Hh:m0', () => { it('Mask d0/M0/0000 should set cursor on right position', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'd0/M0/0000', - leadZeroDateTime: true, + mask: signal('d0/M0/0000'), + leadZeroDateTime: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') .type('33') @@ -193,10 +183,9 @@ describe('Test Date Hh:m0', () => { it('Mask d0/M0/0000 should set cursor on right position', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'd0/M0/0000', - leadZeroDateTime: true, + mask: signal('d0/M0/0000'), + leadZeroDateTime: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -208,11 +197,10 @@ describe('Test Date Hh:m0', () => { it('Mask should work with showMaskTyped 000/00000 with prefix', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '000/00000', - prefix: '+38 ', - showMaskTyped: true, + mask: signal('000/00000'), + prefix: signal('+38 '), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -224,10 +212,9 @@ describe('Test Date Hh:m0', () => { it('Mask should work with showMaskTyped 000/00000', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '000/00000', - showMaskTyped: false, + mask: signal('000/00000'), + showMaskTyped: signal(false), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -239,9 +226,8 @@ describe('Test Date Hh:m0', () => { it('dynamic mask after backspace should have right cursor position (000) 000-0000||+000000000000000', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '(000) 000-0000||+000000000000000', + mask: signal('(000) 000-0000||+000000000000000'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('11111111111').should('have.value', '+11111111111'); @@ -254,9 +240,8 @@ describe('Test Date Hh:m0', () => { it('dynamic mask after backspace should have right cursor position', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '(000) 000-0000||+000000000000000', + mask: signal('(000) 000-0000||+000000000000000'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -271,9 +256,8 @@ describe('Test Date Hh:m0', () => { it('dynamic mask after backspace should have right cursor position (00) 00000000||+00 (00) 00000000', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '(00) 00000000||+00 (00) 00000000', + mask: signal('(00) 00000000||+00 (00) 00000000'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('111').should('have.value', '(11) 1'); diff --git a/projects/ngx-mask-lib/src/test/custom-date.spec.ts b/projects/ngx-mask-lib/src/test/custom-date.spec.ts index 0cbfe9e5..c39b2701 100644 --- a/projects/ngx-mask-lib/src/test/custom-date.spec.ts +++ b/projects/ngx-mask-lib/src/test/custom-date.spec.ts @@ -12,8 +12,7 @@ describe('Directive: Mask (Custom date)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/custom-patterns.spec.ts b/projects/ngx-mask-lib/src/test/custom-patterns.spec.ts index 565b2336..666d4729 100644 --- a/projects/ngx-mask-lib/src/test/custom-patterns.spec.ts +++ b/projects/ngx-mask-lib/src/test/custom-patterns.spec.ts @@ -15,8 +15,7 @@ describe('Directive: Mask (Custom patterns)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); @@ -50,8 +49,7 @@ describe('Directive: Mask (Provide custom patterns)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask(ngxMaskConfigValue)], }); fixture = TestBed.createComponent(TestMaskComponent); @@ -94,8 +92,7 @@ describe('Directive: Mask (Provide custom patterns with symbol *)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask(ngxMaskConfigValue)], }); fixture = TestBed.createComponent(TestMaskComponent); @@ -149,8 +146,7 @@ describe('Directive: Mask (Provide custom patterns with symbol f and F)', () => beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask(ngxMaskConfig)], }); fixture = TestBed.createComponent(TestMaskComponent); @@ -196,8 +192,7 @@ describe('Directive: Mask (Provide custom patterns with symbol B optional)', () beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask(ngxMaskConfigValue)], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/custom-symbol-regexp.spec.ts b/projects/ngx-mask-lib/src/test/custom-symbol-regexp.spec.ts index 0ac1bb90..bbe4e83d 100644 --- a/projects/ngx-mask-lib/src/test/custom-symbol-regexp.spec.ts +++ b/projects/ngx-mask-lib/src/test/custom-symbol-regexp.spec.ts @@ -13,8 +13,7 @@ describe('Directive: Mask', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/default-config.spec.ts b/projects/ngx-mask-lib/src/test/default-config.spec.ts index f4c28a8d..b94bed1b 100644 --- a/projects/ngx-mask-lib/src/test/default-config.spec.ts +++ b/projects/ngx-mask-lib/src/test/default-config.spec.ts @@ -10,8 +10,7 @@ function createComponentWithDefaultConfig( defaultConfig?: NgxMaskOptions ): ComponentFixture { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideEnvironmentNgxMask(defaultConfig)], }); const fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/delete.cy-spec.ts b/projects/ngx-mask-lib/src/test/delete.cy-spec.ts index 2b3a12b1..864656fa 100644 --- a/projects/ngx-mask-lib/src/test/delete.cy-spec.ts +++ b/projects/ngx-mask-lib/src/test/delete.cy-spec.ts @@ -1,14 +1,13 @@ import { CypressTestMaskComponent } from './utils/cypress-test-component.component'; -import { CypressTestMaskModule } from './utils/cypress-test.module'; import { FormControl } from '@angular/forms'; +import { signal } from '@angular/core'; describe('Directive: Mask (Delete)', () => { it('cursor should correct delete with ViewEncapsulation.ShadowDom showMaskTyped=true', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '(000) 000-0000', + mask: signal('(000) 000-0000'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -22,9 +21,8 @@ describe('Directive: Mask (Delete)', () => { it('should delete character in input', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '00/00/0000', + mask: signal('00/00/0000'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -37,9 +35,8 @@ describe('Directive: Mask (Delete)', () => { it('should not delete special mask character', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '00/00/0000', + mask: signal('00/00/0000'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -52,10 +49,9 @@ describe('Directive: Mask (Delete)', () => { it('should delete secure character', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'XXX/X0/0000', - hiddenInput: true, + mask: signal('XXX/X0/0000'), + hiddenInput: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -68,9 +64,8 @@ describe('Directive: Mask (Delete)', () => { it('should delete selection', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '000 000 000', + mask: signal('000 000 000'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -82,10 +77,9 @@ describe('Directive: Mask (Delete)', () => { it('should delete prefix', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '000 000 000', - prefix: '+7', + mask: signal('000 000 000'), + prefix: signal('+7'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('1').type('{backspace}').should('have.value', ''); @@ -93,10 +87,9 @@ describe('Directive: Mask (Delete)', () => { it('should delete suffix', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '000 000 000', - suffix: '$', + mask: signal('000 000 000'), + suffix: signal('$'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('1').type('{backspace}').should('have.value', ''); @@ -105,9 +98,8 @@ describe('Directive: Mask (Delete)', () => { it('should delete specialCharacter from allow few mask', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '(00) 00000000||+00 (00) 00000000', + mask: signal('(00) 00000000||+00 (00) 00000000'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -124,9 +116,8 @@ describe('Directive: Mask (Delete)', () => { it('should return value from ctrl+V', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '9999999999999', + mask: signal('9999999999999'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -141,53 +132,54 @@ describe('Directive: Mask (Delete)', () => { }); it('should not delete special character from backspace', () => { + const patterns = { + '0': { pattern: /\d/ }, + '9': { pattern: /\d/, optional: true }, + A: { pattern: /[a-zA-Z0-9]/ }, + L: { pattern: /[a-z]/ }, + S: { pattern: /[a-zA-Z]/ }, + U: { pattern: /[A-Z]/ }, + X: { pattern: /\d/, symbol: '*' }, + d: { pattern: /\d/ }, + h: { pattern: /\d/ }, + s: { pattern: /\d/ }, + D: { pattern: /D/ }, // custom: The D on the mask can only be the D character + H: { pattern: /H/ }, // custom: the H on the mask can only be the H character + M: { pattern: /M/ }, // custom: the M on the mask can only be the M character + '\\S': { pattern: /\S/ }, // custom: the S on the mask can only be the S character. Escape it to prevent digits from being removed from the value + }; + const specialCharacters = [ + '-', + '/', + '(', + ')', + '.', + ':', + ' ', + '+', + ',', + '@', + '[', + ']', + '"', + "'", + 'D', + 'H', + 'M', + '\\S', + ]; cy.mount(CypressTestMaskComponent, { componentProperties: { form: new FormControl('12345678'), - mask: '00D : 00H : 00M : 00S', - shownMaskExpression: '00D : 00H : 00M : 00S', - showMaskTyped: true, - dropSpecialCharacters: false, - leadZeroDateTime: true, - placeHolderCharacter: '', - patterns: { - '0': { pattern: /\d/ }, - '9': { pattern: /\d/, optional: true }, - A: { pattern: /[a-zA-Z0-9]/ }, - L: { pattern: /[a-z]/ }, - S: { pattern: /[a-zA-Z]/ }, - U: { pattern: /[A-Z]/ }, - X: { pattern: /\d/, symbol: '*' }, - d: { pattern: /\d/ }, - h: { pattern: /\d/ }, - s: { pattern: /\d/ }, - D: { pattern: /D/ }, // custom: The D on the mask can only be the D character - H: { pattern: /H/ }, // custom: the H on the mask can only be the H character - M: { pattern: /M/ }, // custom: the M on the mask can only be the M character - '\\S': { pattern: /\S/ }, // custom: the S on the mask can only be the S character. Escape it to prevent digits from being removed from the value - }, - specialCharacters: [ - '-', - '/', - '(', - ')', - '.', - ':', - ' ', - '+', - ',', - '@', - '[', - ']', - '"', - "'", - 'D', - 'H', - 'M', - '\\S', - ], + mask: signal('00D : 00H : 00M : 00S'), + shownMaskExpression: signal('00D : 00H : 00M : 00S'), + showMaskTyped: signal(true), + dropSpecialCharacters: signal(false), + leadZeroDateTime: signal(true), + placeHolderCharacter: signal(''), + patterns: signal(patterns), + specialCharacters: signal(specialCharacters), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') .type('{rightArrow}'.repeat(1)) @@ -205,11 +197,10 @@ describe('Directive: Mask (Delete)', () => { it('should backspace with showMaskTyped and prefix', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '(000) 000-0000', - prefix: '+7 ', - showMaskTyped: true, + mask: signal('(000) 000-0000'), + prefix: signal('+7 '), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -250,11 +241,10 @@ describe('Directive: Mask (Delete)', () => { it('should backspace with showMaskTyped and prefix', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '00 000 00 00', - prefix: '+32 ', - showMaskTyped: true, + mask: signal('00 000 00 00'), + prefix: signal('+32 '), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -292,11 +282,10 @@ describe('Directive: Mask (Delete)', () => { it('should backspace with showMaskTyped and leadZeroDateTime', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'M0-d0-0000', - leadZeroDateTime: true, - showMaskTyped: true, + mask: signal('M0-d0-0000'), + leadZeroDateTime: signal(true), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -309,11 +298,10 @@ describe('Directive: Mask (Delete)', () => { it('should backspace with showMaskTyped and leadZeroDateTime', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'M0/d0/0000', - leadZeroDateTime: true, - showMaskTyped: true, + mask: signal('M0/d0/0000'), + leadZeroDateTime: signal(true), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -326,11 +314,10 @@ describe('Directive: Mask (Delete)', () => { it('should backspace with showMaskTyped and leadZeroDateTime', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'M0:d0:0000', - leadZeroDateTime: true, - showMaskTyped: true, + mask: signal('M0:d0:0000'), + leadZeroDateTime: signal(true), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -343,10 +330,9 @@ describe('Directive: Mask (Delete)', () => { it('should backspace with mask Hh:m0', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'Hh:m0', - showMaskTyped: true, + mask: signal('Hh:m0'), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -359,11 +345,10 @@ describe('Directive: Mask (Delete)', () => { it('should backspace with mask Hh:m0 and leadZeroDateTime', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'Hh:m0', - showMaskTyped: true, - leadZeroDateTime: true, + mask: signal('Hh:m0'), + showMaskTyped: signal(true), + leadZeroDateTime: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') diff --git a/projects/ngx-mask-lib/src/test/delete.spec.ts b/projects/ngx-mask-lib/src/test/delete.spec.ts index 62b6ebaa..73c01f11 100644 --- a/projects/ngx-mask-lib/src/test/delete.spec.ts +++ b/projects/ngx-mask-lib/src/test/delete.spec.ts @@ -15,8 +15,7 @@ describe('Directive: Mask (Delete)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/drop-special-charaters.spec.ts b/projects/ngx-mask-lib/src/test/drop-special-charaters.spec.ts index 0827887e..e1335d95 100644 --- a/projects/ngx-mask-lib/src/test/drop-special-charaters.spec.ts +++ b/projects/ngx-mask-lib/src/test/drop-special-charaters.spec.ts @@ -13,8 +13,7 @@ describe('Directive: Mask (Drop special characters)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); @@ -28,19 +27,24 @@ describe('Directive: Mask (Drop special characters)', () => { equal('257898', '25-78-98', fixture); expect(component.form.value).toBe('25-78-98'); - equal('123456', '12-34-56', fixture); expect(component.form.value).toBe('12-34-56'); + }); + it('should correct value with mask 00-00/00 with dropSpecialCharacters = /', () => { component.mask = '00-00/00'; component.dropSpecialCharacters = ['/']; + equal('257898', '25-78/98', fixture); expect(component.form.value).toBe('25-7898'); + }); + it('should correct value with mask 0000.00 with dropSpecialCharacters = true', () => { component.mask = '0000.00'; component.dropSpecialCharacters = true; component.form.setValue(123456); + equal('123456', '1234.56', fixture); expect(component.form.value).toBe(123456); }); diff --git a/projects/ngx-mask-lib/src/test/dynamic.spec.ts b/projects/ngx-mask-lib/src/test/dynamic.spec.ts index eb436594..6a600039 100644 --- a/projects/ngx-mask-lib/src/test/dynamic.spec.ts +++ b/projects/ngx-mask-lib/src/test/dynamic.spec.ts @@ -15,8 +15,7 @@ describe('Directive: Mask (Dynamic)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/emit-events.cy-spec.ts b/projects/ngx-mask-lib/src/test/emit-events.cy-spec.ts index 4844ea43..ed53b2c1 100644 --- a/projects/ngx-mask-lib/src/test/emit-events.cy-spec.ts +++ b/projects/ngx-mask-lib/src/test/emit-events.cy-spec.ts @@ -1,12 +1,12 @@ -import { CypressTestMaskModule } from './utils/cypress-test.module'; import { CypressTestMaskComponent } from './utils/cypress-test-component.component'; +import { signal } from '@angular/core'; + describe('Directive: Mask (emit-events)', () => { it('should emit event only when mask is correct', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '00 00 00', + mask: signal('00 00 00'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('1dd').type('dd'); @@ -19,10 +19,9 @@ describe('Directive: Mask (emit-events)', () => { it('should emit event only when mask is correct with hiddenINput', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'XX-XX-XX', - hiddenInput: true, + mask: signal('XX-XX-XX'), + hiddenInput: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('1dd').type('dd'); @@ -35,10 +34,9 @@ describe('Directive: Mask (emit-events)', () => { it('should add trailing zero when mask="separator.1" and leadZero="true"', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.1', - leadZero: true, + mask: signal('separator.1'), + leadZero: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('9').blur().should('have.value', '9.0'); @@ -47,10 +45,9 @@ describe('Directive: Mask (emit-events)', () => { it('should keep trailing decimal when mask="separator.1" and leadZero="true"', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.1', - leadZero: true, + mask: signal('separator.1'), + leadZero: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('7.7').blur().should('have.value', '7.7'); @@ -59,11 +56,10 @@ describe('Directive: Mask (emit-events)', () => { it('should emit event only when mask is correct with suffix separator2', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - leadZero: true, - suffix: ' $', + mask: signal('separator.2'), + leadZero: signal(true), + suffix: signal(' $'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('10').blur().should('have.value', '10.00 $'); @@ -73,11 +69,10 @@ describe('Directive: Mask (emit-events)', () => { it('should emit event only when mask is correct with suffix separator.3', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.3', - leadZero: true, - suffix: ' $', + mask: signal('separator.3'), + leadZero: signal(true), + suffix: signal(' $'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('10.0').blur().should('have.value', '10.000 $'); @@ -87,10 +82,9 @@ describe('Directive: Mask (emit-events)', () => { it('should emit event only when mask is correct with separator2', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - leadZero: true, + mask: signal('separator.2'), + leadZero: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('10').blur().should('have.value', '10.00'); @@ -100,10 +94,9 @@ describe('Directive: Mask (emit-events)', () => { it('should emit event only when mask is correct with separator.3', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.3', - leadZero: true, + mask: signal('separator.3'), + leadZero: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('10').blur().should('have.value', '10.000'); @@ -113,9 +106,8 @@ describe('Directive: Mask (emit-events)', () => { it('should emit event only when mask is correct with SS000', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'SS000', + mask: signal('SS000'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').type('SS11111DDDD11').blur().should('have.value', 'SS111'); diff --git a/projects/ngx-mask-lib/src/test/export-as.spec.ts b/projects/ngx-mask-lib/src/test/export-as.spec.ts index 09df4b99..231087b4 100644 --- a/projects/ngx-mask-lib/src/test/export-as.spec.ts +++ b/projects/ngx-mask-lib/src/test/export-as.spec.ts @@ -2,20 +2,19 @@ import type { ComponentFixture } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing'; import { ReactiveFormsModule } from '@angular/forms'; -import { Component, ViewChild } from '@angular/core'; +import { Component, viewChild } from '@angular/core'; import { provideNgxMask } from '../lib/ngx-mask.providers'; import { NgxMaskDirective } from '../lib/ngx-mask.directive'; @Component({ selector: 'jsdaddy-open-source-test', + standalone: true, + imports: [NgxMaskDirective], template: ` `, }) export class TestMaskComponent { - @ViewChild('refMask') - public refMask!: NgxMaskDirective; - - @ViewChild('refNgxMask') - public refNgxMask!: NgxMaskDirective; + public refNgxMask = viewChild('refNgxMask'); + public refMask = viewChild('refMask'); } describe('Directive: Mask export As', () => { @@ -24,8 +23,7 @@ describe('Directive: Mask export As', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); @@ -34,9 +32,9 @@ describe('Directive: Mask export As', () => { }); it('should export directive instance with exportAs api by name equal mask', () => { - expect(component.refMask).toBeInstanceOf(NgxMaskDirective); + expect(component.refMask()).toBeInstanceOf(NgxMaskDirective); }); it('should export directive instance with exportAs api by name equal ngxMask', () => { - expect(component.refNgxMask).toBeInstanceOf(NgxMaskDirective); + expect(component.refNgxMask()).toBeInstanceOf(NgxMaskDirective); }); }); diff --git a/projects/ngx-mask-lib/src/test/inputTransformFn.spec.ts b/projects/ngx-mask-lib/src/test/inputTransformFn.spec.ts index a8e5a35e..56ae77b2 100644 --- a/projects/ngx-mask-lib/src/test/inputTransformFn.spec.ts +++ b/projects/ngx-mask-lib/src/test/inputTransformFn.spec.ts @@ -13,8 +13,7 @@ describe('Directive: Mask', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/keep-character-position.cy-spec.ts b/projects/ngx-mask-lib/src/test/keep-character-position.cy-spec.ts index bfba7384..82ca93ba 100644 --- a/projects/ngx-mask-lib/src/test/keep-character-position.cy-spec.ts +++ b/projects/ngx-mask-lib/src/test/keep-character-position.cy-spec.ts @@ -1,15 +1,14 @@ import { CypressTestMaskComponent } from './utils/cypress-test-component.component'; -import { CypressTestMaskModule } from './utils/cypress-test.module'; +import { signal } from '@angular/core'; describe('Directive: Mask (Delete)', () => { it('should replace character to _ mask: (000) 000-0000', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '(000) 000-0000', - keepCharacterPositions: true, - showMaskTyped: true, + mask: signal('(000) 000-0000'), + keepCharacterPositions: signal(true), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -22,11 +21,10 @@ describe('Directive: Mask (Delete)', () => { it('should replace character to _ mask: S0S S0S', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'S0S AAA', - keepCharacterPositions: true, - showMaskTyped: true, + mask: signal('S0S AAA'), + keepCharacterPositions: signal(true), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -42,11 +40,10 @@ describe('Directive: Mask (Delete)', () => { it('should replace character to _ mask: 000-000.00', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '000-000.00', - keepCharacterPositions: true, - showMaskTyped: true, + mask: signal('000-000.00'), + keepCharacterPositions: signal(true), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -60,11 +57,10 @@ describe('Directive: Mask (Delete)', () => { it('should replace character to _ mask: 0000 0000 0000 0000', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '0000 0000 0000 0000', - keepCharacterPositions: true, - showMaskTyped: true, + mask: signal('0000 0000 0000 0000'), + keepCharacterPositions: signal(true), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -81,11 +77,10 @@ describe('Directive: Mask (Delete)', () => { it('should replace character to _ mask: 00/00/0000', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '00/00/0000', - keepCharacterPositions: true, - showMaskTyped: true, + mask: signal('00/00/0000'), + keepCharacterPositions: signal(true), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -99,12 +94,11 @@ describe('Directive: Mask (Delete)', () => { it('should replace character to _ mask: (000)000-0000, prefix +38', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '(000)000-0000', - keepCharacterPositions: true, - showMaskTyped: true, - prefix: '+38 ', + mask: signal('(000)000-0000'), + keepCharacterPositions: signal(true), + showMaskTyped: signal(true), + prefix: signal('+38 '), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -118,12 +112,11 @@ describe('Directive: Mask (Delete)', () => { it('should replace character to _ mask: 0 000, prefix $', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '0 000', - keepCharacterPositions: true, - showMaskTyped: true, - prefix: '$ ', + mask: signal('0 000'), + keepCharacterPositions: signal(true), + showMaskTyped: signal(true), + prefix: signal('$ '), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -137,12 +130,11 @@ describe('Directive: Mask (Delete)', () => { it('should replace character to _ mask: 0000, prefix foo/', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '0000', - keepCharacterPositions: true, - showMaskTyped: true, - prefix: 'foo/', + mask: signal('0000'), + keepCharacterPositions: signal(true), + showMaskTyped: signal(true), + prefix: signal('foo/'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -155,11 +147,10 @@ describe('Directive: Mask (Delete)', () => { it('should replace character to _ mask: AAA-AAA-AAA', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'AAA-AAA-AAA', - keepCharacterPositions: true, - showMaskTyped: true, + mask: signal('AAA-AAA-AAA'), + keepCharacterPositions: signal(true), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -173,12 +164,11 @@ describe('Directive: Mask (Delete)', () => { it('should replace character to _ mask: 0 000 suffix $', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '0 000', - keepCharacterPositions: true, - showMaskTyped: true, - suffix: ' $', + mask: signal('0 000'), + keepCharacterPositions: signal(true), + showMaskTyped: signal(true), + suffix: signal(' $'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -192,12 +182,11 @@ describe('Directive: Mask (Delete)', () => { it('should replace character to _ mask: 00/00/000 suffix test', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '00/00/000', - keepCharacterPositions: true, - showMaskTyped: true, - suffix: ' test', + mask: signal('00/00/000'), + keepCharacterPositions: signal(true), + showMaskTyped: signal(true), + suffix: signal(' test'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -211,11 +200,10 @@ describe('Directive: Mask (Delete)', () => { it('should delete character from del', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '000-000-000', - keepCharacterPositions: true, - showMaskTyped: true, + mask: signal('000-000-000'), + keepCharacterPositions: signal(true), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -236,11 +224,10 @@ describe('Directive: Mask (Delete)', () => { it('should delete character from del', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '0000 0000 0000 0000', - keepCharacterPositions: true, - showMaskTyped: true, + mask: signal('0000 0000 0000 0000'), + keepCharacterPositions: signal(true), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') diff --git a/projects/ngx-mask-lib/src/test/percent.spec.ts b/projects/ngx-mask-lib/src/test/percent.spec.ts index 46a8a688..4075b8b7 100644 --- a/projects/ngx-mask-lib/src/test/percent.spec.ts +++ b/projects/ngx-mask-lib/src/test/percent.spec.ts @@ -13,8 +13,7 @@ describe('Directive: Mask (Percent)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/place-holder-character.spec.ts b/projects/ngx-mask-lib/src/test/place-holder-character.spec.ts index 92f19ef3..ef95b8ab 100644 --- a/projects/ngx-mask-lib/src/test/place-holder-character.spec.ts +++ b/projects/ngx-mask-lib/src/test/place-holder-character.spec.ts @@ -13,8 +13,7 @@ describe('Directive: Mask (Placeholder character)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/repeat-mask.spec.ts b/projects/ngx-mask-lib/src/test/repeat-mask.spec.ts index fd20bf1d..318468a1 100644 --- a/projects/ngx-mask-lib/src/test/repeat-mask.spec.ts +++ b/projects/ngx-mask-lib/src/test/repeat-mask.spec.ts @@ -13,8 +13,7 @@ describe('Directive: Mask (Repeat)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/secure-mask.spec.ts b/projects/ngx-mask-lib/src/test/secure-mask.spec.ts index fdedcdf8..295659a5 100644 --- a/projects/ngx-mask-lib/src/test/secure-mask.spec.ts +++ b/projects/ngx-mask-lib/src/test/secure-mask.spec.ts @@ -1,11 +1,12 @@ import type { ComponentFixture } from '@angular/core/testing'; -import { fakeAsync, TestBed, tick } from '@angular/core/testing'; +import { fakeAsync, tick } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { ReactiveFormsModule } from '@angular/forms'; import { TestMaskComponent } from './utils/test-component.component'; import { equal, typeTest } from './utils/test-functions.component'; -import { provideNgxMask } from '../lib/ngx-mask.providers'; -import { NgxMaskDirective } from '../lib/ngx-mask.directive'; +import { provideNgxMask } from 'ngx-mask'; +import { NgxMaskDirective } from 'ngx-mask'; import type { DebugElement } from '@angular/core'; import { By } from '@angular/platform-browser'; @@ -15,8 +16,7 @@ describe('Directive: Mask (Secure)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); @@ -70,7 +70,9 @@ describe('Directive: Mask (Secure)', () => { component.mask = 'XXX/X0/0000'; component.hiddenInput = true; typeTest('54321', fixture); - component.form.reset('98765'); + component.form.reset(); + + component.form.setValue('98765'); fixture.whenStable().then(() => { expect(fixture.nativeElement.querySelector('input').value).toBe('***/*5'); }); @@ -88,6 +90,8 @@ describe('Directive: Mask (Secure)', () => { component.mask = 'XXX/X0/0000'; component.hiddenInput = true; typeTest('54321', fixture); + component.form.reset(); + component.form.setValue('1234567'); fixture.whenStable().then(() => { expect(fixture.nativeElement.querySelector('input').value).toBe('***/*5/67'); diff --git a/projects/ngx-mask-lib/src/test/separator-non-en-locale.spec.ts b/projects/ngx-mask-lib/src/test/separator-non-en-locale.spec.ts index 75391381..527fc9bb 100644 --- a/projects/ngx-mask-lib/src/test/separator-non-en-locale.spec.ts +++ b/projects/ngx-mask-lib/src/test/separator-non-en-locale.spec.ts @@ -16,8 +16,7 @@ describe('Separator: Mask with FR locale', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask(), { provide: LOCALE_ID, useValue: 'fr' }], }); fixture = TestBed.createComponent(TestMaskComponent); 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 d7176ed8..14eba918 100644 --- a/projects/ngx-mask-lib/src/test/separator.cy-spec.ts +++ b/projects/ngx-mask-lib/src/test/separator.cy-spec.ts @@ -1,15 +1,14 @@ -import { CypressTestMaskModule } from './utils/cypress-test.module'; import { CypressTestMaskComponent } from './utils/cypress-test-component.component'; +import { signal } from '@angular/core'; describe('Test Date Hh:m0', () => { it('Mask separator.2 check cursor with value 100.0', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - decimalMarker: '.', - thousandSeparator: ',', + mask: signal('separator.2'), + decimalMarker: signal('.'), + thousandSeparator: signal(','), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') .type('1000') @@ -22,11 +21,10 @@ describe('Test Date Hh:m0', () => { it('Mask separator.2 check cursor with value 1.00', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - decimalMarker: '.', - thousandSeparator: ',', + mask: signal('separator.2'), + decimalMarker: signal('.'), + thousandSeparator: signal(','), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') .type('1000') @@ -39,11 +37,10 @@ describe('Test Date Hh:m0', () => { it('Mask separator.2 check cursor with value 123456789.20', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - decimalMarker: '.', - thousandSeparator: ',', + mask: signal('separator.2'), + decimalMarker: signal('.'), + thousandSeparator: signal(','), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') .type('123456789.20') @@ -56,11 +53,10 @@ describe('Test Date Hh:m0', () => { it('Mask separator.2 check cursor with value 100.0', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - decimalMarker: ',', - thousandSeparator: '.', + mask: signal('separator.2'), + decimalMarker: signal(','), + thousandSeparator: signal('.'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') .type('1000') @@ -73,11 +69,10 @@ describe('Test Date Hh:m0', () => { it('Mask separator.2 check cursor with value 1.00', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - decimalMarker: ',', - thousandSeparator: '.', + mask: signal('separator.2'), + decimalMarker: signal(','), + thousandSeparator: signal('.'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') .type('1000') @@ -90,11 +85,10 @@ describe('Test Date Hh:m0', () => { it('Mask separator.2 check cursor with value 123456789.20', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - decimalMarker: ',', - thousandSeparator: '.', + mask: signal('separator.2'), + decimalMarker: signal(','), + thousandSeparator: signal('.'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') .type('123456789,20') @@ -107,10 +101,9 @@ describe('Test Date Hh:m0', () => { it('when decimalMarker doenst set should have right position cursor thousandSeparator = .', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - thousandSeparator: '.', + mask: signal('separator.2'), + thousandSeparator: signal('.'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -125,10 +118,9 @@ describe('Test Date Hh:m0', () => { it('when decimalMarker doenst set should have right position cursor thousandSeparator = ,', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - thousandSeparator: ',', + mask: signal('separator.2'), + thousandSeparator: signal(','), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -143,10 +135,9 @@ describe('Test Date Hh:m0', () => { it('should place cursor after backspace with separatorLimit = 10 in correct position', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - separatorLimit: '10', + mask: signal('separator.2'), + separatorLimit: signal('10'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -161,10 +152,9 @@ describe('Test Date Hh:m0', () => { it('should place cursor after backspace with separatorLimit = 100 in correct position', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - separatorLimit: '100', + mask: signal('separator.2'), + separatorLimit: signal('100'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -179,11 +169,10 @@ describe('Test Date Hh:m0', () => { it('should place cursor after backspace with separatorLimit = 1000 in correct position', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - thousandSeparator: ',', - separatorLimit: '1000', + mask: signal('separator.2'), + thousandSeparator: signal(','), + separatorLimit: signal('1000'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -198,11 +187,10 @@ describe('Test Date Hh:m0', () => { it('should backspace with separator and prefix', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - thousandSeparator: ',', - prefix: '$ ', + mask: signal('separator.2'), + thousandSeparator: signal(','), + prefix: signal('$ '), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -216,11 +204,10 @@ describe('Test Date Hh:m0', () => { it('should backspace with separator and prefix', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - thousandSeparator: '.', - prefix: '$ ', + mask: signal('separator.2'), + thousandSeparator: signal('.'), + prefix: signal('$ '), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -234,11 +221,10 @@ describe('Test Date Hh:m0', () => { it('should correct work after backspace separator.6 decimalMarker . thousandSeparator ,', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.6', - decimalMarker: '.', - thousandSeparator: ',', + mask: signal('separator.6'), + decimalMarker: signal('.'), + thousandSeparator: signal(','), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -257,11 +243,10 @@ describe('Test Date Hh:m0', () => { it('should correct work after backspace separator.2 decimalMarker . thousandSeparator ,', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - decimalMarker: '.', - thousandSeparator: ',', + mask: signal('separator.2'), + decimalMarker: signal('.'), + thousandSeparator: signal(','), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -278,12 +263,11 @@ describe('Test Date Hh:m0', () => { it('should correct work after backspace separator.2 decimalMarker . thousandSeparator , allowNegative', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - decimalMarker: '.', - thousandSeparator: ',', - allowNegativeNumbers: true, + mask: signal('separator.2'), + decimalMarker: signal('.'), + thousandSeparator: signal(','), + allowNegativeNumbers: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -300,12 +284,11 @@ describe('Test Date Hh:m0', () => { it('should correct work after backspace separator.3 decimalMarker . thousandSeparator , allowNegative', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.3', - decimalMarker: '.', - thousandSeparator: ',', - allowNegativeNumbers: true, + mask: signal('separator.3'), + decimalMarker: signal('.'), + thousandSeparator: signal(','), + allowNegativeNumbers: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -322,11 +305,10 @@ describe('Test Date Hh:m0', () => { it('should correct work after backspace separator.3 leadZero allowNegative', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.3', - allowNegativeNumbers: true, - leadZero: true, + mask: signal('separator.3'), + allowNegativeNumbers: signal(true), + leadZero: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -342,9 +324,8 @@ describe('Test Date Hh:m0', () => { it('should correct work after backspace separator', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator', + mask: signal('separator'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -358,10 +339,9 @@ describe('Test Date Hh:m0', () => { it('should correct work after backspace separator leadZero', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator', - leadZero: true, + mask: signal('separator'), + leadZero: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -375,10 +355,9 @@ describe('Test Date Hh:m0', () => { it('should correct work after backspace separator allowNegativeNumbers', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator', - allowNegativeNumbers: true, + mask: signal('separator'), + allowNegativeNumbers: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -392,11 +371,10 @@ describe('Test Date Hh:m0', () => { it('should correct work after backspace separator leadZero', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator', - leadZero: true, - allowNegativeNumbers: true, + mask: signal('separator'), + leadZero: signal(true), + allowNegativeNumbers: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -410,10 +388,9 @@ describe('Test Date Hh:m0', () => { it('should correct work after backspace separator.2 when first digit .', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - thousandSeparator: '.', + mask: signal('separator.2'), + thousandSeparator: signal('.'), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -427,10 +404,9 @@ describe('Test Date Hh:m0', () => { it('should correct work after backspace separator.2 when first digit ,', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - thousandSeparator: ',', + mask: signal('separator.2'), + thousandSeparator: signal(','), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') @@ -444,10 +420,9 @@ describe('Test Date Hh:m0', () => { it('should correct work after backspace separator.2 when first digit whitespace', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: 'separator.2', - thousandSeparator: ' ', + mask: signal('separator.2'), + thousandSeparator: signal(' '), }, - imports: [CypressTestMaskModule], }); cy.get('#masked') diff --git a/projects/ngx-mask-lib/src/test/separator.spec.ts b/projects/ngx-mask-lib/src/test/separator.spec.ts index 93529b7a..1f2e8ea0 100644 --- a/projects/ngx-mask-lib/src/test/separator.spec.ts +++ b/projects/ngx-mask-lib/src/test/separator.spec.ts @@ -15,8 +15,7 @@ describe('Separator: Mask', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/show-mask-typed.cy-spec.ts b/projects/ngx-mask-lib/src/test/show-mask-typed.cy-spec.ts index 535118c5..a46a5a87 100644 --- a/projects/ngx-mask-lib/src/test/show-mask-typed.cy-spec.ts +++ b/projects/ngx-mask-lib/src/test/show-mask-typed.cy-spec.ts @@ -1,14 +1,13 @@ import { CypressTestMaskComponent } from './utils/cypress-test-component.component'; -import { CypressTestMaskModule } from './utils/cypress-test.module'; +import { signal } from '@angular/core'; describe('Directive: Mask (Delete)', () => { it('should place cursor in right place mask (000) 000-0000', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '(000) 000-0000', - showMaskTyped: true, + mask: signal('(000) 000-0000'), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').click().should('have.prop', 'selectionStart', 1); @@ -17,10 +16,9 @@ describe('Directive: Mask (Delete)', () => { it('should place cursor in right place mask ((000)) 000-0000', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '((000)) 000-0000', - showMaskTyped: true, + mask: signal('((000)) 000-0000'), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').click().should('have.prop', 'selectionStart', 2); @@ -29,10 +27,9 @@ describe('Directive: Mask (Delete)', () => { it('should place cursor in right place mask 000 000-0000', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '000 000-0000', - showMaskTyped: true, + mask: signal('000 000-0000'), + showMaskTyped: signal(true), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').click().should('have.prop', 'selectionStart', 0); @@ -41,11 +38,10 @@ describe('Directive: Mask (Delete)', () => { it('should place cursor in right place mask (000) 000-0000', () => { cy.mount(CypressTestMaskComponent, { componentProperties: { - mask: '(000) 000-0000', - showMaskTyped: true, - prefix: '+380 ', + mask: signal('(000) 000-0000'), + showMaskTyped: signal(true), + prefix: signal('+380 '), }, - imports: [CypressTestMaskModule], }); cy.get('#masked').click().should('have.prop', 'selectionStart', 6); diff --git a/projects/ngx-mask-lib/src/test/show-mask-typed.spec.ts b/projects/ngx-mask-lib/src/test/show-mask-typed.spec.ts index 28b9e2d8..9008dc9d 100644 --- a/projects/ngx-mask-lib/src/test/show-mask-typed.spec.ts +++ b/projects/ngx-mask-lib/src/test/show-mask-typed.spec.ts @@ -15,8 +15,7 @@ describe('Directive: Mask', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/test-sufix.spec.ts b/projects/ngx-mask-lib/src/test/test-sufix.spec.ts index baec7b6e..89590bde 100644 --- a/projects/ngx-mask-lib/src/test/test-sufix.spec.ts +++ b/projects/ngx-mask-lib/src/test/test-sufix.spec.ts @@ -14,8 +14,7 @@ describe('Directive: Mask (Suffix)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); 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 5355a101..cf15da40 100644 --- a/projects/ngx-mask-lib/src/test/time-mask.spec.ts +++ b/projects/ngx-mask-lib/src/test/time-mask.spec.ts @@ -13,8 +13,7 @@ describe('Directive: Mask (Time)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/trigger-on-mask-change.cy-spec.ts b/projects/ngx-mask-lib/src/test/trigger-on-mask-change.cy-spec.ts index 0ccece86..66a438d6 100644 --- a/projects/ngx-mask-lib/src/test/trigger-on-mask-change.cy-spec.ts +++ b/projects/ngx-mask-lib/src/test/trigger-on-mask-change.cy-spec.ts @@ -1,11 +1,8 @@ import { CypressTestTriggerOnMaskChangeComponent } from './utils/cypress-test-trigger-on-mask-change.component'; -import { CypressTestMaskModule } from './utils/cypress-test.module'; describe('Directive: Mask (Trigger on mask change) [Cypress]', () => { it('should put back initial value if mask is toggled', async () => { - cy.mount(CypressTestTriggerOnMaskChangeComponent, { - imports: [CypressTestMaskModule], - }); + cy.mount(CypressTestTriggerOnMaskChangeComponent); cy.get('#masked').type('7912345678').should('have.value', '7912345678'); cy.get('.formvalue').should('have.text', '7912345678'); diff --git a/projects/ngx-mask-lib/src/test/trigger-on-mask-change.spec.ts b/projects/ngx-mask-lib/src/test/trigger-on-mask-change.spec.ts index 2d84f3ea..c473484c 100644 --- a/projects/ngx-mask-lib/src/test/trigger-on-mask-change.spec.ts +++ b/projects/ngx-mask-lib/src/test/trigger-on-mask-change.spec.ts @@ -15,8 +15,7 @@ describe('Directive: Mask (Trigger on mask change)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestMaskComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestMaskComponent); diff --git a/projects/ngx-mask-lib/src/test/type-number.spec.ts b/projects/ngx-mask-lib/src/test/type-number.spec.ts index b82144f1..5d0ebc05 100644 --- a/projects/ngx-mask-lib/src/test/type-number.spec.ts +++ b/projects/ngx-mask-lib/src/test/type-number.spec.ts @@ -7,6 +7,8 @@ import { equal } from './utils/test-functions.component'; @Component({ selector: 'jsdaddy-open-source-test', + standalone: true, + imports: [ReactiveFormsModule, NgxMaskDirective], template: ` `, }) // eslint-disable-next-line @angular-eslint/component-class-suffix @@ -21,8 +23,7 @@ describe('Directive: Mask (Trigger on mask change)', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestTypeNumber], - imports: [ReactiveFormsModule, NgxMaskDirective], + imports: [ReactiveFormsModule, NgxMaskDirective, TestTypeNumber], providers: [provideNgxMask()], }); fixture = TestBed.createComponent(TestTypeNumber); diff --git a/projects/ngx-mask-lib/src/test/utils/cypress-test-component.component.ts b/projects/ngx-mask-lib/src/test/utils/cypress-test-component.component.ts index 70cb470a..36248788 100644 --- a/projects/ngx-mask-lib/src/test/utils/cypress-test-component.component.ts +++ b/projects/ngx-mask-lib/src/test/utils/cypress-test-component.component.ts @@ -1,80 +1,101 @@ -import { Component, inject, Input } from '@angular/core'; -import { FormControl } from '@angular/forms'; +import { Component, inject, input } from '@angular/core'; +import { FormControl, ReactiveFormsModule } from '@angular/forms'; import { scan, startWith } from 'rxjs'; import type { NgxMaskConfig } from 'ngx-mask'; +import { provideNgxMask } from 'ngx-mask'; +import { NgxMaskDirective } from 'ngx-mask'; import { NGX_MASK_CONFIG } from 'ngx-mask'; +import { toSignal } from '@angular/core/rxjs-interop'; @Component({ selector: 'jsdaddy-open-source-test', + standalone: true, + imports: [NgxMaskDirective, ReactiveFormsModule], + providers: [provideNgxMask()], template: ` - -
{{ counter$ | async }}
+ [mask]="mask()" + [prefix]="prefix()" + [suffix]="suffix()" + [leadZero]="leadZero()" + [showMaskTyped]="showMaskTyped()" + [allowNegativeNumbers]="allowNegativeNumbers()" + [decimalMarker]="decimalMarker()" + [thousandSeparator]="thousandSeparator()" + [shownMaskExpression]="shownMaskExpression()" + [leadZeroDateTime]="leadZeroDateTime()" + [dropSpecialCharacters]="dropSpecialCharacters()" + [specialCharacters]="specialCharacters()" + [patterns]="patterns()" + [keepCharacterPositions]="keepCharacterPositions()" + [separatorLimit]="separatorLimit()" + [hiddenInput]="hiddenInput()" /> + +
{{ counter$() }}
{{ form.value }}
- {{ leadZeroDateTime }} + {{ leadZeroDateTime() }}
`, }) export class CypressTestMaskComponent { protected _config = inject(NGX_MASK_CONFIG); - @Input() public mask = ''; + public mask = input(''); - @Input() public hiddenInput = null; + public hiddenInput = input(this._config.hiddenInput); - @Input() public allowNegativeNumbers = false; - - @Input() public prefix = ''; + public allowNegativeNumbers = input( + this._config.allowNegativeNumbers + ); - @Input() public suffix = ''; + public prefix = input(this._config.prefix); - @Input() public leadZero = false; + public suffix = input(this._config.suffix); - @Input() public showMaskTyped = false; + public leadZero = input(this._config.leadZero); - @Input() public decimalMarker = '.'; + public showMaskTyped = input(this._config.showMaskTyped); - @Input() public thousandSeparator = ','; + public decimalMarker = input('.'); - @Input() public keepCharacterPositions = false; + public thousandSeparator = input(','); - @Input() public shownMaskExpression = ''; + public keepCharacterPositions = input( + this._config.keepCharacterPositions + ); - @Input() public placeHolderCharacter = ''; + public shownMaskExpression = input( + this._config.shownMaskExpression + ); - @Input() public dropSpecialCharacters = true; + public placeHolderCharacter = input( + this._config.placeHolderCharacter + ); - @Input() public leadZeroDateTime = false; + public dropSpecialCharacters = input( + this._config.dropSpecialCharacters + ); + public leadZeroDateTime = input( + this._config.leadZeroDateTime + ); - @Input() public separatorLimit = ''; + public separatorLimit = input(this._config.separatorLimit); - @Input() public patterns = this._config.patterns; + public patterns = input(this._config.patterns); - @Input() public specialCharacters = this._config.specialCharacters; + public specialCharacters = input( + this._config.specialCharacters + ); public form: FormControl = new FormControl(''); - public readonly counter$ = this.form.valueChanges.pipe( - startWith(0), + public readonly counter$ = toSignal( + this.form.valueChanges.pipe( + startWith(0), - scan((acc) => acc + 1, 0) + scan((acc) => acc + 1, 0) + ) ); } diff --git a/projects/ngx-mask-lib/src/test/utils/cypress-test-shadow-dom.component.ts b/projects/ngx-mask-lib/src/test/utils/cypress-test-shadow-dom.component.ts deleted file mode 100644 index c9f942aa..00000000 --- a/projects/ngx-mask-lib/src/test/utils/cypress-test-shadow-dom.component.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Component, Input, ViewEncapsulation } from '@angular/core'; -import { FormControl } from '@angular/forms'; - -@Component({ - encapsulation: ViewEncapsulation.ShadowDom, - selector: 'jsdaddy-open-source-test', - template: ` - - `, -}) -export class CypressTestMaskShadowDomComponent { - @Input() public mask = ''; - - @Input() public hiddenInput = false; - - @Input() public prefix = ''; - - public form: FormControl = new FormControl(''); -} diff --git a/projects/ngx-mask-lib/src/test/utils/cypress-test-trigger-on-mask-change.component.ts b/projects/ngx-mask-lib/src/test/utils/cypress-test-trigger-on-mask-change.component.ts index 4215ac72..43dbb481 100644 --- a/projects/ngx-mask-lib/src/test/utils/cypress-test-trigger-on-mask-change.component.ts +++ b/projects/ngx-mask-lib/src/test/utils/cypress-test-trigger-on-mask-change.component.ts @@ -1,10 +1,13 @@ import type { OnDestroy, OnInit } from '@angular/core'; import { Component } from '@angular/core'; -import { FormControl } from '@angular/forms'; +import { FormControl, ReactiveFormsModule } from '@angular/forms'; import { Subject, takeUntil } from 'rxjs'; +import { NgxMaskDirective } from 'ngx-mask'; @Component({ selector: 'jsdaddy-open-source-test', + standalone: true, + imports: [ReactiveFormsModule, NgxMaskDirective], styles: [ 'code { border: 1px solid #ddd; background-color: #eee; padding: 0 5px; border-radius: 3px; }', ], diff --git a/projects/ngx-mask-lib/src/test/utils/cypress-test.module.ts b/projects/ngx-mask-lib/src/test/utils/cypress-test.module.ts deleted file mode 100644 index 68deb46b..00000000 --- a/projects/ngx-mask-lib/src/test/utils/cypress-test.module.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { CypressTestTriggerOnMaskChangeComponent } from './cypress-test-trigger-on-mask-change.component'; -import { CypressTestMaskComponent } from './cypress-test-component.component'; -import { CypressTestMaskShadowDomComponent } from './cypress-test-shadow-dom.component'; -import { provideNgxMask } from '../../lib/ngx-mask.providers'; -import { NgxMaskDirective } from '../../lib/ngx-mask.directive'; - -@NgModule({ - imports: [CommonModule, ReactiveFormsModule, FormsModule, NgxMaskDirective], - declarations: [ - CypressTestMaskShadowDomComponent, - CypressTestMaskComponent, - CypressTestTriggerOnMaskChangeComponent, - ], - exports: [ - CypressTestMaskShadowDomComponent, - CypressTestMaskComponent, - CypressTestTriggerOnMaskChangeComponent, - ], - providers: [provideNgxMask()], -}) -export class CypressTestMaskModule {} diff --git a/projects/ngx-mask-lib/src/test/utils/test-component.component.ts b/projects/ngx-mask-lib/src/test/utils/test-component.component.ts index 194ec9e8..f231a1cb 100644 --- a/projects/ngx-mask-lib/src/test/utils/test-component.component.ts +++ b/projects/ngx-mask-lib/src/test/utils/test-component.component.ts @@ -1,9 +1,13 @@ -import { ChangeDetectorRef, Component, inject } from '@angular/core'; -import { FormControl } from '@angular/forms'; +import { Component, inject } from '@angular/core'; +import { FormControl, ReactiveFormsModule } from '@angular/forms'; import type { NgxMaskConfig } from 'ngx-mask'; +import { NGX_MASK_CONFIG } from 'ngx-mask'; +import { NgxMaskDirective } from 'ngx-mask'; @Component({ selector: 'jsdaddy-open-source-test', + standalone: true, + imports: [ReactiveFormsModule, NgxMaskDirective], template: ` `, }) export class TestMaskComponent { public mask!: string | null | undefined; + protected _config = inject(NGX_MASK_CONFIG); public form: FormControl = new FormControl(); - public dropSpecialCharacters: NgxMaskConfig['dropSpecialCharacters'] | undefined; + public dropSpecialCharacters: NgxMaskConfig['dropSpecialCharacters'] = + this._config.dropSpecialCharacters; - public clearIfNotMatch: NgxMaskConfig['clearIfNotMatch'] | undefined; + public clearIfNotMatch: NgxMaskConfig['clearIfNotMatch'] = this._config.clearIfNotMatch; - public patterns: NgxMaskConfig['patterns'] | undefined; + public patterns: NgxMaskConfig['patterns'] = this._config.patterns; - public prefix: NgxMaskConfig['prefix'] = ''; + public prefix: NgxMaskConfig['prefix'] = this._config.prefix; - public thousandSeparator: NgxMaskConfig['thousandSeparator'] | undefined; + public thousandSeparator: NgxMaskConfig['thousandSeparator'] = this._config.thousandSeparator; - public decimalMarker: NgxMaskConfig['decimalMarker'] | undefined; + public decimalMarker: NgxMaskConfig['decimalMarker'] = this._config.decimalMarker; - public suffix: NgxMaskConfig['suffix'] = ''; + public suffix: NgxMaskConfig['suffix'] = this._config.suffix; - public specialCharacters: NgxMaskConfig['specialCharacters'] | undefined; + public specialCharacters: NgxMaskConfig['specialCharacters'] = this._config.specialCharacters; - public keepCharacterPositions: NgxMaskConfig['keepCharacterPositions'] | undefined; + public keepCharacterPositions: NgxMaskConfig['keepCharacterPositions'] = + this._config.keepCharacterPositions; - public showMaskTyped: NgxMaskConfig['showMaskTyped'] | undefined; + public showMaskTyped: NgxMaskConfig['showMaskTyped'] = this._config.showMaskTyped; - public placeHolderCharacter: NgxMaskConfig['placeHolderCharacter'] | undefined; + public placeHolderCharacter: NgxMaskConfig['placeHolderCharacter'] = + this._config.placeHolderCharacter; - public hiddenInput: NgxMaskConfig['hiddenInput'] | undefined; + public hiddenInput: NgxMaskConfig['hiddenInput'] = this._config.hiddenInput; - public separatorLimit: NgxMaskConfig['separatorLimit'] = ''; + public separatorLimit: NgxMaskConfig['separatorLimit'] = this._config.separatorLimit; - public allowNegativeNumbers: NgxMaskConfig['allowNegativeNumbers'] | undefined; + public allowNegativeNumbers: NgxMaskConfig['allowNegativeNumbers'] = + this._config.allowNegativeNumbers; - public leadZeroDateTime: NgxMaskConfig['leadZeroDateTime'] | undefined; + public leadZeroDateTime: NgxMaskConfig['leadZeroDateTime'] = this._config.leadZeroDateTime; - public leadZero: NgxMaskConfig['leadZero'] | undefined; + public leadZero: NgxMaskConfig['leadZero'] = this._config.leadZero; - public triggerOnMaskChange: NgxMaskConfig['triggerOnMaskChange'] | undefined; + public triggerOnMaskChange: NgxMaskConfig['triggerOnMaskChange'] = + this._config.triggerOnMaskChange; - public validation: NgxMaskConfig['validation'] | undefined; + public validation: NgxMaskConfig['validation'] = this._config.validation; - public apm: NgxMaskConfig['apm'] | undefined; + public apm: NgxMaskConfig['apm'] = this._config.apm; - public inputTransformFn: NgxMaskConfig['inputTransformFn'] | undefined; + public inputTransformFn: NgxMaskConfig['inputTransformFn'] = this._config.inputTransformFn; - public outputTransformFn: NgxMaskConfig['outputTransformFn'] | undefined; - - public cdr = inject(ChangeDetectorRef); + public outputTransformFn: NgxMaskConfig['outputTransformFn'] = this._config.outputTransformFn; } diff --git a/projects/ngx-mask-lib/src/test/validation.spec.ts b/projects/ngx-mask-lib/src/test/validation.spec.ts index 6ce0fdd9..6e566403 100644 --- a/projects/ngx-mask-lib/src/test/validation.spec.ts +++ b/projects/ngx-mask-lib/src/test/validation.spec.ts @@ -1,484 +1,275 @@ import type { ComponentFixture } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing'; -import { Component } from '@angular/core'; -import { ReactiveFormsModule, FormControl, Validators } from '@angular/forms'; +import { ReactiveFormsModule, Validators } from '@angular/forms'; import { equal } from './utils/test-functions.component'; import { provideNgxMask } from '../lib/ngx-mask.providers'; import { NgxMaskDirective } from '../lib/ngx-mask.directive'; - -@Component({ - selector: 'jsdaddy-open-source-test', - template: ` `, -}) -export class TestMaskNoValidationAttributeComponent { - public form: FormControl = new FormControl(''); -} - -@Component({ - selector: 'jsdaddy-open-source-test', - template: ` `, -}) -export class TestMaskValidationAttributeComponent { - public form: FormControl = new FormControl(''); - - public validate = true; -} - -@Component({ - selector: 'jsdaddy-open-source-test', - template: ` - - `, -}) -export class TestMaskValidationEmailComponent { - public form: FormControl = new FormControl(''); - - public mask = ''; - - public validate = true; - - public dropSpecialCharacters = false; -} - -@Component({ - selector: 'jsdaddy-open-source-test', - template: ` `, -}) -// eslint-disable-next-line @angular-eslint/component-class-suffix -export class TestMaskValidationTestSymbolStar { - public form: FormControl = new FormControl('', [Validators.required, Validators.min(1)]); - public mask = ''; - public validate = true; -} - -@Component({ - selector: 'jsdaddy-open-source-test', - template: ` `, -}) -// eslint-disable-next-line @angular-eslint/component-class-suffix -export class TestValidatorNumber { - public form: FormControl = new FormControl(44, Validators.required); - public mask = ''; - public validate = true; -} - -@Component({ - selector: 'jsdaddy-open-source-test', - template: ` - - `, -}) -// eslint-disable-next-line @angular-eslint/component-class-suffix -export class TestValidatorDropSpecialCharacters { - public form: FormControl = new FormControl('+373', Validators.required); - public mask = '+000'; - public specialCharacters = ['+', ' ']; - public dropSpecialCharacters = [' ']; -} - -@Component({ - selector: 'jsdaddy-open-source-test', - template: ` - - `, -}) -// eslint-disable-next-line @angular-eslint/component-class-suffix -export class TestValidatorEmailMask { - public form: FormControl = new FormControl('', Validators.required); - public mask = 'A*@A*.A*'; - public dropSpecialCharacters = false; -} +import { TestMaskComponent } from './utils/test-component.component'; describe('Directive: Mask (Validation)', () => { - describe('Global validation true, validation attribute on input not specified', () => { - let fixture: ComponentFixture; - let component: TestMaskNoValidationAttributeComponent; - - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [TestMaskNoValidationAttributeComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], - providers: [provideNgxMask({ validation: true })], - }); - fixture = TestBed.createComponent(TestMaskNoValidationAttributeComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + let fixture: ComponentFixture; + let component: TestMaskComponent; - it('should be marked as not valid if not valid', () => { - equal('12', '12', fixture); - expect(component.form.valid).toBe(false); - expect(component.form.hasError('mask')).toBe(true); - }); - - it('should be marked as valid if valid', () => { - equal('1234', '1234', fixture); - expect(component.form.valid).toBe(true); + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent], + providers: [provideNgxMask({ validation: true })], }); + fixture = TestBed.createComponent(TestMaskComponent); + component = fixture.componentInstance; + fixture.detectChanges(); }); - describe('Global validation true, validation attribute on input specified', () => { - let fixture: ComponentFixture; - let component: TestMaskValidationAttributeComponent; - - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [TestMaskValidationAttributeComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], - providers: [provideNgxMask()], - }); - fixture = TestBed.createComponent(TestMaskValidationAttributeComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + it('should be marked as not valid if not valid and validation attribute true', () => { + component.mask = '0000'; + component.form.addValidators(Validators.required); - it('should be marked as not valid if not valid and validation attribute true', () => { - equal('12', '12', fixture); - expect(component.form.valid).toBe(false); - expect(component.form.hasError('mask')).toBe(true); - }); + equal('12', '12', fixture); + expect(component.form.valid).toBe(false); + expect(component.form.hasError('mask')).toBe(true); + }); - it('should be marked as valid if valid and validation attribute true', () => { - equal('1234', '1234', fixture); - expect(component.form.valid).toBe(true); - }); + it('should be marked as valid if not valid and validation attribute false', () => { + component.validation = false; + component.form.addValidators(Validators.required); - it('should be marked as valid if not valid and validation attribute false', () => { - component.validate = false; - equal('12', '12', fixture); - expect(component.form.valid).toBe(true); - }); + equal('12', '12', fixture); + expect(component.form.valid).toBe(true); }); - describe('Global validation false, validation attribute on input not specified', () => { - let fixture: ComponentFixture; - let component: TestMaskNoValidationAttributeComponent; - - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [TestMaskNoValidationAttributeComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], - providers: [provideNgxMask({ validation: false })], - }); - fixture = TestBed.createComponent(TestMaskNoValidationAttributeComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + it('should be marked as valid if valid and validation attribute true', () => { + component.mask = '0000'; + component.form.addValidators(Validators.required); - it('should be marked as valid if not valid', () => { - equal('12', '12', fixture); - expect(component.form.valid).toBe(true); - }); + equal('1234', '1234', fixture); + expect(component.form.valid).toBe(true); }); - describe('Global validation false, validation attribute on input specified', () => { - let fixture: ComponentFixture; - let component: TestMaskValidationAttributeComponent; - - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [TestMaskValidationAttributeComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], - providers: [provideNgxMask()], - }); - fixture = TestBed.createComponent(TestMaskValidationAttributeComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + it('should be marked as valid if not valid and validation attribute false', () => { + component.validation = false; + component.mask = '0000'; + component.form.addValidators(Validators.required); - it('should be marked as not valid if not valid and validation attribute true', () => { - equal('12', '12', fixture); - expect(component.form.valid).toBe(false); - expect(component.form.hasError('mask')).toBe(true); - }); + equal('12', '12', fixture); + expect(component.form.valid).toBe(true); + }); - it('should be marked as valid if not valid and validation attribute false', () => { - component.validate = false; - equal('12', '12', fixture); - expect(component.form.valid).toBe(true); - }); + it('should be not valid email mask A*@A*.SSS', () => { + component.mask = 'A*@A*.SSS'; + component.dropSpecialCharacters = false; + component.form.addValidators(Validators.required); + + equal('a', 'a', fixture); + expect(component.form.valid).toBe(false); + equal('as', 'as', fixture); + expect(component.form.valid).toBe(false); + equal('asd', 'asd', fixture); + expect(component.form.valid).toBe(false); + equal('andr', 'andr', fixture); + expect(component.form.valid).toBe(false); + equal('testing', 'testing', fixture); + expect(component.form.valid).toBe(false); + equal('testing@', 'testing@', fixture); + expect(component.form.valid).toBe(false); + equal('testing@a', 'testing@a', fixture); + expect(component.form.valid).toBe(false); + equal('testing@aa', 'testing@aa', fixture); + expect(component.form.valid).toBe(false); + equal('testing@gmail', 'testing@gmail', fixture); + expect(component.form.valid).toBe(false); + equal('testing@gmail.', 'testing@gmail.', fixture); + expect(component.form.valid).toBe(false); + equal('testing@gmail.c', 'testing@gmail.c', fixture); + expect(component.form.valid).toBe(false); + equal('testing@email.ua', 'testing@email.ua', fixture); + expect(component.form.valid).toBe(false); }); - describe('Global validation for email', () => { - let fixture: ComponentFixture; - let component: TestMaskValidationEmailComponent; - - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [TestMaskValidationEmailComponent], - imports: [ReactiveFormsModule, NgxMaskDirective], - providers: [provideNgxMask()], - }); - fixture = TestBed.createComponent(TestMaskValidationEmailComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + it('should valid email mask A*@A*.SSS', () => { + component.mask = 'A*@A*.SSS'; + component.dropSpecialCharacters = false; + component.form.addValidators(Validators.required); - it('should be not valid email mask A*@A*.SSS', () => { - component.mask = 'A*@A*.SSS'; - equal('a', 'a', fixture); - expect(component.form.valid).toBe(false); - equal('as', 'as', fixture); - expect(component.form.valid).toBe(false); - equal('asd', 'asd', fixture); - expect(component.form.valid).toBe(false); - equal('andr', 'andr', fixture); - expect(component.form.valid).toBe(false); - equal('testing', 'testing', fixture); - expect(component.form.valid).toBe(false); - equal('testing@', 'testing@', fixture); - expect(component.form.valid).toBe(false); - equal('testing@a', 'testing@a', fixture); - expect(component.form.valid).toBe(false); - equal('testing@aa', 'testing@aa', fixture); - expect(component.form.valid).toBe(false); - equal('testing@gmail', 'testing@gmail', fixture); - expect(component.form.valid).toBe(false); - equal('testing@gmail.', 'testing@gmail.', fixture); - expect(component.form.valid).toBe(false); - equal('testing@gmail.c', 'testing@gmail.c', fixture); - expect(component.form.valid).toBe(false); - equal('testing@email.ua', 'testing@email.ua', fixture); - expect(component.form.valid).toBe(false); - }); + equal('testing@gmail.com', 'testing@gmail.com', fixture); + expect(component.form.valid).toBe(true); + }); - it('should valid email mask A*@A*.SSS', () => { - component.mask = 'A*@A*.SSS'; - equal('testing@gmail.com', 'testing@gmail.com', fixture); - expect(component.form.valid).toBe(true); - }); + it('should be not valid mask A*@A*.SS', () => { + component.mask = 'A*@A*.SS'; + component.dropSpecialCharacters = false; + component.form.addValidators(Validators.required); + + equal('d', 'd', fixture); + expect(component.form.valid).toBe(false); + equal('dd', 'dd', fixture); + expect(component.form.valid).toBe(false); + equal('ddd', 'ddd', fixture); + expect(component.form.valid).toBe(false); + equal('dddd', 'dddd', fixture); + expect(component.form.valid).toBe(false); + equal('andre', 'andre', fixture); + expect(component.form.valid).toBe(false); + equal('andrey', 'andrey', fixture); + expect(component.form.valid).toBe(false); + equal('andrey@', 'andrey@', fixture); + expect(component.form.valid).toBe(false); + equal('andrey@a', 'andrey@a', fixture); + expect(component.form.valid).toBe(false); + equal('andrey@te', 'andrey@te', fixture); + expect(component.form.valid).toBe(false); + equal('andrey@test', 'andrey@test', fixture); + expect(component.form.valid).toBe(false); + equal('andrey@test.c', 'andrey@test.c', fixture); + expect(component.form.valid).toBe(false); + }); - it('should be not valid mask A*@A*.SS', () => { - component.mask = 'A*@A*.SS'; - equal('d', 'd', fixture); - expect(component.form.valid).toBe(false); - equal('dd', 'dd', fixture); - expect(component.form.valid).toBe(false); - equal('ddd', 'ddd', fixture); - expect(component.form.valid).toBe(false); - equal('dddd', 'dddd', fixture); - expect(component.form.valid).toBe(false); - equal('andre', 'andre', fixture); - expect(component.form.valid).toBe(false); - equal('andrey', 'andrey', fixture); - expect(component.form.valid).toBe(false); - equal('andrey@', 'andrey@', fixture); - expect(component.form.valid).toBe(false); - equal('andrey@a', 'andrey@a', fixture); - expect(component.form.valid).toBe(false); - equal('andrey@te', 'andrey@te', fixture); - expect(component.form.valid).toBe(false); - equal('andrey@test', 'andrey@test', fixture); - expect(component.form.valid).toBe(false); - equal('andrey@test.c', 'andrey@test.c', fixture); - expect(component.form.valid).toBe(false); - }); + it('should valid email mask', () => { + component.mask = 'A*@A*.SS'; + component.dropSpecialCharacters = false; + component.form.addValidators(Validators.required); - it('should valid email mask', () => { - component.mask = 'A*@A*.SS'; - equal('testing@some.ua', 'testing@some.ua', fixture); - expect(component.form.valid).toBe(true); - }); + equal('testing@some.ua', 'testing@some.ua', fixture); + expect(component.form.valid).toBe(true); }); - describe('Global validation symbol star', () => { - let fixture: ComponentFixture; - let component: TestMaskValidationTestSymbolStar; - - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [TestMaskValidationTestSymbolStar], - imports: [ReactiveFormsModule, NgxMaskDirective], - providers: [provideNgxMask()], - }); - fixture = TestBed.createComponent(TestMaskValidationTestSymbolStar); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - it('should valid from one digit mask 0*', () => { - component.mask = '0*'; - component.validate = true; - equal('', '', fixture); - expect(component.form.valid).toBe(false); - equal('0', '0', fixture); - expect(component.form.valid).toBe(false); - equal('00', '00', fixture); - expect(component.form.valid).toBe(false); - equal('1', '1', fixture); - expect(component.form.valid).toBe(true); - equal('01', '01', fixture); - expect(component.form.valid).toBe(true); - }); + it('should valid from one digit mask 0*', () => { + component.mask = '0*'; + component.form.setValidators([Validators.required, Validators.min(1)]); + component.form.updateValueAndValidity(); + + equal('', '', fixture); + expect(component.form.valid).toBe(false); + equal('0', '0', fixture); + expect(component.form.valid).toBe(false); + equal('00', '00', fixture); + expect(component.form.valid).toBe(false); + equal('1', '1', fixture); + expect(component.form.valid).toBe(true); + equal('01', '01', fixture); + expect(component.form.valid).toBe(true); + }); - it('should valid from one digit mask S*', () => { - component.mask = 'S*'; - component.validate = true; - equal('', '', fixture); - expect(component.form.valid).toBe(false); - equal('d', 'd', fixture); - expect(component.form.valid).toBe(true); - }); + it('should valid from one digit mask S*', () => { + component.mask = 'S*'; + component.form.setValidators([Validators.required, Validators.min(1)]); + component.form.updateValueAndValidity(); - it('should valid from one digit mask A*', () => { - component.mask = 'A*'; - component.validate = true; - equal('', '', fixture); - expect(component.form.valid).toBe(false); - equal('d', 'd', fixture); - expect(component.form.valid).toBe(true); - equal('1', '1', fixture); - expect(component.form.valid).toBe(true); - }); + equal('', '', fixture); + expect(component.form.valid).toBe(false); + equal('d', 'd', fixture); + expect(component.form.valid).toBe(true); }); - describe('Global validation true, validation attribute on input not specified', () => { - let fixture: ComponentFixture; - let component: TestValidatorNumber; - - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [TestValidatorNumber], - imports: [ReactiveFormsModule, NgxMaskDirective], - providers: [provideNgxMask({ validation: true })], - }); - fixture = TestBed.createComponent(TestValidatorNumber); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('mask with number value should work as expected mask 0*', () => { - component.mask = '0*'; - equal('44', '44', fixture); - expect(component.form.valid).toBe(true); - expect(component.form.value).toBe(44); + it('should valid from one digit mask A*', () => { + component.mask = 'A*'; + component.form.setValidators([Validators.required, Validators.min(1)]); + component.form.updateValueAndValidity(); + + equal('', '', fixture); + expect(component.form.valid).toBe(false); + equal('d', 'd', fixture); + expect(component.form.valid).toBe(true); + equal('1', '1', fixture); + expect(component.form.valid).toBe(true); + }); - equal('', '', fixture); - expect(component.form.invalid).toBe(true); - expect(component.form.value).toBe(''); + it('mask with number value should work as expected mask 0*', () => { + // public form: FormControl = new FormControl(44, Validators.required); + // public mask = ''; + // public validate = true; + component.mask = '0*'; + component.form.setValidators([Validators.required, Validators.min(1)]); + component.form.updateValueAndValidity(); + + equal('44', '44', fixture); + expect(component.form.valid).toBe(true); + expect(component.form.value).toBe('44'); + + equal('', '', fixture); + expect(component.form.invalid).toBe(true); + expect(component.form.value).toBe(''); + + equal('1', '1', fixture); + expect(component.form.valid).toBe(true); + expect(component.form.value).toBe('1'); + }); - equal('1', '1', fixture); - expect(component.form.valid).toBe(true); - expect(component.form.value).toBe(1); - }); + it('mask with number value should work as expected mask 000.00', () => { + component.mask = '000.00'; + component.form.addValidators(Validators.required); + component.form.setValue(''); - it('mask with number value should work as expected mask 000.00', () => { - component.mask = '000.00'; - equal('', '', fixture); - expect(component.form.invalid).toBe(true); - expect(component.form.value).toBe(''); + equal('', '', fixture); + expect(component.form.invalid).toBe(true); + expect(component.form.value).toBe(''); - equal('44', '44', fixture); - expect(component.form.invalid).toBe(true); - expect(component.form.value).toBe(44); + equal('44', '44', fixture); + expect(component.form.invalid).toBe(true); + expect(component.form.value).toBe('44'); - equal('1', '1', fixture); - expect(component.form.invalid).toBe(true); - expect(component.form.value).toBe(1); + equal('1', '1', fixture); + expect(component.form.invalid).toBe(true); + expect(component.form.value).toBe('1'); - equal('444', '444', fixture); - expect(component.form.invalid).toBe(true); - expect(component.form.value).toBe(444); + equal('444', '444', fixture); + expect(component.form.invalid).toBe(true); + expect(component.form.value).toBe('444'); - equal('444.3', '444.3', fixture); - expect(component.form.invalid).toBe(true); - expect(component.form.value).toBe(4443); + equal('444.3', '444.3', fixture); + expect(component.form.invalid).toBe(true); + expect(component.form.value).toBe('4443'); - equal('444.31', '444.31', fixture); - expect(component.form.valid).toBe(true); - expect(component.form.value).toBe(44431); - }); + equal('444.31', '444.31', fixture); + expect(component.form.valid).toBe(true); + expect(component.form.value).toBe('44431'); }); - describe('Global validation true, dropSpecialCharacters attribute on input specified as array', () => { - let fixture: ComponentFixture; - let component: TestValidatorDropSpecialCharacters; - - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [TestValidatorDropSpecialCharacters], - imports: [ReactiveFormsModule, NgxMaskDirective], - providers: [provideNgxMask({ validation: true })], - }); - fixture = TestBed.createComponent(TestValidatorDropSpecialCharacters); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('dropSpecialCharacters is different from specialCharacters', () => { - component.mask = '+000'; - component.specialCharacters = ['+', ' ']; - component.dropSpecialCharacters = [' ']; + it('dropSpecialCharacters is different from specialCharacters', () => { + component.mask = '+000'; + component.specialCharacters = ['+', ' ']; + component.dropSpecialCharacters = [' ']; + component.form.addValidators(Validators.required); - equal('+37', '+37', fixture); - expect(component.form.valid).toBe(false); + equal('+37', '+37', fixture); + expect(component.form.valid).toBe(false); - equal('+373', '+373', fixture); - expect(component.form.valid).toBe(true); + equal('+373', '+373', fixture); + expect(component.form.valid).toBe(true); - component.mask = '+000 000 00 000'; + component.mask = '+000 000 00 000'; - equal('+3736000000', '+373 600 00 00', fixture); - expect(component.form.valid).toBe(false); + equal('+3736000000', '+373 600 00 00', fixture); + expect(component.form.valid).toBe(false); - equal('+37360000000', '+373 600 00 000', fixture); - expect(component.form.valid).toBe(true); - }); + equal('+37360000000', '+373 600 00 000', fixture); + expect(component.form.valid).toBe(true); }); - describe('Global validation true, email mask', () => { - let fixture: ComponentFixture; - let component: TestValidatorEmailMask; - - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [TestValidatorEmailMask], - imports: [ReactiveFormsModule, NgxMaskDirective], - providers: [provideNgxMask({ validation: true })], - }); - fixture = TestBed.createComponent(TestValidatorEmailMask); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('email Mask should validated correct', () => { - component.mask = 'A*@A*.A*'; - component.dropSpecialCharacters = false; + it('email Mask should validated correct', () => { + component.mask = 'A*@A*.A*'; + component.dropSpecialCharacters = false; + component.form.addValidators(Validators.required); - equal('validate', 'validate', fixture); - expect(component.form.valid).toBe(false); + equal('validate', 'validate', fixture); + expect(component.form.valid).toBe(false); - equal('validate@', 'validate@', fixture); - expect(component.form.valid).toBe(false); + equal('validate@', 'validate@', fixture); + expect(component.form.valid).toBe(false); - equal('validate@some', 'validate@some', fixture); - expect(component.form.valid).toBe(false); + equal('validate@some', 'validate@some', fixture); + expect(component.form.valid).toBe(false); - equal('validate@some.', 'validate@some.', fixture); - expect(component.form.valid).toBe(false); + equal('validate@some.', 'validate@some.', fixture); + expect(component.form.valid).toBe(false); - equal('validate@some.e', 'validate@some.e', fixture); - expect(component.form.valid).toBe(true); + equal('validate@some.e', 'validate@some.e', fixture); + expect(component.form.valid).toBe(true); - equal('validate@some.eu', 'validate@some.eu', fixture); - expect(component.form.valid).toBe(true); + equal('validate@some.eu', 'validate@some.eu', fixture); + expect(component.form.valid).toBe(true); - equal('validate@some.com', 'validate@some.com', fixture); - expect(component.form.valid).toBe(true); - }); + equal('validate@some.com', 'validate@some.com', fixture); + expect(component.form.valid).toBe(true); }); }); diff --git a/src/app/options/options.component.ts b/src/app/options/options.component.ts index 16d8b5b8..f2d53679 100644 --- a/src/app/options/options.component.ts +++ b/src/app/options/options.component.ts @@ -5,7 +5,6 @@ import { initialConfig, NgxMaskDirective, NgxMaskPipe } from 'ngx-mask'; import { HighlightModule } from 'ngx-highlightjs'; import { AssetPipe } from '@libraries/asset/asset.pipe'; import { IsEmptyPipe } from '@open-source/is-empty/is-empty.pipe'; -import { ColorPipe } from '@open-source/color/color.pipe'; import { CardContentComponent } from '../shared/card-content/card-content.component'; import { ScrollService } from '@open-source/scroll/scroll.service'; import { AccordionService } from '@open-source/accordion/accordion.service'; @@ -29,7 +28,6 @@ import type { ComDoc, MaskOptions, TExample } from '@open-source/accordion/conte NgxMaskPipe, AssetPipe, IsEmptyPipe, - ColorPipe, CardContentComponent, NgOptimizedImage, ], diff --git a/src/libraries b/src/libraries index 339053d4..44bebdfb 160000 --- a/src/libraries +++ b/src/libraries @@ -1 +1 @@ -Subproject commit 339053d4cd781ffede25ca6049defbedd69c67b5 +Subproject commit 44bebdfba90c6534af67bf84d5f90f8f1b0b343b diff --git a/src/styles.scss b/src/styles.scss index b5c61c95..a065c93f 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -1,3 +1,5 @@ +@use './libraries/styles/scroll-bar'; + @tailwind base; @tailwind components; @tailwind utilities; diff --git a/tsconfig.json b/tsconfig.json index 49d5458f..e154a50d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -39,6 +39,7 @@ "isolatedModules": true }, "angularCompilerOptions": { + "strictStandalone": true, "enableI18nLegacyMessageIdFormat": false, "strictInjectionParameters": true, "preserveWhitespaces": true, @@ -48,7 +49,8 @@ "extendedDiagnostics": { "checks": { "invalidBananaInBox": "error", - "nullishCoalescingNotNullable": "warning" + "nullishCoalescingNotNullable": "warning", + "unusedStandaloneImports": "suppress" }, "defaultCategory": "suppress" }