From 03bb045cca26245804592602c7ff0c6e477f3b8d Mon Sep 17 00:00:00 2001 From: Grégoire Aubert Date: Tue, 16 Jul 2019 13:12:16 +0200 Subject: SC-704 Extract more components (#1921) * Extract BoxedGroupAccordion * Extract Select and SearchSelect * Extract Validation controls * Update sonar-ui-common --- .../js/components/controls/BoxedGroupAccordion.tsx | 78 ---- .../src/main/js/components/controls/DateInput.tsx | 2 +- .../main/js/components/controls/SearchSelect.tsx | 154 ------- .../src/main/js/components/controls/Select.tsx | 59 --- .../main/js/components/controls/ValidationForm.tsx | 72 --- .../js/components/controls/ValidationInput.tsx | 60 --- .../js/components/controls/ValidationModal.tsx | 83 ---- .../__tests__/BoxedGroupAccordion-test.tsx | 52 --- .../controls/__tests__/SearchSelect-test.tsx | 50 --- .../controls/__tests__/ValidationForm-test.tsx | 47 -- .../controls/__tests__/ValidationInput-test.tsx | 73 ---- .../controls/__tests__/ValidationModal-test.tsx | 47 -- .../BoxedGroupAccordion-test.tsx.snap | 26 -- .../__snapshots__/SearchSelect-test.tsx.snap | 17 - .../__snapshots__/ValidationForm-test.tsx.snap | 19 - .../__snapshots__/ValidationInput-test.tsx.snap | 104 ----- .../__snapshots__/ValidationModal-test.tsx.snap | 21 - .../main/js/components/controls/react-select.css | 483 --------------------- 18 files changed, 1 insertion(+), 1446 deletions(-) delete mode 100644 server/sonar-web/src/main/js/components/controls/BoxedGroupAccordion.tsx delete mode 100644 server/sonar-web/src/main/js/components/controls/SearchSelect.tsx delete mode 100644 server/sonar-web/src/main/js/components/controls/Select.tsx delete mode 100644 server/sonar-web/src/main/js/components/controls/ValidationForm.tsx delete mode 100644 server/sonar-web/src/main/js/components/controls/ValidationInput.tsx delete mode 100644 server/sonar-web/src/main/js/components/controls/ValidationModal.tsx delete mode 100644 server/sonar-web/src/main/js/components/controls/__tests__/BoxedGroupAccordion-test.tsx delete mode 100644 server/sonar-web/src/main/js/components/controls/__tests__/SearchSelect-test.tsx delete mode 100644 server/sonar-web/src/main/js/components/controls/__tests__/ValidationForm-test.tsx delete mode 100644 server/sonar-web/src/main/js/components/controls/__tests__/ValidationInput-test.tsx delete mode 100644 server/sonar-web/src/main/js/components/controls/__tests__/ValidationModal-test.tsx delete mode 100644 server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/BoxedGroupAccordion-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/SearchSelect-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/ValidationForm-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/ValidationInput-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/ValidationModal-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/components/controls/react-select.css (limited to 'server/sonar-web/src/main/js/components/controls') diff --git a/server/sonar-web/src/main/js/components/controls/BoxedGroupAccordion.tsx b/server/sonar-web/src/main/js/components/controls/BoxedGroupAccordion.tsx deleted file mode 100644 index 8e1a4cd99ad..00000000000 --- a/server/sonar-web/src/main/js/components/controls/BoxedGroupAccordion.tsx +++ /dev/null @@ -1,78 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import * as classNames from 'classnames'; -import OpenCloseIcon from 'sonar-ui-common/components/icons/OpenCloseIcon'; - -interface Props { - children: React.ReactNode; - className?: string; - data?: string; - onClick: (data?: string) => void; - open: boolean; - renderHeader?: () => React.ReactNode; - title: React.ReactNode; -} - -interface State { - hoveringInner: boolean; -} - -export default class BoxedGroupAccordion extends React.PureComponent { - state: State = { hoveringInner: false }; - - handleClick = () => { - this.props.onClick(this.props.data); - }; - - onDetailEnter = () => { - this.setState({ hoveringInner: true }); - }; - - onDetailLeave = () => { - this.setState({ hoveringInner: false }); - }; - - render() { - const { className, open, renderHeader, title } = this.props; - return ( -
-
- - - {title} - - {renderHeader && renderHeader()} -
- {open && ( -
- {this.props.children} -
- )} -
- ); - } -} diff --git a/server/sonar-web/src/main/js/components/controls/DateInput.tsx b/server/sonar-web/src/main/js/components/controls/DateInput.tsx index dcb777c8573..da7918c9be3 100644 --- a/server/sonar-web/src/main/js/components/controls/DateInput.tsx +++ b/server/sonar-web/src/main/js/components/controls/DateInput.tsx @@ -37,7 +37,7 @@ import { import { ButtonIcon, ClearButton } from 'sonar-ui-common/components/controls/buttons'; import OutsideClickHandler from 'sonar-ui-common/components/controls/OutsideClickHandler'; import { lazyLoad } from 'sonar-ui-common/components/lazyLoad'; -import Select from './Select'; +import Select from 'sonar-ui-common/components/controls/Select'; import './DayPicker.css'; import './styles.css'; diff --git a/server/sonar-web/src/main/js/components/controls/SearchSelect.tsx b/server/sonar-web/src/main/js/components/controls/SearchSelect.tsx deleted file mode 100644 index c4b681624e6..00000000000 --- a/server/sonar-web/src/main/js/components/controls/SearchSelect.tsx +++ /dev/null @@ -1,154 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import { debounce } from 'lodash'; -import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n'; -import Select, { Creatable } from './Select'; - -interface Props { - autofocus?: boolean; - canCreate?: boolean; - className?: string; - clearable?: boolean; - defaultOptions?: T[]; - minimumQueryLength?: number; - multi?: boolean; - onSearch: (query: string) => Promise; - onSelect?: (option: T) => void; - onMultiSelect?: (options: T[]) => void; - promptTextCreator?: (label: string) => string; - renderOption?: (option: T) => JSX.Element; - resetOnBlur?: boolean; - value?: T | T[]; -} - -interface State { - loading: boolean; - options: T[]; - query: string; -} - -export default class SearchSelect extends React.PureComponent< - Props, - State -> { - mounted = false; - - constructor(props: Props) { - super(props); - this.state = { loading: false, options: props.defaultOptions || [], query: '' }; - this.handleSearch = debounce(this.handleSearch, 250); - } - - componentDidMount() { - this.mounted = true; - } - - componentWillUnmount() { - this.mounted = false; - } - - get autofocus() { - return this.props.autofocus !== undefined ? this.props.autofocus : true; - } - - get minimumQueryLength() { - return this.props.minimumQueryLength !== undefined ? this.props.minimumQueryLength : 2; - } - - get resetOnBlur() { - return this.props.resetOnBlur !== undefined ? this.props.resetOnBlur : true; - } - - handleSearch = (query: string) => { - // Ignore the result if the query changed - const currentQuery = query; - this.props.onSearch(currentQuery).then( - options => { - if (this.mounted) { - this.setState(state => ({ - loading: false, - options: state.query === currentQuery ? options : state.options - })); - } - }, - () => { - if (this.mounted) { - this.setState({ loading: false }); - } - } - ); - }; - - handleChange = (option: T | T[]) => { - if (Array.isArray(option)) { - if (this.props.onMultiSelect) { - this.props.onMultiSelect(option); - } - } else if (this.props.onSelect) { - this.props.onSelect(option); - } - }; - - handleInputChange = (query: string) => { - if (query.length >= this.minimumQueryLength) { - this.setState({ loading: true, query }); - this.handleSearch(query); - } else { - // `onInputChange` is called with an empty string after a user selects a value - // in this case we shouldn't reset `options`, because it also resets select value :( - const options = (query.length === 0 && this.props.defaultOptions) || []; - this.setState({ options, query }); - } - }; - - // disable internal filtering - handleFilterOption = () => true; - - render() { - const Component = this.props.canCreate ? Creatable : Select; - return ( - - ); - } -} diff --git a/server/sonar-web/src/main/js/components/controls/Select.tsx b/server/sonar-web/src/main/js/components/controls/Select.tsx deleted file mode 100644 index 2086716ac0f..00000000000 --- a/server/sonar-web/src/main/js/components/controls/Select.tsx +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import { ReactSelectProps, ReactCreatableSelectProps, ReactAsyncSelectProps } from 'react-select'; -import { ClearButton } from 'sonar-ui-common/components/controls/buttons'; -import { lazyLoad } from 'sonar-ui-common/components/lazyLoad'; -import './react-select.css'; - -const ReactSelectLib = import('react-select'); -const ReactSelect = lazyLoad(() => ReactSelectLib); -const ReactCreatable = lazyLoad(() => ReactSelectLib.then(lib => ({ default: lib.Creatable }))); -const ReactAsync = lazyLoad(() => ReactSelectLib.then(lib => ({ default: lib.Async }))); - -function renderInput() { - return ; -} - -interface WithInnerRef { - innerRef?: (element: React.Component) => void; -} - -export default function Select({ innerRef, ...props }: WithInnerRef & ReactSelectProps) { - // TODO try to define good defaults, if any - // ReactSelect doesn't declare `clearRenderer` prop - const ReactSelectAny = ReactSelect as any; - // hide the "x" icon when select is empty - const clearable = props.clearable ? Boolean(props.value) : false; - return ( - - ); -} - -export function Creatable(props: ReactCreatableSelectProps) { - // ReactSelect doesn't declare `clearRenderer` prop - const ReactCreatableAny = ReactCreatable as any; - return ; -} - -// TODO figure out why `ref` prop is incompatible -export function AsyncSelect(props: ReactAsyncSelectProps & { ref?: any }) { - return ; -} diff --git a/server/sonar-web/src/main/js/components/controls/ValidationForm.tsx b/server/sonar-web/src/main/js/components/controls/ValidationForm.tsx deleted file mode 100644 index 9f2ca8217ee..00000000000 --- a/server/sonar-web/src/main/js/components/controls/ValidationForm.tsx +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import { FormikActions, FormikProps, Formik } from 'formik'; - -export type ChildrenProps = T.Omit, 'handleSubmit'>; - -interface Props { - children: (props: ChildrenProps) => React.ReactNode; - initialValues: V; - isInitialValid?: boolean; - onSubmit: (data: V) => Promise; - validate: (data: V) => { [P in keyof V]?: string } | Promise<{ [P in keyof V]?: string }>; -} - -export default class ValidationForm extends React.Component> { - mounted = false; - - componentDidMount() { - this.mounted = true; - } - - componentWillUnmount() { - this.mounted = false; - } - - handleSubmit = (data: V, { setSubmitting }: FormikActions) => { - const result = this.props.onSubmit(data); - const stopSubmitting = () => { - if (this.mounted) { - setSubmitting(false); - } - }; - - if (result) { - result.then(stopSubmitting, stopSubmitting); - } else { - stopSubmitting(); - } - }; - - render() { - return ( - - initialValues={this.props.initialValues} - isInitialValid={this.props.isInitialValid} - onSubmit={this.handleSubmit} - validate={this.props.validate}> - {({ handleSubmit, ...props }) => ( -
{this.props.children(props)}
- )} - - ); - } -} diff --git a/server/sonar-web/src/main/js/components/controls/ValidationInput.tsx b/server/sonar-web/src/main/js/components/controls/ValidationInput.tsx deleted file mode 100644 index 3d7a78104a1..00000000000 --- a/server/sonar-web/src/main/js/components/controls/ValidationInput.tsx +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import AlertErrorIcon from 'sonar-ui-common/components/icons/AlertErrorIcon'; -import AlertSuccessIcon from 'sonar-ui-common/components/icons/AlertSuccessIcon'; -import HelpTooltip from 'sonar-ui-common/components/controls/HelpTooltip'; - -interface Props { - description?: string; - children: React.ReactNode; - className?: string; - error: string | undefined; - help?: string; - id: string; - isInvalid: boolean; - isValid: boolean; - label: React.ReactNode; - required?: boolean; -} - -export default function ValidationInput(props: Props) { - const hasError = props.isInvalid && props.error !== undefined; - return ( -
- -
- {props.children} - {props.isInvalid && } - {hasError && ( - {props.error} - )} - {props.isValid && } -
- {props.description &&
{props.description}
} -
- ); -} diff --git a/server/sonar-web/src/main/js/components/controls/ValidationModal.tsx b/server/sonar-web/src/main/js/components/controls/ValidationModal.tsx deleted file mode 100644 index 841b3592be1..00000000000 --- a/server/sonar-web/src/main/js/components/controls/ValidationModal.tsx +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import { translate } from 'sonar-ui-common/helpers/l10n'; -import { SubmitButton, ResetButtonLink } from 'sonar-ui-common/components/controls/buttons'; -import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner'; -import Modal, { ModalProps } from 'sonar-ui-common/components/controls/Modal'; -import ValidationForm, { ChildrenProps } from './ValidationForm'; - -interface Props extends ModalProps { - children: (props: ChildrenProps) => React.ReactNode; - confirmButtonText: string; - header: string; - initialValues: V; - isDestructive?: boolean; - isInitialValid?: boolean; - onClose: () => void; - onSubmit: (data: V) => Promise; - validate: (data: V) => { [P in keyof V]?: string }; -} - -export default class ValidationModal extends React.PureComponent> { - handleSubmit = (data: V) => { - return this.props.onSubmit(data).then(() => { - this.props.onClose(); - }); - }; - - render() { - return ( - - - {props => ( - <> -
-

