2019-09-08 15:05:53 +00:00
|
|
|
import React from 'react';
|
2019-09-12 10:58:55 +00:00
|
|
|
import { mount, shallow } from 'enzyme';
|
2019-09-08 15:05:53 +00:00
|
|
|
import PasswordInput from '.';
|
|
|
|
|
2019-09-11 12:38:43 +00:00
|
|
|
const basePasswordSettings = {
|
|
|
|
minLength: 6,
|
|
|
|
upperCase: false,
|
|
|
|
digits: false,
|
|
|
|
specSymbols: false
|
|
|
|
};
|
|
|
|
|
|
|
|
const baseProps = {
|
|
|
|
inputName: 'demoPasswordInput',
|
|
|
|
emailInputName: 'demoEmailInput',
|
|
|
|
inputValue: '',
|
|
|
|
clipActionResource: 'Copy e-mail and password',
|
|
|
|
clipEmailResource: 'E-mail: ',
|
|
|
|
clipPasswordResource: 'Password: ',
|
|
|
|
tooltipPasswordTitle: 'Password must contain:',
|
|
|
|
tooltipPasswordLength: 'from 6 to 30 characters',
|
|
|
|
tooltipPasswordDigits: 'digits',
|
|
|
|
tooltipPasswordCapital: 'capital letters',
|
|
|
|
tooltipPasswordSpecial: 'special characters (!@#$%^&*)',
|
|
|
|
generatorSpecial: '!@#$%^&*',
|
|
|
|
passwordSettings: basePasswordSettings,
|
|
|
|
isDisabled: false,
|
|
|
|
placeholder: 'password',
|
|
|
|
onChange: () => jest.fn(),
|
|
|
|
onValidateInput: () => jest.fn(),
|
|
|
|
onCopyToClipboard: () => jest.fn()
|
|
|
|
}
|
|
|
|
|
2019-09-08 15:08:21 +00:00
|
|
|
describe('<PasswordInput />', () => {
|
2019-09-08 15:05:53 +00:00
|
|
|
it('renders without error', () => {
|
2019-09-11 12:38:43 +00:00
|
|
|
const wrapper = mount(<PasswordInput {...baseProps} />);
|
2019-09-08 15:05:53 +00:00
|
|
|
|
|
|
|
expect(wrapper).toExist();
|
|
|
|
});
|
2019-09-11 12:38:43 +00:00
|
|
|
|
|
|
|
it('render password input', () => {
|
|
|
|
const wrapper = mount(<PasswordInput {...baseProps} />);
|
|
|
|
|
|
|
|
expect(wrapper.find('input').prop('type')).toEqual('password');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('have an HTML name', () => {
|
|
|
|
const wrapper = mount(<PasswordInput {...baseProps} />);
|
|
|
|
|
|
|
|
expect(wrapper.find('input').prop('name')).toEqual('demoPasswordInput');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('forward passed value', () => {
|
|
|
|
const wrapper = mount(<PasswordInput {...baseProps} inputValue='demo' />);
|
|
|
|
|
|
|
|
expect(wrapper.props().inputValue).toEqual('demo');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('call onChange when changing value', () => {
|
|
|
|
const onChange = jest.fn(event => {
|
|
|
|
expect(event.target.id).toEqual('demoPasswordInput');
|
|
|
|
expect(event.target.name).toEqual('demoPasswordInput');
|
|
|
|
expect(event.target.value).toEqual('demo');
|
|
|
|
});
|
|
|
|
|
|
|
|
const wrapper = mount(<PasswordInput {...baseProps} id="demoPasswordInput" name="demoPasswordInput" onChange={onChange} />);
|
|
|
|
|
|
|
|
const event = { target: { value: "demo" } };
|
|
|
|
|
|
|
|
wrapper.simulate('change', event);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('call onFocus when input is focused', () => {
|
|
|
|
const onFocus = jest.fn(event => {
|
|
|
|
expect(event.target.id).toEqual('demoPasswordInput');
|
|
|
|
expect(event.target.name).toEqual('demoPasswordInput');
|
|
|
|
});
|
|
|
|
|
|
|
|
const wrapper = mount(<PasswordInput {...baseProps} id="demoPasswordInput" name="demoPasswordInput" onFocus={onFocus} />);
|
|
|
|
|
|
|
|
wrapper.simulate('focus');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('call onBlur when input loses focus', () => {
|
|
|
|
const onBlur = jest.fn(event => {
|
|
|
|
expect(event.target.id).toEqual('demoPasswordInput');
|
|
|
|
expect(event.target.name).toEqual('demoPasswordInput');
|
|
|
|
});
|
|
|
|
|
|
|
|
const wrapper = mount(<PasswordInput {...baseProps} id="demoPasswordInput" name="demoPasswordInput" onBlur={onBlur} />);
|
|
|
|
|
|
|
|
wrapper.simulate('blur');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('disabled when isDisabled is passed', () => {
|
|
|
|
const wrapper = mount(<PasswordInput {...baseProps} isDisabled={true} />);
|
|
|
|
|
|
|
|
expect(wrapper.prop('isDisabled')).toEqual(true);
|
|
|
|
});
|
2019-09-12 10:58:55 +00:00
|
|
|
|
|
|
|
it('not re-render test', () => {
|
|
|
|
const wrapper = shallow(<PasswordInput {...baseProps} />).instance();
|
|
|
|
|
|
|
|
const shouldUpdate = wrapper.shouldComponentUpdate(wrapper.props, wrapper.state);
|
|
|
|
|
|
|
|
expect(shouldUpdate).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('re-render test', () => {
|
|
|
|
const wrapper = shallow(<PasswordInput {...baseProps} />).instance();
|
|
|
|
|
|
|
|
const shouldUpdate = wrapper.shouldComponentUpdate({
|
|
|
|
inputName: 'demoPasswordInput',
|
|
|
|
emailInputName: 'demoEmailInput',
|
|
|
|
inputValue: '',
|
|
|
|
clipActionResource: 'Copy e-mail and password',
|
|
|
|
clipEmailResource: 'E-mail: ',
|
|
|
|
clipPasswordResource: 'Password: ',
|
|
|
|
tooltipPasswordTitle: 'Password must contain:',
|
|
|
|
tooltipPasswordLength: 'from 6 to 30 characters',
|
|
|
|
tooltipPasswordDigits: 'digits',
|
|
|
|
tooltipPasswordCapital: 'capital letters',
|
|
|
|
tooltipPasswordSpecial: 'special characters (!@#$%^&*)',
|
|
|
|
generatorSpecial: '!@#$%^&*',
|
|
|
|
passwordSettings: {
|
|
|
|
minLength: 8,
|
|
|
|
upperCase: false,
|
|
|
|
digits: false,
|
|
|
|
specSymbols: false
|
|
|
|
},
|
|
|
|
isDisabled: false,
|
|
|
|
placeholder: 'password',
|
|
|
|
onChange: () => jest.fn(),
|
|
|
|
onValidateInput: () => jest.fn(),
|
|
|
|
onCopyToClipboard: () => jest.fn()
|
|
|
|
}, wrapper.state);
|
|
|
|
|
|
|
|
expect(shouldUpdate).toBe(true);
|
|
|
|
});
|
2019-10-23 12:24:51 +00:00
|
|
|
|
|
|
|
it('generate password with props: 10 , false , false , false', () => {
|
|
|
|
const newPasswordSettings = {
|
|
|
|
minLength: 10,
|
|
|
|
upperCase: false,
|
|
|
|
digits: false,
|
|
|
|
specSymbols: false
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = shallow(<PasswordInput {...baseProps} passwordSettings={newPasswordSettings} />);
|
|
|
|
const instance = wrapper.instance();
|
|
|
|
|
|
|
|
instance.onGeneratePassword();
|
|
|
|
|
|
|
|
expect(wrapper.state('type')).toBe('text');
|
|
|
|
expect(wrapper.state('progressWidth')).toBe(100);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('generate password with props: 10 , true , false , false', () => {
|
|
|
|
const newPasswordSettings = {
|
|
|
|
minLength: 10,
|
|
|
|
upperCase: true,
|
|
|
|
digits: false,
|
|
|
|
specSymbols: false
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = shallow(<PasswordInput {...baseProps} passwordSettings={newPasswordSettings} />);
|
|
|
|
const instance = wrapper.instance();
|
|
|
|
|
|
|
|
instance.onGeneratePassword();
|
|
|
|
|
|
|
|
expect(wrapper.state('type')).toBe('text');
|
|
|
|
expect(wrapper.state('progressWidth')).toBe(100);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('generate password with props: 10 , true , true , false', () => {
|
|
|
|
const newPasswordSettings = {
|
|
|
|
minLength: 10,
|
|
|
|
upperCase: true,
|
|
|
|
digits: true,
|
|
|
|
specSymbols: false
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = shallow(<PasswordInput {...baseProps} passwordSettings={newPasswordSettings} />);
|
|
|
|
const instance = wrapper.instance();
|
|
|
|
|
|
|
|
instance.onGeneratePassword();
|
|
|
|
|
|
|
|
expect(wrapper.state('type')).toBe('text');
|
|
|
|
expect(wrapper.state('progressWidth')).toBe(100);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('generate password with props: 10 , true , true , true', () => {
|
|
|
|
const newPasswordSettings = {
|
|
|
|
minLength: 10,
|
|
|
|
upperCase: true,
|
|
|
|
digits: true,
|
|
|
|
specSymbols: true
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = shallow(<PasswordInput {...baseProps} passwordSettings={newPasswordSettings} />);
|
|
|
|
const instance = wrapper.instance();
|
|
|
|
|
|
|
|
instance.onGeneratePassword();
|
|
|
|
|
|
|
|
expect(wrapper.state('type')).toBe('text');
|
|
|
|
expect(wrapper.state('progressWidth')).toBe(100);
|
|
|
|
});
|
2019-09-08 15:05:53 +00:00
|
|
|
});
|