generated from Tinkoff/angular-open-source-starter
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kit): new
maskitoPostfixPostprocessorGenerator
(#257)
- Loading branch information
1 parent
ed9a503
commit fdc86db
Showing
18 changed files
with
431 additions
and
139 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
projects/demo-integrations/cypress/tests/recipes/postfix/percentage.cy.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
112 changes: 112 additions & 0 deletions
112
projects/demo-integrations/cypress/tests/recipes/postfix/postprocessor.cy.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,112 @@ | ||
import {DemoPath} from '@demo/path'; | ||
|
||
describe('Postfix | Postprocessor (maskitoPostfixPostprocessorGenerator)', () => { | ||
beforeEach(() => { | ||
cy.visit(DemoPath.Postfix); | ||
cy.get('#by-postprocessor input') | ||
.should('be.visible') | ||
.first() | ||
.should('have.value', '') | ||
.focus() | ||
.as('input'); | ||
}); | ||
|
||
it('Type 100 => $100|.00', () => { | ||
cy.get('@input') | ||
.should('have.value', '$.00') | ||
.should('have.prop', 'selectionStart', 1) | ||
.should('have.prop', 'selectionEnd', 1) | ||
.type('100') | ||
.should('have.value', '$100.00') | ||
.should('have.prop', 'selectionStart', '$100'.length) | ||
.should('have.prop', 'selectionEnd', '$100'.length); | ||
}); | ||
|
||
it('$10|0.00 => Backspace => Type 5 => $15|0.00', () => { | ||
cy.get('@input') | ||
.should('have.value', '$.00') | ||
.should('have.prop', 'selectionStart', 1) | ||
.should('have.prop', 'selectionEnd', 1) | ||
.type('100') | ||
.type('{leftArrow}{backspace}') | ||
.type('5') | ||
.should('have.value', '$150.00') | ||
.should('have.prop', 'selectionStart', '$15'.length) | ||
.should('have.prop', 'selectionEnd', '$15'.length); | ||
}); | ||
|
||
describe('Attempts to delete the postfix', () => { | ||
beforeEach(() => { | ||
cy.get('@input') | ||
.should('have.value', '$.00') | ||
.should('have.prop', 'selectionStart', 1) | ||
.should('have.prop', 'selectionEnd', 1) | ||
.type('100'); | ||
}); | ||
|
||
it('$100.00| => Backspace => $100.0|0', () => { | ||
cy.get('@input') | ||
.type('{moveToEnd}{backspace}') | ||
.should('have.value', '$100.00') | ||
.should('have.prop', 'selectionStart', '$100.0'.length) | ||
.should('have.prop', 'selectionEnd', '$100.0'.length); | ||
}); | ||
|
||
it('$100.0|0 => Backspace => $100.|00', () => { | ||
cy.get('@input') | ||
.type('{moveToEnd}{leftArrow}{backspace}') | ||
.should('have.value', '$100.00') | ||
.should('have.prop', 'selectionStart', '$100.'.length) | ||
.should('have.prop', 'selectionEnd', '$100.'.length); | ||
}); | ||
|
||
it('$100.|00 => Backspace => $100|.00', () => { | ||
cy.get('@input') | ||
.type('{moveToEnd}') | ||
.type('{leftArrow}'.repeat('00'.length)) | ||
.type('{backspace}') | ||
.should('have.value', '$100.00') | ||
.should('have.prop', 'selectionStart', '$100'.length) | ||
.should('have.prop', 'selectionEnd', '$100'.length); | ||
}); | ||
|
||
it('$100.00 => Select All => Delete => $|.00', () => { | ||
cy.get('@input') | ||
.type('{selectAll}{del}') | ||
.should('have.value', '$.00') | ||
.should('have.prop', 'selectionStart', 1) | ||
.should('have.prop', 'selectionEnd', 1); | ||
}); | ||
}); | ||
|
||
describe('Attempts to delete the prefix', () => { | ||
beforeEach(() => { | ||
cy.get('@input') | ||
.should('have.value', '$.00') | ||
.should('have.prop', 'selectionStart', 1) | ||
.should('have.prop', 'selectionEnd', 1) | ||
.type('1') | ||
.should('have.value', '$1.00') | ||
.should('have.prop', 'selectionStart', 2) | ||
.should('have.prop', 'selectionEnd', 2); | ||
}); | ||
|
||
it('$|1.00 => Backspace => $|1.00', () => { | ||
cy.get('@input') | ||
.type('{leftArrow}') | ||
.type('{backspace}') | ||
.should('have.value', '$1.00') | ||
.should('have.prop', 'selectionStart', 1) | ||
.should('have.prop', 'selectionEnd', 1); | ||
}); | ||
|
||
it('|$1.00 => Delete => $|1.00', () => { | ||
cy.get('@input') | ||
.type('{moveToStart}') | ||
.type('{del}') | ||
.should('have.value', '$1.00') | ||
.should('have.prop', 'selectionStart', 1) | ||
.should('have.prop', 'selectionEnd', 1); | ||
}); | ||
}); | ||
}); |
52 changes: 0 additions & 52 deletions
52
projects/demo-integrations/cypress/tests/recipes/postfix/time.cy.ts
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
58 changes: 58 additions & 0 deletions
58
projects/demo/src/pages/recipes/postfix/examples/2-postprocessor/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,58 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
ElementRef, | ||
NgZone, | ||
ViewChild, | ||
} from '@angular/core'; | ||
|
||
import mask from './mask'; | ||
|
||
@Component({ | ||
selector: 'postfix-doc-example-2', | ||
template: ` | ||
<tui-input | ||
[style.max-width.rem]="20" | ||
[(ngModel)]="value" | ||
> | ||
Enter price | ||
<input | ||
#inputRef | ||
tuiTextfield | ||
inputmode="numeric" | ||
[maskito]="maskitoOptions" | ||
(focus)="onFocus()" | ||
(blur)="onBlur()" | ||
/> | ||
</tui-input> | ||
`, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class PostfixDocExample2 { | ||
@ViewChild('inputRef', {read: ElementRef}) | ||
inputElement!: ElementRef<HTMLInputElement>; | ||
|
||
readonly maskitoOptions = mask; | ||
value = ''; | ||
|
||
constructor(private readonly ngZone: NgZone) {} | ||
|
||
onFocus(): void { | ||
if (!this.value) { | ||
this.value = '$.00'; | ||
|
||
this.ngZone.runOutsideAngular(() => | ||
setTimeout(() => { | ||
// To put cursor after dollar ($|.00) | ||
this.inputElement.nativeElement.setSelectionRange(1, 1); | ||
}), | ||
); | ||
} | ||
} | ||
|
||
onBlur(): void { | ||
if (this.value === '$.00') { | ||
this.value = ''; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
projects/demo/src/pages/recipes/postfix/examples/2-postprocessor/mask.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,14 @@ | ||
import {MaskitoOptions, maskitoPipe} from '@maskito/core'; | ||
import { | ||
maskitoPostfixPostprocessorGenerator, | ||
maskitoPrefixPostprocessorGenerator, | ||
} from '@maskito/kit'; | ||
|
||
export default { | ||
// prefix (dollar sign) + digits + postfix ('.00') | ||
mask: /^\$?\d*(\.0{0,2})?$/, | ||
postprocessor: maskitoPipe( | ||
maskitoPrefixPostprocessorGenerator('$'), | ||
maskitoPostfixPostprocessorGenerator('.00'), | ||
), | ||
} as MaskitoOptions; |
25 changes: 0 additions & 25 deletions
25
projects/demo/src/pages/recipes/postfix/examples/2-time-pm/component.ts
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
projects/demo/src/pages/recipes/postfix/examples/2-time-pm/mask.ts
This file was deleted.
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
Oops, something went wrong.