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.
- Loading branch information
1 parent
e63d384
commit 0c6d1b9
Showing
3 changed files
with
81 additions
and
6 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
58 changes: 58 additions & 0 deletions
58
projects/kit/src/lib/masks/time/processors/tests/max-validation-preprocessor.spec.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 {DEFAULT_TIME_SEGMENT_MAX_VALUES} from '../../../../constants'; | ||
import {createMaxValidationPreprocessor} from '../max-validation-preprocessor'; | ||
|
||
describe('createMaxValidationPreprocessor', () => { | ||
const processor = createMaxValidationPreprocessor(DEFAULT_TIME_SEGMENT_MAX_VALUES); | ||
|
||
describe('Paste from clipboard', () => { | ||
const process = (data: string): string => | ||
processor( | ||
{ | ||
elementState: { | ||
value: '', | ||
selection: [0, 0], | ||
}, | ||
data, | ||
}, | ||
'insert', | ||
).data || ''; | ||
|
||
it('All time segments valid', () => { | ||
expect(process('17:43:00')).toBe('17:43:00'); | ||
}); | ||
|
||
it('contains invalid time segment for hours', () => { | ||
expect(process('30:30:30')).toBe(''); | ||
}); | ||
|
||
it('Invalid time segment for minutes', () => { | ||
expect(process('23:70:30')).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('Dropping text inside with a pointer / browser autofill', () => { | ||
const process = (value: string): string => | ||
processor( | ||
{ | ||
elementState: { | ||
value, | ||
selection: [0, value.length], | ||
}, | ||
data: '', | ||
}, | ||
'validation', | ||
).elementState.value; | ||
|
||
it('All time segments valid', () => { | ||
expect(process('17:43:00')).toBe('17:43:00'); | ||
}); | ||
|
||
it('contains invalid time segment for hours', () => { | ||
expect(process('30:30:30')).toBe(''); | ||
}); | ||
|
||
it('Invalid time segment for minutes', () => { | ||
expect(process('23:70:30')).toBe(''); | ||
}); | ||
}); | ||
}); |
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