{this.props.header}

-
- -
{this.props.children(props)}
- -
- - - {this.props.confirmButtonText} - - - {translate('cancel')} - -
- - )} -
-
- ); - } -} diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/BoxedGroupAccordion-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/BoxedGroupAccordion-test.tsx deleted file mode 100644 index b77c4c5bbcd..00000000000 --- a/server/sonar-web/src/main/js/components/controls/__tests__/BoxedGroupAccordion-test.tsx +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import { shallow } from 'enzyme'; -import { click } from 'sonar-ui-common/helpers/testUtils'; -import BoxedGroupAccordion from '../BoxedGroupAccordion'; - -it('should render correctly', () => { - expect(getWrapper()).toMatchSnapshot(); -}); - -it('should show the inner content after a click', () => { - const onClick = jest.fn(); - const wrapper = getWrapper({ onClick }); - click(wrapper.find('.boxed-group-header')); - - expect(onClick).lastCalledWith('foo'); - wrapper.setProps({ open: true }); - - expect(wrapper.find('.boxed-group-inner').exists()).toBeTruthy(); -}); - -function getWrapper(props = {}) { - return shallow( - {}} - open={false} - renderHeader={() =>
header content
} - title="Foo" - {...props}> -
inner content
-
- ); -} diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/SearchSelect-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/SearchSelect-test.tsx deleted file mode 100644 index 340e30c16f2..00000000000 --- a/server/sonar-web/src/main/js/components/controls/__tests__/SearchSelect-test.tsx +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import { shallow } from 'enzyme'; -import SearchSelect from '../SearchSelect'; - -jest.mock('lodash', () => { - const lodash = require.requireActual('lodash'); - lodash.debounce = jest.fn(fn => fn); - return lodash; -}); - -it('should render Select', () => { - expect(shallow()).toMatchSnapshot(); -}); - -it('should call onSelect', () => { - const onSelect = jest.fn(); - const wrapper = shallow(); - wrapper.prop('onChange')({ value: 'foo' }); - expect(onSelect).lastCalledWith({ value: 'foo' }); -}); - -it('should call onSearch', () => { - const onSearch = jest.fn().mockReturnValue(Promise.resolve([])); - const wrapper = shallow( - - ); - wrapper.prop('onInputChange')('f'); - expect(onSearch).not.toHaveBeenCalled(); - wrapper.prop('onInputChange')('foo'); - expect(onSearch).lastCalledWith('foo'); -}); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/ValidationForm-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/ValidationForm-test.tsx deleted file mode 100644 index 3760b02ca81..00000000000 --- a/server/sonar-web/src/main/js/components/controls/__tests__/ValidationForm-test.tsx +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import { shallow } from 'enzyme'; -import ValidationForm from '../ValidationForm'; - -it('should render and submit', async () => { - const render = jest.fn(); - const onSubmit = jest.fn(); - const setSubmitting = jest.fn(); - const wrapper = shallow( - - {render} - - ); - expect(wrapper).toMatchSnapshot(); - wrapper.dive(); - expect(render).toBeCalledWith( - expect.objectContaining({ dirty: false, errors: {}, values: { foo: 'bar' } }) - ); - - wrapper.prop('onSubmit')({ foo: 'bar' }, { setSubmitting }); - expect(setSubmitting).toBeCalledWith(false); - - onSubmit.mockResolvedValue(undefined).mockClear(); - setSubmitting.mockClear(); - wrapper.prop('onSubmit')({ foo: 'bar' }, { setSubmitting }); - await new Promise(setImmediate); - expect(setSubmitting).toBeCalledWith(false); -}); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/ValidationInput-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/ValidationInput-test.tsx deleted file mode 100644 index 280d52bec6c..00000000000 --- a/server/sonar-web/src/main/js/components/controls/__tests__/ValidationInput-test.tsx +++ /dev/null @@ -1,73 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import { shallow } from 'enzyme'; -import ValidationInput from '../ValidationInput'; - -it('should render', () => { - expect( - shallow( - -
- - ) - ).toMatchSnapshot(); -}); - -it('should render with error', () => { - expect( - shallow( - -
- - ) - ).toMatchSnapshot(); -}); - -it('should render when valid', () => { - expect( - shallow( - -
- - ) - ).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/ValidationModal-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/ValidationModal-test.tsx deleted file mode 100644 index f4af7f14294..00000000000 --- a/server/sonar-web/src/main/js/components/controls/__tests__/ValidationModal-test.tsx +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import { shallow } from 'enzyme'; -import ValidationModal from '../ValidationModal'; - -it('should render correctly', () => { - const wrapper = shallow( - - confirmButtonText="confirm" - header="title" - initialValues={{ field: 'foo' }} - isDestructive={true} - isInitialValid={true} - onClose={jest.fn()} - onSubmit={jest.fn()} - validate={jest.fn()}> - {props => ( - - )} - - ); - expect(wrapper).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/BoxedGroupAccordion-test.tsx.snap b/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/BoxedGroupAccordion-test.tsx.snap deleted file mode 100644 index 0c7b74b79d9..00000000000 --- a/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/BoxedGroupAccordion-test.tsx.snap +++ /dev/null @@ -1,26 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -
-
- - - Foo - -
- header content -
-
-
-`; diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/SearchSelect-test.tsx.snap b/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/SearchSelect-test.tsx.snap deleted file mode 100644 index 792343f1a73..00000000000 --- a/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/SearchSelect-test.tsx.snap +++ /dev/null @@ -1,17 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render Select 1`] = ` -