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.
refactor(demo-integrations): rewriting e2e tests to CT (tests for `pr…
…edicate` Maskito attribute) (#1100)
- Loading branch information
1 parent
3a33b17
commit 34d5353
Showing
4 changed files
with
109 additions
and
29 deletions.
There are no files selected for viewing
28 changes: 0 additions & 28 deletions
28
projects/demo-integrations/src/tests/angular/predicate.cy.ts
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
projects/demo-integrations/src/tests/component-testing/predicate/multi-test.component.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,54 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {FormsModule} from '@angular/forms'; | ||
import {MaskitoDirective} from '@maskito/angular'; | ||
import {MaskitoElementPredicate, MaskitoOptions} from '@maskito/core'; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'synchronous-test-input', | ||
imports: [MaskitoDirective, FormsModule], | ||
template: ` | ||
<div | ||
[maskito]="card.matches(':focus') ? cardMask : nameMask" | ||
[maskitoElement]="card.matches(':focus') ? cardPredicate : namePredicate" | ||
> | ||
<input | ||
#card | ||
[(ngModel)]="value.number" | ||
/> | ||
<input [(ngModel)]="value.name" /> | ||
</div> | ||
`, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class MultiTestInputComponent { | ||
value = { | ||
number: '', | ||
name: '', | ||
}; | ||
|
||
readonly cardMask: MaskitoOptions = { | ||
mask: [ | ||
...new Array(4).fill(/\d/), | ||
' ', | ||
...new Array(4).fill(/\d/), | ||
' ', | ||
...new Array(4).fill(/\d/), | ||
' ', | ||
...new Array(4).fill(/\d/), | ||
], | ||
}; | ||
|
||
readonly nameMask: MaskitoOptions = { | ||
mask: /^[a-zA-Z\s]+$/, | ||
postprocessors: [ | ||
({value, selection}) => ({value: value.toUpperCase(), selection}), | ||
], | ||
}; | ||
|
||
readonly cardPredicate: MaskitoElementPredicate = element => | ||
element.querySelectorAll('input')[0]; | ||
|
||
readonly namePredicate: MaskitoElementPredicate = element => | ||
element.querySelectorAll('input')[1]; | ||
} |
46 changes: 46 additions & 0 deletions
46
projects/demo-integrations/src/tests/component-testing/predicate/predicate.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,46 @@ | ||
import {MaskitoOptions} from '@maskito/core'; | ||
|
||
import {TestInput} from '../utils'; | ||
import {MultiTestInputComponent} from './multi-test.component'; | ||
|
||
describe('@maskito/angular | Predicate', () => { | ||
it('can detect run-time changes', () => { | ||
cy.mount(MultiTestInputComponent); | ||
cy.get('input').should('be.visible').first().as('card'); | ||
cy.get('input').should('be.visible').eq(1).as('name'); | ||
|
||
cy.get('@card') | ||
.focus() | ||
.type('12341234abcd12341234') | ||
.should('have.value', '1234 1234 1234 1234'); | ||
|
||
cy.get('@name').focus().type('12341234abcd12341234').should('have.value', 'ABCD'); | ||
}); | ||
|
||
it('supports asynchronous predicate', () => { | ||
const cardMask: MaskitoOptions = { | ||
mask: [ | ||
...new Array(4).fill(/\d/), | ||
' ', | ||
...new Array(4).fill(/\d/), | ||
' ', | ||
...new Array(4).fill(/\d/), | ||
' ', | ||
...new Array(4).fill(/\d/), | ||
], | ||
}; | ||
|
||
cy.mount(TestInput, { | ||
componentProperties: { | ||
maskitoOptions: cardMask, | ||
maskitoElementPredicate: async element => | ||
Promise.resolve(element as HTMLInputElement), | ||
}, | ||
}); | ||
cy.get('input').as('card'); | ||
cy.get('@card') | ||
.focus() | ||
.type('12341234abcd12341234') | ||
.should('have.value', '1234 1234 1234 1234'); | ||
}); | ||
}); |
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