generated from Tinkoff/angular-open-source-starter
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(demo-integrations): cypress CT for new
maskitoChangeEventPlugin
- Loading branch information
1 parent
55192a7
commit 623961e
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...mo-integrations/src/tests/component-testing/change-event-plugin/change-event-plugin.cy.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,62 @@ | ||
import type {MaskitoOptions} from '@maskito/core'; | ||
import {maskitoChangeEventPlugin} from '@maskito/core'; | ||
import {maskitoNumberOptionsGenerator} from '@maskito/kit'; | ||
import {createOutputSpy} from 'cypress/angular'; | ||
|
||
import {TestInput} from '../utils'; | ||
|
||
describe('maskitoChangeEventPlugin', () => { | ||
const numberMask = maskitoNumberOptionsGenerator({ | ||
thousandSeparator: ' ', | ||
decimalSeparator: '.', | ||
precision: 2, | ||
}); | ||
const maskitoOptions: MaskitoOptions = { | ||
...numberMask, | ||
plugins: [...numberMask.plugins, maskitoChangeEventPlugin()], | ||
}; | ||
|
||
beforeEach(() => { | ||
cy.mount(TestInput, { | ||
componentProperties: { | ||
maskitoOptions, | ||
change: createOutputSpy('changeEvent'), | ||
}, | ||
}); | ||
}); | ||
|
||
it('Enter only valid value (Maskito does not prevent any typed character) => only 1 change event on blur', () => { | ||
cy.get('input').type('123').should('have.value', '123'); | ||
cy.get('@changeEvent').should('not.be.called'); | ||
cy.get('input').blur(); | ||
cy.get('@changeEvent').should('have.callCount', 1); | ||
}); | ||
|
||
it('Enter valid value + pseudo decimal separator (Maskito replaces pseudo separator with valid one) => only 1 change event on blur', () => { | ||
cy.get('input').type('123,').should('have.value', '123.'); | ||
cy.get('@changeEvent').should('not.be.called'); | ||
cy.get('input').blur(); | ||
cy.get('@changeEvent').should('have.callCount', 1); | ||
}); | ||
|
||
it('Enter only decimal separator (Maskito pads it with zero) => only 1 change event on blur', () => { | ||
cy.get('input').type('.').should('have.value', '0.'); | ||
cy.get('@changeEvent').should('not.be.called'); | ||
cy.get('input').blur(); | ||
cy.get('@changeEvent').should('have.callCount', 1); | ||
}); | ||
|
||
it('Enter only invalid value (Maskito rejects all typed characters) => no change event', () => { | ||
cy.get('input').type('abc').should('have.value', ''); | ||
cy.get('@changeEvent').should('not.be.called'); | ||
cy.get('input').blur(); | ||
cy.get('@changeEvent').should('not.be.called'); | ||
}); | ||
|
||
it('Enter any value value and then erase it again => no change event', () => { | ||
cy.get('input').type('123').should('have.value', '123'); | ||
cy.get('@changeEvent').should('not.be.called'); | ||
cy.get('input').clear().blur(); | ||
cy.get('@changeEvent').should('not.be.called'); | ||
}); | ||
}); |
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