Skip to content

Commit

Permalink
test(directive): add delete e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Meister committed May 26, 2021
1 parent b0d608d commit c80d567
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
91 changes: 91 additions & 0 deletions projects/ngx-mask-lib/src/test/delete.cy-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { mount } from '@jscutlery/cypress-angular/mount';
import { CypressTestMaskComponent, CypressTestMaskModule } from './utils/cypress-test-component.component';

describe('Directive: Mask (Delete)', () => {
it('should delete character in input', () => {
mount(CypressTestMaskComponent, {
inputs: {
mask: '00/00/0000',
},
imports: [CypressTestMaskModule],
});

const inputTarget = cy.get('input');
inputTarget.type('12/34/5678');
inputTarget.focus();
inputTarget.setSelectionRange(1, 1);
inputTarget.type('{backspace}');

inputTarget.should('have.value', '23/45/678');
});

it('should not delete special mask character', () => {
mount(CypressTestMaskComponent, {
inputs: {
mask: '00/00/0000',
},
imports: [CypressTestMaskModule],
});

const inputTarget = cy.get('input');
inputTarget.type('12/34/5678');
inputTarget.setSelectionRange(3, 3);
inputTarget.type('{backspace}');

inputTarget.should('have.value', '12/34/5678');
inputTarget.should('have.prop', 'selectionStart', 2);
});

it('should delete secure character', () => {
mount(CypressTestMaskComponent, {
inputs: {
mask: 'XXX/X0/0000',
hiddenInput: true,
},
imports: [CypressTestMaskModule],
});

const inputTarget = cy.get('input');
inputTarget.type('123/45/6789');
inputTarget.setSelectionRange(3, 3);
inputTarget.type('{backspace}');

inputTarget.should('have.value', '***/*6/789');
inputTarget.should('have.prop', 'selectionStart', 2);
});

it('should not delete prefix', () => {
mount(CypressTestMaskComponent, {
inputs: {
mask: '(00) 00',
prefix: '+1 ',
},
imports: [CypressTestMaskModule],
});

const inputTarget = cy.get('input');
inputTarget.type('1234');
inputTarget.setSelectionRange(3, 3);
inputTarget.type('{backspace}');

inputTarget.should('have.value', '+1 (12) 34');
inputTarget.should('have.prop', 'selectionStart', 3);
});

it('should delete selection', () => {
mount(CypressTestMaskComponent, {
inputs: {
mask: '000 000 000',
},
imports: [CypressTestMaskModule],
});

const inputTarget = cy.get('input');
inputTarget.type('123456789');
inputTarget.setSelectionRange(4, 7);
inputTarget.type('{backspace}');

inputTarget.should('have.value', '123 789');
inputTarget.should('have.prop', 'selectionStart', 3);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Component, Input, NgModule } from '@angular/core';
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';

import { CommonModule } from '@angular/common';
import { NgxMaskModule } from 'ngx-mask';

@Component({
selector: 'mask-cypress-test-mask',
template: ` <input id="maska" [formControl]="form" [mask]="mask" [hiddenInput]="hiddenInput" [prefix]="prefix" /> `,
})
export class CypressTestMaskComponent {
@Input() public mask!: string | null;
@Input() public hiddenInput: boolean = false;
@Input() public prefix: string = '';
public form: FormControl = new FormControl('');
}

@NgModule({
imports: [CommonModule, ReactiveFormsModule, FormsModule, NgxMaskModule.forRoot()],
declarations: [CypressTestMaskComponent],
exports: [CypressTestMaskComponent],
})
export class CypressTestMaskModule {}

0 comments on commit c80d567

Please sign in to comment.