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.
feat(kit):
DateTime
supports configurable parameter `dateTimeSepara…
…tor` (#1143)
- Loading branch information
1 parent
8e853a2
commit ec86284
Showing
19 changed files
with
315 additions
and
64 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
projects/demo-integrations/src/tests/kit/date-time/date-time-date-time-separator.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,61 @@ | ||
import {DemoPath} from '@demo/constants'; | ||
import type {MaskitoTimeMode} from '@maskito/kit'; | ||
|
||
describe('DateTime | dateTimeSeparator', () => { | ||
const dateTimeSeparators = [':', ';_', '_-_', '_at_']; | ||
|
||
dateTimeSeparators.forEach(dateTimeSeparator => { | ||
const testCases: Array<{ | ||
typedDigits: string; | ||
formattedDate: string; | ||
formattedValue: string; | ||
timeMode: MaskitoTimeMode; | ||
}> = [ | ||
{ | ||
typedDigits: '522004341', | ||
formattedValue: `05.02.2004${dateTimeSeparator}03:41`, | ||
formattedDate: '05.02.2004', | ||
timeMode: 'HH:MM', | ||
}, | ||
{ | ||
typedDigits: '233123434111', | ||
formattedValue: `23.03.1234${dateTimeSeparator}03:41:11`, | ||
formattedDate: '23.03.1234', | ||
timeMode: 'HH:MM:SS', | ||
}, | ||
{ | ||
typedDigits: '69200734111111', | ||
formattedValue: `06.09.2007${dateTimeSeparator}03:41:11.111`, | ||
formattedDate: '06.09.2007', | ||
timeMode: 'HH:MM:SS.MSS', | ||
}, | ||
]; | ||
|
||
describe(`correctly applies "${dateTimeSeparator}" as dateTimeSeparator`, () => { | ||
testCases.forEach( | ||
({typedDigits, formattedDate, formattedValue, timeMode}) => { | ||
const timeDigitsCount = timeMode.replaceAll(/[:.]/g, '').length; | ||
|
||
beforeEach(() => { | ||
cy.visit( | ||
`/${DemoPath.DateTime}/API?dateTimeSeparator=${encodeURIComponent(dateTimeSeparator)}&timeMode=${encodeURIComponent(timeMode)}`, | ||
); | ||
cy.get('#demo-content input') | ||
.should('be.visible') | ||
.first() | ||
.focus() | ||
.as('input'); | ||
}); | ||
|
||
it(`${typedDigits} => ${formattedValue} => {backspace} * ${timeDigitsCount} => ${formattedDate}`, () => { | ||
cy.get('@input') | ||
.type(typedDigits) | ||
.should('have.value', formattedValue) | ||
.type('{backspace}'.repeat(timeDigitsCount)) | ||
.should('have.value', formattedDate); | ||
}); | ||
}, | ||
); | ||
}); | ||
}); | ||
}); |
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
39 changes: 39 additions & 0 deletions
39
projects/demo/src/pages/kit/date-time/examples/2-date-time-separator/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,39 @@ | ||
import {ChangeDetectionStrategy, 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: 'date-time-mask-doc-example-2', | ||
imports: [ | ||
TuiInputModule, | ||
TuiTextfieldControllerModule, | ||
FormsModule, | ||
MaskitoDirective, | ||
], | ||
template: ` | ||
<tui-input | ||
tuiTextfieldCustomContent="tuiIconCalendarLarge" | ||
[style.max-width.rem]="30" | ||
[tuiTextfieldFiller]="filler" | ||
[(ngModel)]="value" | ||
> | ||
Custom date and time separator | ||
<input | ||
inputmode="decimal" | ||
tuiTextfield | ||
[maskito]="mask" | ||
/> | ||
</tui-input> | ||
`, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class DateTimeMaskDocExample2 { | ||
protected value = '05.02.2004; 10:10'; | ||
protected readonly filler = 'dd.mm.yyyy; hh:mm'; | ||
protected readonly mask = mask; | ||
} |
7 changes: 7 additions & 0 deletions
7
projects/demo/src/pages/kit/date-time/examples/2-date-time-separator/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,7 @@ | ||
import {maskitoDateTimeOptionsGenerator} from '@maskito/kit'; | ||
|
||
export default maskitoDateTimeOptionsGenerator({ | ||
dateMode: 'dd/mm/yyyy', | ||
timeMode: 'HH:MM', | ||
dateTimeSeparator: '; ', | ||
}); |
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
Oops, something went wrong.