File size: 2,969 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
describe('controller basic form validation', () => {
  it('should validate the form and reset the form', () => {
    cy.visit('http://localhost:3000/controller/onSubmit');
    cy.get('#submit').click();

    cy.get('#TextField').contains('TextField Error');
    cy.get('#RadioGroup').contains('RadioGroup Error');
    cy.get('#Checkbox').contains('Checkbox Error');
    cy.get('#RadioGroup').contains('RadioGroup Error');
    cy.get('#Select').contains('Select Error');
    cy.get('#switch').contains('switch Error');

    cy.get('#input-checkbox input').click();
    cy.get('input[name="gender1"]').first().click();
    cy.get('#input-textField input').type('test');
    cy.get('#input-select > div > div').click();
    cy.get('.MuiPopover-root ul > li:first-child').click();
    cy.get('#input-switch input').click();
    cy.get('#input-ReactSelect > div').click();
    cy.get('#input-ReactSelect > div > div').eq(1).click();

    cy.get('.container > p').should('have.length', 0);
    cy.get('#renderCount').contains('9');
  });

  it.only('should validate the form with onBlur mode and reset the form', () => {
    cy.visit('http://localhost:3000/controller/onBlur');

    cy.get('p').should('have.length', 0);
    cy.get('#input-checkbox input').focus();
    cy.get('#input-checkbox input').blur();
    cy.get('#Checkbox').contains('Checkbox Error');

    cy.get('#input-textField input').focus();
    cy.get('#input-textField input').blur();
    cy.get('#TextField').contains('TextField Error');

    cy.get('#input-select > div > div').focus();
    cy.get('#input-select > div > div').blur();
    cy.get('#Select').contains('Select Error');

    cy.get('#input-switch input').focus();
    cy.get('#input-switch input').blur();
    cy.get('#switch').contains('switch Error');

    cy.get('#input-checkbox input').click();
    cy.get('#input-textField input').type('test');
    cy.get('#input-select > div > div').click();
    cy.get('.MuiPopover-root ul > li:first-child').click();
    cy.get('#input-switch input').click();
    cy.get('#input-switch input').blur();

    cy.get('p').should('have.length', 0);
    cy.get('#renderCount').contains('10');
  });

  it('should validate the form with onChange mode and reset the form', () => {
    cy.visit('http://localhost:3000/controller/onChange');

    cy.get('#input-checkbox input').click();
    cy.get('#input-checkbox input').click();
    cy.get('#Checkbox').contains('Checkbox Error');

    cy.get('#input-textField input').type('test');
    cy.get('#input-textField input').clear();
    cy.get('#TextField').contains('TextField Error');

    cy.get('#input-switch input').click();
    cy.get('#input-switch input').click();
    cy.get('#switch').contains('switch Error');

    cy.get('#input-checkbox input').click();
    cy.get('#input-textField input').type('test');
    cy.get('#input-switch input').click();

    cy.get('p').should('have.length', 0);
    cy.get('#renderCount').contains('8');
  });
});