Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kit): Number incorrectly shift caret for 1st time insertion into textfield with initial value #1792

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,78 @@ import {TestInput} from '../utils';
describe('Number | With initial value', () => {
let maskitoOptions!: MaskitoOptions;

beforeEach(() => {
const prefix = '$';
const postfix = ' kg';

const numberOptions = maskitoNumberOptionsGenerator({
prefix,
postfix,
thousandSeparator: ' ',
describe('with prefix & postfix', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests inside this describe were not changed (just a new tabulation)

beforeEach(() => {
const prefix = '$';
const postfix = ' kg';

const numberOptions = maskitoNumberOptionsGenerator({
prefix,
postfix,
thousandSeparator: ' ',
});

maskitoOptions = {
...numberOptions,
plugins: [
...numberOptions.plugins,
maskitoCaretGuard((value) => [
prefix.length,
value.length - postfix.length,
]),
],
};
});

maskitoOptions = {
...numberOptions,
plugins: [
...numberOptions.plugins,
maskitoCaretGuard((value) => [
prefix.length,
value.length - postfix.length,
]),
],
};
});
it('$6 432 kg => Select all + Backspace => $| kg', () => {
cy.mount(TestInput, {
componentProperties: {maskitoOptions, initialValue: '$6 432 kg'},
});

it('$6 432 kg => Select all + Backspace => $| kg', () => {
cy.mount(TestInput, {
componentProperties: {maskitoOptions, initialValue: '$6 432 kg'},
cy.get('input')
.type('{selectAll}{backspace}')
.should('have.value', '$ kg')
.should('have.prop', 'selectionStart', 1)
.should('have.prop', 'selectionEnd', 1);
});

cy.get('input')
.type('{selectAll}{backspace}')
.should('have.value', '$ kg')
.should('have.prop', 'selectionStart', 1)
.should('have.prop', 'selectionEnd', 1);
it('$6 4|32 kg => Delete => $64|2 kg', () => {
cy.mount(TestInput, {
componentProperties: {maskitoOptions, initialValue: '$6 432 kg'},
});

cy.get('input')
.focus()
.type('{moveToEnd}')
.should('have.prop', 'selectionStart', '$6 432'.length)
.should('have.prop', 'selectionEnd', '$6 432'.length)
.type('{leftArrow}'.repeat(2))
.should('have.prop', 'selectionStart', '$6 4'.length)
.should('have.prop', 'selectionEnd', '$6 4'.length)
.type('{del}')
.should('have.value', '$642 kg')
.should('have.prop', 'selectionStart', '$64'.length)
.should('have.prop', 'selectionEnd', '$64'.length);
});
});

it('$6 4|32 kg => Delete => $64|2 kg', () => {
it('123 45|6 789 => Type 0 (the 1st time input event) => 1 234 50|6 789', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New test starts here

cy.mount(TestInput, {
componentProperties: {maskitoOptions, initialValue: '$6 432 kg'},
componentProperties: {
maskitoOptions: maskitoNumberOptionsGenerator({
thousandSeparator: ' ',
}),
initialValue: '123 456 789',
},
});

cy.get('input')
.focus()
.type('{moveToEnd}')
.should('have.prop', 'selectionStart', '$6 432'.length)
.should('have.prop', 'selectionEnd', '$6 432'.length)
.type('{leftArrow}'.repeat(2))
.should('have.prop', 'selectionStart', '$6 4'.length)
.should('have.prop', 'selectionEnd', '$6 4'.length)
.type('{del}')
.should('have.value', '$642 kg')
.should('have.prop', 'selectionStart', '$64'.length)
.should('have.prop', 'selectionEnd', '$64'.length);
.type('{moveToStart}')
.type('{rightArrow}'.repeat('123 45'.length))
.type('0')
.should('have.value', '1 234 506 789')
.should('have.prop', 'selectionStart', '1 234 50'.length)
.should('have.prop', 'selectionEnd', '1 234 50'.length);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,12 @@ describe('Number | Zero integer part', () => {

cy.get('@input')
.type('0,0005')
.type('{moveToStart}{rightArrow}{rightArrow}')
.type('{moveToStart}')
.type('{rightArrow}'.repeat('0,'.length))
.type('{backspace}')
.should('have.value', '00_005')
.should('have.prop', 'selectionStart', '00'.length)
.should('have.prop', 'selectionEnd', '00'.length)
.should('have.prop', 'selectionStart', '0'.length)
.should('have.prop', 'selectionEnd', '0'.length)
Comment on lines -194 to +196
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was invalid assertion

.blur()
.should('have.value', '5');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ export function createThousandSeparatorPostprocessor({
return char + formattedValuePart;
}

if (i <= initialFrom) {
if (i < initialFrom) {
from++;
}

if (i <= initialTo) {
if (i < initialTo) {
to++;
}

Expand Down
Loading