|
5 | 5 | import React from 'react'; |
6 | 6 | import { expect } from 'chai'; |
7 | 7 | import { shallow, render, mount } from 'enzyme'; |
| 8 | +import './jsdom'; |
8 | 9 | import { |
9 | 10 | TextApp1, |
10 | 11 | TextApp2, |
@@ -32,3 +33,41 @@ describe('Test to create a basic form', () => { |
32 | 33 | }); |
33 | 34 |
|
34 | 35 | }); |
| 36 | + |
| 37 | + |
| 38 | +describe('Test Form change validation', () => { |
| 39 | + it('The form is validated correctly', () => { |
| 40 | + const app = mount( |
| 41 | + <TextApp2 |
| 42 | + classNames={{ |
| 43 | + static: 'form-control', |
| 44 | + success: 'valid-success', |
| 45 | + error: 'valid-error', |
| 46 | + }} |
| 47 | + values={{ email: '' }} |
| 48 | + />, |
| 49 | + ); |
| 50 | + const input = app.find('input'); |
| 51 | + const label = app.find('label'); |
| 52 | + |
| 53 | + expect(label.text()).to.be.empty; |
| 54 | + // trigger |
| 55 | + input.simulate('change'); |
| 56 | + expect(input.props().className).to.contains('valid-error'); |
| 57 | + expect(label.text()).to.equal('Can not be empty!'); |
| 58 | + expect(app.node.formValues.email).to.be.empty; |
| 59 | + // Change |
| 60 | + input.get(0).value = 'example#example.com'; |
| 61 | + input.simulate('change'); |
| 62 | + expect(label.text()).to.equal('Please enter a valid email address.'); |
| 63 | + expect(app.node.isAllValid).to.equal(false); |
| 64 | + // Change |
| 65 | + input.get(0).value = 'example@example.com'; |
| 66 | + input.simulate('change'); |
| 67 | + expect(label.text()).to.be.empty; |
| 68 | + expect(input.props().className).to.contains('valid-success'); |
| 69 | + expect(app.node.isAllValid).to.equal(true); |
| 70 | + }); |
| 71 | + |
| 72 | + // it('Initialize the parameter by function', () => {}); |
| 73 | +}); |
0 commit comments