generated from Tinkoff/angular-open-source-starter
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbff667
commit a7bec35
Showing
14 changed files
with
482 additions
and
523 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
projects/demo-integrations/src/tests/kit/number/number-minus-sign.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,102 @@ | ||
import { | ||
CHAR_EM_DASH, | ||
CHAR_EN_DASH, | ||
CHAR_HYPHEN, | ||
CHAR_JP_HYPHEN, | ||
CHAR_MINUS, | ||
} from 'projects/kit/src/lib/constants'; | ||
|
||
import {openNumberPage} from './utils'; | ||
|
||
describe('Properly using custom minus sign', () => { | ||
const minuses: Array<{value: string; name: string}> = [ | ||
{ | ||
value: CHAR_HYPHEN, | ||
name: 'hyphen', | ||
}, | ||
{ | ||
value: CHAR_EN_DASH, | ||
name: 'en-dash', | ||
}, | ||
{ | ||
value: CHAR_EM_DASH, | ||
name: 'em-dash', | ||
}, | ||
]; | ||
|
||
const numbers = ['321', '2_432']; | ||
|
||
const pseudoMinuses: Array<{value: string; name: string}> = [ | ||
{value: CHAR_HYPHEN, name: 'hyphen'}, | ||
{value: CHAR_EN_DASH, name: 'en-dash'}, | ||
{value: CHAR_EM_DASH, name: 'em-dash'}, | ||
{value: CHAR_JP_HYPHEN, name: 'japanese prolonged sound mark'}, | ||
{value: CHAR_MINUS, name: 'unicode minus sign'}, | ||
]; | ||
|
||
minuses.forEach(minus => { | ||
pseudoMinuses.forEach(pseudoMinus => { | ||
numbers.forEach(number => { | ||
it(`transforms ${pseudoMinus.name} into ${minus.name}`, () => { | ||
openNumberPage( | ||
`precision=Infinity&thousandSeparator=_&minusSign=${encodeURIComponent(minus.value)}`, | ||
); | ||
cy.get('@input') | ||
.type(`${pseudoMinus.value}${number}`) | ||
.should('have.value', `${minus.value}${number}`); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('can use letters as minus sign', () => { | ||
beforeEach(() => { | ||
openNumberPage('precision=Infinity&thousandSeparator=_&minusSign=i'); | ||
}); | ||
|
||
it('transforms i into i', () => { | ||
cy.get('@input').type('i1234').should('have.value', 'i1_234'); | ||
}); | ||
|
||
pseudoMinuses.forEach(pseudoMinus => { | ||
it(`transforms ${pseudoMinus.name} into i`, () => { | ||
cy.get('@input') | ||
.type(`${pseudoMinus.value}1234`) | ||
.should('have.value', 'i1_234'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('custom minus should work properly with min(max) value', () => { | ||
[ | ||
{value: CHAR_HYPHEN, name: 'hyphen'}, | ||
{value: CHAR_EN_DASH, name: 'en-dash'}, | ||
{value: CHAR_EM_DASH, name: 'em-dash'}, | ||
{ | ||
value: CHAR_JP_HYPHEN, | ||
name: 'japanese prolonged sound mark', | ||
}, | ||
{value: CHAR_MINUS, name: 'unicode minus sign'}, | ||
].forEach(minus => { | ||
describe(`applies ${minus.name} properly`, () => { | ||
beforeEach(() => { | ||
openNumberPage( | ||
`min=-123&thousandSeparator=_&minusSign=${encodeURIComponent(minus.value)}`, | ||
); | ||
}); | ||
|
||
it(`-94 => ${minus.value}94`, () => { | ||
cy.get('@input') | ||
.type(`${minus.value}94`) | ||
.should('have.value', `${minus.value}94`); | ||
}); | ||
|
||
it(`-432 => ${minus.value}123`, () => { | ||
cy.get('@input') | ||
.type(`${minus.value}432`) | ||
.should('have.value', `${minus.value}123`); | ||
}); | ||
}); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
projects/demo/src/pages/kit/number/examples/5-custom-minus-sign/components.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,34 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormsModule} from '@angular/forms'; | ||
import {MaskitoDirective} from '@maskito/angular'; | ||
import {TuiTextfieldControllerModule} from '@taiga-ui/core'; | ||
import {TuiInputModule} from '@taiga-ui/kit'; | ||
|
||
import mask from './mask'; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'number-mask-doc-example-5', | ||
imports: [ | ||
TuiInputModule, | ||
TuiTextfieldControllerModule, | ||
MaskitoDirective, | ||
FormsModule, | ||
], | ||
template: ` | ||
<tui-input | ||
[style.max-width.rem]="30" | ||
[tuiTextfieldLabelOutside]="true" | ||
[(ngModel)]="value" | ||
> | ||
<input | ||
tuiTextfield | ||
[maskito]="options" | ||
/> | ||
</tui-input> | ||
`, | ||
}) | ||
export class NumberMaskDocExample5 { | ||
protected value = '-42'; | ||
protected readonly options = mask; | ||
} |
6 changes: 6 additions & 0 deletions
6
projects/demo/src/pages/kit/number/examples/5-custom-minus-sign/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,6 @@ | ||
import {maskitoNumberOptionsGenerator} from '@maskito/kit'; | ||
|
||
export default maskitoNumberOptionsGenerator({ | ||
minusSign: '-', | ||
thousandSeparator: '', | ||
}); |
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
File renamed without changes.
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
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.