|
@@ -1,35 +1,34 @@
|
|
|
import React from 'react';
|
|
import React from 'react';
|
|
|
-import Form, { InputWithPlaceHolder } from '../components/Form';
|
|
|
|
|
|
|
+import Form from '../components/Form';
|
|
|
import { mount, shallow } from 'enzyme';
|
|
import { mount, shallow } from 'enzyme';
|
|
|
|
|
|
|
|
describe('Place holder', () => {
|
|
describe('Place holder', () => {
|
|
|
const colorTest = (inputWindow, color) => {
|
|
const colorTest = (inputWindow, color) => {
|
|
|
- expect(inputWindow.find('input').prop('style')).toHaveProperty(
|
|
|
|
|
- 'color',
|
|
|
|
|
- color
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ expect(inputWindow.find('input').at(0).prop('style'))
|
|
|
|
|
+ .toHaveProperty('color', color);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
it('Placeholder shows on loading and color is grey', () => {
|
|
it('Placeholder shows on loading and color is grey', () => {
|
|
|
- const inputWindow = shallow(<InputWithPlaceHolder placeHolder="test" />);
|
|
|
|
|
- expect(inputWindow.find('input').prop('value')).toBe('test');
|
|
|
|
|
|
|
+ const inputWindow = shallow(<Form />);
|
|
|
|
|
+ expect(inputWindow.find('input').at(0).prop('value')).toBeTruthy();
|
|
|
colorTest(inputWindow, 'grey');
|
|
colorTest(inputWindow, 'grey');
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('Clicking on the input field hides the placeholder', () => {
|
|
it('Clicking on the input field hides the placeholder', () => {
|
|
|
- const inputWindow = shallow(<InputWithPlaceHolder placeHolder="test" />);
|
|
|
|
|
- const inputField = inputWindow.find('input');
|
|
|
|
|
|
|
+ const inputWindow = mount(<Form />);
|
|
|
|
|
+ const inputField = inputWindow.find('input').at(0);
|
|
|
inputField.simulate('focus');
|
|
inputField.simulate('focus');
|
|
|
- expect(inputWindow.find('input').prop('value')).toBe('');
|
|
|
|
|
|
|
+ expect(inputField.prop('value')).toBe('');
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('Typing in the input area shows the text with color black, \
|
|
it('Typing in the input area shows the text with color black, \
|
|
|
deleting the text shows placeholder again on blur', () => {
|
|
deleting the text shows placeholder again on blur', () => {
|
|
|
- const inputWindow = mount(<InputWithPlaceHolder placeHolder="test" />);
|
|
|
|
|
- const inputField = inputWindow.find('input');
|
|
|
|
|
- inputField.simulate('focus');
|
|
|
|
|
- const newValue = 'Entered new value';
|
|
|
|
|
- inputField.simulate('change', { target: { value: newValue } });
|
|
|
|
|
|
|
+ const inputWindow = mount(<Form />);
|
|
|
|
|
+ const inputField = inputWindow.find('input').at(0);
|
|
|
|
|
+ inputField.simulate('focus');
|
|
|
|
|
+ const newValue = 'Entered new value'
|
|
|
|
|
+ inputField.node.value = newValue;
|
|
|
|
|
+ inputField.simulate('change', inputField);
|
|
|
expect(inputField.prop('value')).toBe(newValue);
|
|
expect(inputField.prop('value')).toBe(newValue);
|
|
|
colorTest(inputWindow, 'black');
|
|
colorTest(inputWindow, 'black');
|
|
|
inputField.simulate('change', { target: { value: '' } });
|
|
inputField.simulate('change', { target: { value: '' } });
|
|
@@ -38,3 +37,13 @@ describe('Place holder', () => {
|
|
|
colorTest(inputWindow, 'grey');
|
|
colorTest(inputWindow, 'grey');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+describe('Validation', () => {
|
|
|
|
|
+ it('Exceeding the max length shows show a warning', () => {
|
|
|
|
|
+ const inputWindow = mount(<InputWithPlaceHolder maxLength={8}/>)
|
|
|
|
|
+ const inputField = inputWindow.find('input')
|
|
|
|
|
+ const newValue = 'test test'
|
|
|
|
|
+ inputField.simulate('change', { target: { value: newValue } });
|
|
|
|
|
+ expect(inputWindow.find('.warning').text()).toTruthy()
|
|
|
|
|
+ })
|
|
|
|
|
+})
|