diff --git a/CHANGELOG.md b/CHANGELOG.md index f13ba5185..4a41032b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [1791](https://github.com/microsoft/BotFramework-Emulator/pull/1791) - [1827](https://github.com/microsoft/BotFramework-Emulator/pull/1827) - [1828](https://github.com/microsoft/BotFramework-Emulator/pull/1828) + - [1832](https://github.com/microsoft/BotFramework-Emulator/pull/1832) ## v4.5.2 - 2019 - 07 - 17 ## Fixed diff --git a/packages/app/client/src/ui/editor/appSettingsEditor/appSettingsEditor.tsx b/packages/app/client/src/ui/editor/appSettingsEditor/appSettingsEditor.tsx index 57dbcdff4..711932434 100644 --- a/packages/app/client/src/ui/editor/appSettingsEditor/appSettingsEditor.tsx +++ b/packages/app/client/src/ui/editor/appSettingsEditor/appSettingsEditor.tsx @@ -63,6 +63,7 @@ function shallowEqual(x: any, y: any) { export class AppSettingsEditor extends React.Component { public state = {} as AppSettingsEditorState; + private pathToNgrokInputRef: HTMLInputElement; public static getDerivedStateFromProps( newProps: AppSettingsEditorProps, @@ -79,6 +80,12 @@ export class AppSettingsEditor extends React.Component { + this.pathToNgrokInputRef = ref; + }; } diff --git a/packages/sdk/ui-react/src/widget/textField/textField.spec.tsx b/packages/sdk/ui-react/src/widget/textField/textField.spec.tsx new file mode 100644 index 000000000..bbce0ad86 --- /dev/null +++ b/packages/sdk/ui-react/src/widget/textField/textField.spec.tsx @@ -0,0 +1,87 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. +// +// Microsoft Bot Framework: http://botframework.com +// +// Bot Framework Emulator Github: +// https://github.com/Microsoft/BotFramwork-Emulator +// +// Copyright (c) Microsoft Corporation +// All rights reserved. +// +// MIT License: +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import * as React from 'react'; +import { mount } from 'enzyme'; + +import { TextField } from './textField'; + +describe(' Component', () => { + it('should render without any errors', () => { + const wrapper = mount(); + const node = wrapper.find(TextField); + expect(node.html()).not.toBeFalsy(); + }); + + it('should call the inputRef prop to set the ref', () => { + const mockInputRef = jest.fn(() => null); + const wrapper = mount(); + const instance: any = wrapper.instance(); + const mockRef = {}; + instance.setInputRef({}); + + expect(mockInputRef).toHaveBeenCalledWith(mockRef); + }); + + it('should return a label node if there is a label', () => { + const wrapper = mount(); + const instance: any = wrapper.instance(); + const labelNode = instance.labelNode; + + expect(labelNode).toBeTruthy(); + }); + + it('should not return a label node if there is no label', () => { + const wrapper = mount(); + const instance: any = wrapper.instance(); + const labelNode = instance.labelNode; + + expect(labelNode).toBeNull(); + }); + + it('should return an error node if there is an error', () => { + const wrapper = mount(); + const instance: any = wrapper.instance(); + const errorNode = instance.errorNode; + + expect(errorNode).toBeTruthy(); + }); + + it('should not return an error node if there is no error node', () => { + const wrapper = mount(); + const instance: any = wrapper.instance(); + const errorNode = instance.errorNode; + + expect(errorNode).toBeNull(); + }); +}); diff --git a/packages/sdk/ui-react/src/widget/textField/textField.tsx b/packages/sdk/ui-react/src/widget/textField/textField.tsx index 570e8c006..86a20a509 100644 --- a/packages/sdk/ui-react/src/widget/textField/textField.tsx +++ b/packages/sdk/ui-react/src/widget/textField/textField.tsx @@ -42,7 +42,7 @@ export interface TextFieldProps extends InputHTMLAttributes { label?: string; errorMessage?: string; inputContainerClassName?: string; - inputRef?: React.Ref; + inputRef?: (ref: HTMLInputElement) => void; } export class TextField extends Component { @@ -58,7 +58,6 @@ export class TextField extends Component { const { inputContainerClassName = '', className = '', - label, errorMessage, children, inputRef, @@ -71,13 +70,20 @@ export class TextField extends Component { return (
{this.labelNode} - + {children} {this.errorNode}
); } + private setInputRef = (ref: HTMLInputElement): void => { + const { inputRef } = this.props; + if (inputRef) { + inputRef(ref); + } + }; + protected get labelNode(): ReactNode { const { label, required, disabled } = this.props; const className = required ? styles.requiredIndicator : '';