Update (js-) tests and snapshots for react-select 2 #13425

This commit is contained in:
Johannes Schill
2018-10-08 09:36:08 +02:00
parent 7e7c7fe64c
commit 2d65845bac
9 changed files with 134 additions and 140 deletions

View File

@@ -42,7 +42,6 @@ class DescriptionPicker extends Component<Props, any> {
onChange={onSelected} onChange={onSelected}
getOptionValue={i => i.value} getOptionValue={i => i.value}
getOptionLabel={i => i.label} getOptionLabel={i => i.label}
// menuIsOpen={true} // debug
/> />
</div> </div>
); );

View File

@@ -3,10 +3,12 @@ import renderer from 'react-test-renderer';
import PickerOption from './PickerOption'; import PickerOption from './PickerOption';
const model = { const model = {
onSelect: () => {}, cx: jest.fn(),
onFocus: () => {}, clearValue: jest.fn(),
isFocused: () => {}, onSelect: jest.fn(),
option: { getStyles: jest.fn(),
children: 'Model title',
data: {
title: 'Model title', title: 'Model title',
avatarUrl: 'url/to/avatar', avatarUrl: 'url/to/avatar',
label: 'User picker label', label: 'User picker label',

View File

@@ -2,15 +2,12 @@ import React from 'react';
import { components } from 'react-select'; import { components } from 'react-select';
import { OptionProps } from 'react-select/lib/components/Option'; import { OptionProps } from 'react-select/lib/components/Option';
export interface Props { // https://github.com/JedWatson/react-select/issues/3038
children: Element; interface ExtendedOptionProps extends OptionProps<any> {
isSelected: boolean;
data: any; data: any;
getStyles: any;
className?: string;
} }
export const PickerOption = (props: OptionProps<any>) => { export const PickerOption = (props: ExtendedOptionProps) => {
const { children, data } = props; const { children, data } = props;
return ( return (
<components.Option {...props}> <components.Option {...props}>

View File

@@ -80,7 +80,6 @@ export class TeamPicker extends Component<Props, State> {
noOptionsMessage={() => 'No teams found'} noOptionsMessage={() => 'No teams found'}
getOptionValue={i => i.id} getOptionValue={i => i.id}
getOptionLabel={i => i.label} getOptionLabel={i => i.label}
// menuIsOpen={true}
/> />
</div> </div>
); );

View File

@@ -36,7 +36,7 @@ export class UserPicker extends Component<Props, State> {
this.setState({ isLoading: true }); this.setState({ isLoading: true });
return backendSrv return backendSrv
.get(`/api/org/users?query=${query}&limit=1`) .get(`/api/org/users?query=${query}&limit=10`)
.then(result => { .then(result => {
return result.map(user => ({ return result.map(user => ({
id: user.userId, id: user.userId,
@@ -75,7 +75,6 @@ export class UserPicker extends Component<Props, State> {
noOptionsMessage={() => 'No users found'} noOptionsMessage={() => 'No users found'}
getOptionValue={i => i.id} getOptionValue={i => i.id}
getOptionLabel={i => i.label} getOptionLabel={i => i.label}
// menuIsOpen={true}
/> />
</div> </div>
); );

View File

@@ -1,17 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`PickerOption renders correctly 1`] = ` exports[`PickerOption renders correctly 1`] = `
<button <div>
className="user-picker-option__button btn btn-link class-for-user-picker" <div
onMouseDown={[Function]} className="description-picker-option__button btn btn-link width-19"
onMouseEnter={[Function]} >
onMouseMove={[Function]} <img
title="Model title" alt="User picker label"
> className="user-picker-option__avatar"
<img src="url/to/avatar"
alt="User picker label" />
className="user-picker-option__avatar" Model title
src="url/to/avatar" </div>
/> </div>
</button>
`; `;

View File

@@ -5,85 +5,86 @@ exports[`TeamPicker renders correctly 1`] = `
className="user-picker" className="user-picker"
> >
<div <div
className="Select gf-form-input gf-form-input--form-dropdown is-clearable is-loading is-searchable Select--single" className="css-0 gf-form-input gf-form-input--form-dropdown"
onKeyDown={[Function]}
> >
<div <div
className="Select-control" className="css-0 gf-form-select2__control"
onKeyDown={[Function]}
onMouseDown={[Function]} onMouseDown={[Function]}
onTouchEnd={[Function]} onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
> >
<div <div
className="Select-multi-value-wrapper" className="css-0 gf-form-select2__value-container"
id="react-select-2--value"
> >
<div <div
className="Select-placeholder" className="css-0 gf-form-select2__placeholder"
> >
Loading... Select a team
</div> </div>
<div <div
className="Select-input" className="css-0"
style={
Object {
"display": "inline-block",
}
}
> >
<input
aria-activedescendant="react-select-2--value"
aria-expanded="false"
aria-haspopup="false"
aria-owns=""
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
required={false}
role="combobox"
style={
Object {
"boxSizing": "content-box",
"width": "5px",
}
}
value=""
/>
<div <div
className="gf-form-select2__input"
style={ style={
Object { Object {
"height": 0, "display": "inline-block",
"left": 0,
"overflow": "scroll",
"position": "absolute",
"top": 0,
"visibility": "hidden",
"whiteSpace": "pre",
} }
} }
> >
<input
aria-autocomplete="list"
autoCapitalize="none"
autoComplete="off"
autoCorrect="off"
disabled={false}
id="react-select-2-input"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
spellCheck="false"
style={
Object {
"background": 0,
"border": 0,
"boxSizing": "content-box",
"color": "inherit",
"fontSize": "inherit",
"opacity": 1,
"outline": 0,
"padding": 0,
"width": "1px",
}
}
tabIndex="0"
type="text"
value=""
/>
<div
style={
Object {
"height": 0,
"left": 0,
"overflow": "scroll",
"position": "absolute",
"top": 0,
"visibility": "hidden",
"whiteSpace": "pre",
}
}
>
</div>
</div> </div>
</div> </div>
</div> </div>
<span <div
aria-hidden="true" className="css-0 gf-form-select2__indicators"
className="Select-loading-zone"
> >
<span <span
className="Select-loading" className="gf-form-select2__select-arrow "
/> />
</span> </div>
<span
className="Select-arrow-zone"
onMouseDown={[Function]}
>
<span
className="Select-arrow"
onMouseDown={[Function]}
/>
</span>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -5,85 +5,86 @@ exports[`UserPicker renders correctly 1`] = `
className="user-picker" className="user-picker"
> >
<div <div
className="Select gf-form-input gf-form-input--form-dropdown is-clearable is-loading is-searchable Select--single" className="css-0 gf-form-input gf-form-input--form-dropdown"
onKeyDown={[Function]}
> >
<div <div
className="Select-control" className="css-0 gf-form-select2__control"
onKeyDown={[Function]}
onMouseDown={[Function]} onMouseDown={[Function]}
onTouchEnd={[Function]} onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
> >
<div <div
className="Select-multi-value-wrapper" className="css-0 gf-form-select2__value-container"
id="react-select-2--value"
> >
<div <div
className="Select-placeholder" className="css-0 gf-form-select2__placeholder"
> >
Loading... Select user
</div> </div>
<div <div
className="Select-input" className="css-0"
style={
Object {
"display": "inline-block",
}
}
> >
<input
aria-activedescendant="react-select-2--value"
aria-expanded="false"
aria-haspopup="false"
aria-owns=""
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
required={false}
role="combobox"
style={
Object {
"boxSizing": "content-box",
"width": "5px",
}
}
value=""
/>
<div <div
className="gf-form-select2__input"
style={ style={
Object { Object {
"height": 0, "display": "inline-block",
"left": 0,
"overflow": "scroll",
"position": "absolute",
"top": 0,
"visibility": "hidden",
"whiteSpace": "pre",
} }
} }
> >
<input
aria-autocomplete="list"
autoCapitalize="none"
autoComplete="off"
autoCorrect="off"
disabled={false}
id="react-select-2-input"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
spellCheck="false"
style={
Object {
"background": 0,
"border": 0,
"boxSizing": "content-box",
"color": "inherit",
"fontSize": "inherit",
"opacity": 1,
"outline": 0,
"padding": 0,
"width": "1px",
}
}
tabIndex="0"
type="text"
value=""
/>
<div
style={
Object {
"height": 0,
"left": 0,
"overflow": "scroll",
"position": "absolute",
"top": 0,
"visibility": "hidden",
"whiteSpace": "pre",
}
}
>
</div>
</div> </div>
</div> </div>
</div> </div>
<span <div
aria-hidden="true" className="css-0 gf-form-select2__indicators"
className="Select-loading-zone"
> >
<span <span
className="Select-loading" className="gf-form-select2__select-arrow "
/> />
</span> </div>
<span
className="Select-arrow-zone"
onMouseDown={[Function]}
>
<span
className="Select-arrow"
onMouseDown={[Function]}
/>
</span>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -60,7 +60,6 @@ exports[`Render should render component 1`] = `
<UserPicker <UserPicker
className="width-30" className="width-30"
onSelected={[Function]} onSelected={[Function]}
value={null}
/> />
</div> </div>
</div> </div>
@@ -155,7 +154,6 @@ exports[`Render should render team members 1`] = `
<UserPicker <UserPicker
className="width-30" className="width-30"
onSelected={[Function]} onSelected={[Function]}
value={null}
/> />
</div> </div>
</div> </div>
@@ -376,7 +374,6 @@ exports[`Render should render team members when sync enabled 1`] = `
<UserPicker <UserPicker
className="width-30" className="width-30"
onSelected={[Function]} onSelected={[Function]}
value={null}
/> />
</div> </div>
</div> </div>