Skip to content

Commit

Permalink
fix keyboard decimal point counts
Browse files Browse the repository at this point in the history
related to #39
  • Loading branch information
changhuixu committed Jul 17, 2020
1 parent 07de8bf commit 961b057
Show file tree
Hide file tree
Showing 6 changed files with 15,209 additions and 12,898 deletions.
33 changes: 33 additions & 0 deletions cypress/integration/clipboard-events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,39 @@ describe('Copy & Paste', () => {
cy.get('#digit-only-decimal').should('have.value', '1234.81');
});

cy.get<HTMLInputElement>('#digit-only-decimal').then(($el) => {
$el[0].setSelectionRange(0, 7); // should select 1234.81

dt.setData('text/plain', '.4');
$el[0].dispatchEvent(pasteEvent);
cy.get('#digit-only-decimal').should('have.value', '.4');
});

cy.get('#digit-only-decimal').clear();
});

it.only('s', ()=> {
const dt = new DataTransfer();
dt.setData('text/plain', 'abc1.0s.1');
const pasteEvent = new ClipboardEvent('paste', {
clipboardData: dt,
bubbles: true,
cancelable: true,
});

cy.get('#digit-only-decimal').type('.4').should('have.value', '.4');

cy.get<HTMLInputElement>('#digit-only-decimal').then(($el) => {
$el[0].setSelectionRange(0, 2); // should select .4
cy.get('#digit-only-decimal').type('.2').should('have.value', '.2');
});

cy.get<HTMLInputElement>('#digit-only-decimal').then(($el) => {
dt.setData('text/plain', '.3');
$el[0].dispatchEvent(pasteEvent);
cy.get('#digit-only-decimal').should('have.value', '.23'); // the second decimal point should not be accepted
});

cy.get('#digit-only-decimal').clear();
});

Expand Down
18 changes: 18 additions & 0 deletions cypress/integration/keyboard-events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,22 @@ describe('Keyboard Typing', () => {
.should('have.value', '814.15')
.clear();
});

it('should correctly count decimal point when select input text', () => {
cy.get('#digit-only-decimal').type('1.35').should('have.value', '1.35');

cy.get<HTMLInputElement>('#digit-only-decimal').then(($el) => {
$el[0].setSelectionRange(0, 4); // should select 1.35
cy.get('#digit-only-decimal').type('.2').should('have.value', '.2');
});
});

it('should correctly count decimal point when select input text 2', () => {
cy.get('#dollar-amount').type('1.35').should('have.value', '1.35');

cy.get<HTMLInputElement>('#dollar-amount').then(($el) => {
$el[0].setSelectionRange(0, 4); // should select 1.35
cy.get('#dollar-amount').type('.2.5').should('have.value', '.25');
});
});
});
Loading

0 comments on commit 961b057

Please sign in to comment.