Skip to content

Commit

Permalink
fix: fix adding unnecessary symbols in postfix-postprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Belokopytov committed Nov 23, 2024
1 parent 20fce01 commit eb34994
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {maskitoNumberOptionsGenerator} from '@maskito/kit';

import {TestInput} from '../utils';

describe('Number | [postfix]=" EUR" (no initial value & no caret guard)', () => {
beforeEach(() => {
cy.mount(TestInput, {
componentProperties: {
initialValue: '',
maskitoOptions: maskitoNumberOptionsGenerator({
postfix: ' EUR',
precision: 2,
}),
},
});
cy.get('input').focus().should('have.value', '').as('input');
});

it('Empty input => Paste "11.22 " => Textfield\'s value is "11.22 EUR"', () => {
cy.get('input')
.paste('11.22 ')
.should('have.value', '11.22 EUR')
.should('have.prop', 'selectionStart', '11.22 '.length)
.should('have.prop', 'selectionEnd', '11.22 '.length);
});

it('Empty input => Paste "11.22 " => Textfield\'s value is "11.22 EUR"', () => {
cy.get('input')
.paste('11.22 ')
.should('have.value', '11.22 EUR')
.should('have.prop', 'selectionStart', '11.22 '.length)
.should('have.prop', 'selectionEnd', '11.22 '.length);
});
});
1 change: 1 addition & 0 deletions projects/kit/src/lib/processors/postfix-postprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function maskitoPostfixPostprocessorGenerator(
'',
);
const postfixWasModified =
!value.endsWith(postfix) &&
initialElementState.selection[1] >= initialValueBeforePostfix.length;
const alreadyExistedValueBeforePostfix = findCommonBeginningSubstr(
initialValueBeforePostfix,
Expand Down

0 comments on commit eb34994

Please sign in to comment.