Skip to content

Commit

Permalink
fix(multilineInput): add invalidmessage prop (#1414)
Browse files Browse the repository at this point in the history
* fix(multilineInput): add invalidmessage prop

* fix(multilineInput): add ut
  • Loading branch information
rosalie-liu authored Jan 29, 2020
1 parent ce06413 commit 5605adf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import * as _ from 'underscore';

import {UUID} from '../../utils/UUID';
import {Label} from '../input/Label';
import {AddInput} from './AddInput';
Expand All @@ -14,6 +15,8 @@ export interface IMultilineInputOwnProps {
id?: string;
placeholder?: string;
title?: string;
invalidMessage?: string;
validate?: (value: string) => boolean;
}

export interface IMultilineInputStateProps {
Expand Down Expand Up @@ -97,6 +100,8 @@ export class MultilineInput extends React.Component<IMultilineInputProps, any> {
placeholder={this.props.placeholder}
value=""
onBlur={(newValue: string) => this.handleAddInputChange(newValue)}
labelProps={{invalidMessage: this.props.invalidMessage}}
validate={this.props.validate}
>
<Label classes={this.props.values && this.props.values.length === 0 ? ['first-label'] : []}>
{this.props.title}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import {mount, ReactWrapper, shallow} from 'enzyme';
// tslint:disable-next-line:no-unused-variable
import * as React from 'react';
import {Store} from 'redux';

import {IReactVaporState} from '../../../ReactVapor';
import {TestUtils} from '../../../utils/tests/TestUtils';
import {ILabelProps} from '../../input';
import {validateInputValue} from '../../input/InputActions';
import {AddInput} from '../AddInput';
import {DeletableInput} from '../DeletableInput';
import {IMultilineInputProps, IMultilineInputValue, MultilineInput} from '../MultilineInput';
Expand All @@ -15,6 +21,8 @@ describe('MultilineInput', () => {
});

describe('<MultilineInput />', () => {
let store: Store<IReactVaporState>;

let multilineInput: ReactWrapper<IMultilineInputProps, any>;
const valueId = 'an-id';
const valueValue = 'a-value';
Expand All @@ -25,6 +33,7 @@ describe('MultilineInput', () => {
const aNewValue = 'a-new-value';

beforeEach(() => {
store = TestUtils.buildStore();
multilineInput = mount(<MultilineInput />, {attachTo: document.getElementById('App')});
});

Expand All @@ -38,7 +47,18 @@ describe('MultilineInput', () => {
expect(innerAddInput.length).toBe(1);
});

it('should render no DeletableInput when no values are specifie.', () => {
it('should be able to render an invalid message if the input is not valid', () => {
store.dispatch(validateInputValue(valueId, false));

const invalidMessage = '📦';
const inputLabel = shallow(<MultilineInput invalidMessage={invalidMessage} />)
.find('AddInput')
.prop('labelProps') as ILabelProps;

expect(inputLabel.invalidMessage).toBe(invalidMessage);
});

it('should render no DeletableInput when no values are specified.', () => {
const innerDeleteInput = multilineInput.find(DeletableInput);

expect(innerDeleteInput.length).toBe(0);
Expand Down

0 comments on commit 5605adf

Please sign in to comment.