forked from JsDaddy/ngx-mask
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build: fix new rxjs requirements * build: limit node to v14 * feat(test): add cypress component testing * test(directive): add delete e2e tests * build: update package-lock.json Co-authored-by: Manuel Meister <[email protected]> Co-authored-by: Manuel Meister <[email protected]>
- Loading branch information
1 parent
841a799
commit 2851cb0
Showing
10 changed files
with
21,708 additions
and
9,691 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"fixturesFolder": "./src/test/utils", | ||
"pluginsFile": "./cypress/plugins/index.ts", | ||
"supportFile": "./cypress/support/index.ts", | ||
"component": { | ||
"testFiles": "**/*.cy-spec.{js,ts,jsx,tsx}", | ||
"componentFolder": "./src" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ResolvedDevServerConfig } from '@cypress/webpack-dev-server'; | ||
import { startAngularDevServer } from '@jscutlery/cypress-angular-dev-server'; | ||
|
||
module.exports = ( | ||
on: (arg0: string, arg1: (options: any) => Promise<ResolvedDevServerConfig>) => void, | ||
config: any | ||
) => { | ||
on('dev-server:start', (options) => startAngularDevServer({ options, tsConfig: 'tsconfig.cypress.json' })); | ||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
declare namespace Cypress { | ||
interface Chainable { | ||
setSelectionRange(start: number, end: number): Chainable<JQuery<HTMLInputElement>>; | ||
} | ||
} | ||
|
||
Cypress.Commands.add('setSelectionRange', { prevSubject: 'element' }, (subject, start, end) => { | ||
return cy.wrap(subject).then(($el: JQuery<HTMLInputElement>) => { | ||
$el[0].setSelectionRange(start, end); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import '@jscutlery/cypress-angular/support'; | ||
import './commands'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { mount } from '@jscutlery/cypress-angular/mount'; | ||
import { CypressTestMaskComponent, CypressTestMaskModule } from './utils/cypress-test-component.component'; | ||
|
||
describe('Directive: Mask (Delete)', () => { | ||
it('should delete character in input', () => { | ||
mount(CypressTestMaskComponent, { | ||
inputs: { | ||
mask: '00/00/0000', | ||
}, | ||
imports: [CypressTestMaskModule], | ||
}); | ||
|
||
const inputTarget = cy.get('input'); | ||
inputTarget.type('12/34/5678'); | ||
inputTarget.focus(); | ||
inputTarget.setSelectionRange(1, 1); | ||
inputTarget.type('{backspace}'); | ||
|
||
inputTarget.should('have.value', '23/45/678'); | ||
}); | ||
|
||
it('should not delete special mask character', () => { | ||
mount(CypressTestMaskComponent, { | ||
inputs: { | ||
mask: '00/00/0000', | ||
}, | ||
imports: [CypressTestMaskModule], | ||
}); | ||
|
||
const inputTarget = cy.get('input'); | ||
inputTarget.type('12/34/5678'); | ||
inputTarget.setSelectionRange(3, 3); | ||
inputTarget.type('{backspace}'); | ||
|
||
inputTarget.should('have.value', '12/34/5678'); | ||
inputTarget.should('have.prop', 'selectionStart', 2); | ||
}); | ||
|
||
it('should delete secure character', () => { | ||
mount(CypressTestMaskComponent, { | ||
inputs: { | ||
mask: 'XXX/X0/0000', | ||
hiddenInput: true, | ||
}, | ||
imports: [CypressTestMaskModule], | ||
}); | ||
|
||
const inputTarget = cy.get('input'); | ||
inputTarget.type('123/45/6789'); | ||
inputTarget.setSelectionRange(3, 3); | ||
inputTarget.type('{backspace}'); | ||
|
||
inputTarget.should('have.value', '***/*6/789'); | ||
inputTarget.should('have.prop', 'selectionStart', 2); | ||
}); | ||
|
||
it('should not delete prefix', () => { | ||
mount(CypressTestMaskComponent, { | ||
inputs: { | ||
mask: '(00) 00', | ||
prefix: '+1 ', | ||
}, | ||
imports: [CypressTestMaskModule], | ||
}); | ||
|
||
const inputTarget = cy.get('input'); | ||
inputTarget.type('1234'); | ||
inputTarget.setSelectionRange(3, 3); | ||
inputTarget.type('{backspace}'); | ||
|
||
inputTarget.should('have.value', '+1 (12) 34'); | ||
inputTarget.should('have.prop', 'selectionStart', 3); | ||
}); | ||
|
||
it('should delete selection', () => { | ||
mount(CypressTestMaskComponent, { | ||
inputs: { | ||
mask: '000 000 000', | ||
}, | ||
imports: [CypressTestMaskModule], | ||
}); | ||
|
||
const inputTarget = cy.get('input'); | ||
inputTarget.type('123456789'); | ||
inputTarget.setSelectionRange(4, 7); | ||
inputTarget.type('{backspace}'); | ||
|
||
inputTarget.should('have.value', '123 789'); | ||
inputTarget.should('have.prop', 'selectionStart', 3); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
projects/ngx-mask-lib/src/test/utils/cypress-test-component.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Component, Input, NgModule } from '@angular/core'; | ||
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms'; | ||
|
||
import { CommonModule } from '@angular/common'; | ||
import { NgxMaskModule } from 'ngx-mask'; | ||
|
||
@Component({ | ||
selector: 'mask-cypress-test-mask', | ||
template: ` <input id="maska" [formControl]="form" [mask]="mask" [hiddenInput]="hiddenInput" [prefix]="prefix" /> `, | ||
}) | ||
export class CypressTestMaskComponent { | ||
@Input() public mask!: string | null; | ||
@Input() public hiddenInput: boolean = false; | ||
@Input() public prefix: string = ''; | ||
public form: FormControl = new FormControl(''); | ||
} | ||
|
||
@NgModule({ | ||
imports: [CommonModule, ReactiveFormsModule, FormsModule, NgxMaskModule.forRoot()], | ||
declarations: [CypressTestMaskComponent], | ||
exports: [CypressTestMaskComponent], | ||
}) | ||
export class CypressTestMaskModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"allowSyntheticDefaultImports": true, | ||
"allowJs": true, | ||
"types": ["cypress", "node"] | ||
}, | ||
"include": ["src/test/test/*.cy-spec.ts", "cypress/support/**/*.ts", "**/*.cy-spec.ts"] | ||
} |