mirror of
https://github.com/tenrok/maska.git
synced 2026-05-15 11:59:38 +03:00
Fix eager mask bug #128
This commit is contained in:
+2
-5
@@ -105,16 +105,13 @@ export class MaskInput {
|
||||
let value = valueOld
|
||||
|
||||
if (mask.isEager()) {
|
||||
const masked = mask.masked(valueOld)
|
||||
const unmasked = mask.unmasked(valueOld)
|
||||
const maskedUnmasked = mask.masked(unmasked)
|
||||
|
||||
if (unmasked === '' && 'data' in e && e.data != null) {
|
||||
// empty state and something like `space` pressed
|
||||
value = e.data
|
||||
} else if (
|
||||
maskedUnmasked.startsWith(valueOld) ||
|
||||
mask.completed(unmasked)
|
||||
) {
|
||||
} else if (unmasked !== mask.unmasked(masked)) {
|
||||
value = unmasked
|
||||
}
|
||||
}
|
||||
|
||||
@@ -802,6 +802,71 @@ describe('#-# eager mask', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('+1 (#) #-# eager mask', () => {
|
||||
beforeAll(() => {
|
||||
input = prepareInput({ mask: '+1 (#) #-#', eager: true })
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await user.clear(input)
|
||||
})
|
||||
|
||||
test('input 1', async () => {
|
||||
await user.type(input, '1')
|
||||
expect(input).toHaveValue('+1 (1) ')
|
||||
})
|
||||
|
||||
test('input 12', async () => {
|
||||
await user.type(input, '12')
|
||||
expect(input).toHaveValue('+1 (1) 2-')
|
||||
})
|
||||
|
||||
test('input 123', async () => {
|
||||
await user.type(input, '123')
|
||||
expect(input).toHaveValue('+1 (1) 2-3')
|
||||
})
|
||||
|
||||
test('input 123', async () => {
|
||||
await user.type(input, '123')
|
||||
expect(input).toHaveValue('+1 (1) 2-3')
|
||||
})
|
||||
|
||||
test('input 2', async () => {
|
||||
await user.type(input, '2')
|
||||
expect(input).toHaveValue('+1 (2) ')
|
||||
})
|
||||
|
||||
test('input 234', async () => {
|
||||
await user.type(input, '234')
|
||||
expect(input).toHaveValue('+1 (2) 3-4')
|
||||
})
|
||||
|
||||
test('input 2{ArrowLeft}3', async () => {
|
||||
await user.type(input, '2{ArrowLeft}3')
|
||||
expect(input).toHaveValue('+1 (2) 3-')
|
||||
})
|
||||
|
||||
test('input 234{backspace}', async () => {
|
||||
await user.type(input, '234{backspace}')
|
||||
expect(input).toHaveValue('+1 (2) 3-')
|
||||
})
|
||||
|
||||
test('input 234{backspace}×2', async () => {
|
||||
await user.type(input, '234{backspace}{backspace}')
|
||||
expect(input).toHaveValue('+1 (2) 3-')
|
||||
})
|
||||
|
||||
test('input 234{backspace}×3', async () => {
|
||||
await user.type(input, '234{backspace}{backspace}{backspace}')
|
||||
expect(input).toHaveValue('+1 (2) ')
|
||||
})
|
||||
|
||||
test('input 234{backspace}×4', async () => {
|
||||
await user.type(input, '234{backspace}{backspace}{backspace}{backspace}')
|
||||
expect(input).toHaveValue('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#-#--# mask', () => {
|
||||
beforeAll(() => {
|
||||
input = prepareInput({ mask: '#-#--#' })
|
||||
@@ -1104,6 +1169,11 @@ describe('12## eager mask', () => {
|
||||
expect(input).toHaveValue('123')
|
||||
})
|
||||
|
||||
test('input 11', async () => {
|
||||
await user.type(input, '11')
|
||||
expect(input).toHaveValue('1211')
|
||||
})
|
||||
|
||||
test('input 12', async () => {
|
||||
await user.type(input, '12')
|
||||
expect(input).toHaveValue('1212')
|
||||
@@ -1578,6 +1648,16 @@ describe('IP eager mask', () => {
|
||||
await user.type(input, '123.456.789.0123')
|
||||
expect(input).toHaveValue('123.456.789.012')
|
||||
})
|
||||
|
||||
test('input 12.3{ArrowLeft}a', async () => {
|
||||
await user.type(input, '12.3{ArrowLeft}a')
|
||||
expect(input).toHaveValue('12.3')
|
||||
})
|
||||
|
||||
test('input 12.3{ArrowLeft}1', async () => {
|
||||
await user.type(input, '12.3{ArrowLeft}1')
|
||||
expect(input).toHaveValue('12.13')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Repeated mask', () => {
|
||||
|
||||
Reference in New Issue
Block a user