diff --git a/app/javascript/src/Settings/components/Form.jsx b/app/javascript/src/Settings/components/Form.jsx new file mode 100644 index 0000000000..3ff29e80d1 --- /dev/null +++ b/app/javascript/src/Settings/components/Form.jsx @@ -0,0 +1,58 @@ +// @flow + +import * as React from 'react' +import { useState } from 'react' +import { FormFieldset, FormLegend } from 'Form' +import { FormCollection, TextInputGroup, RadioFieldset } from 'Settings/components/Common' +import { AuthenticationSettingsFieldset } from 'Settings/components/AuthenticationSettingsFieldset' +import type { SettingsProps as Props } from 'Settings/types' + +const SERVICE_MESH_INTEGRATION = 'service_mesh_istio' +const PROXY_HOSTED_INTEGRATION = 'hosted' + +const Form = ({ + isProxyCustomUrlActive, + integrationMethod, + authenticationMethod, + proxyEndpoints, + authenticationSettings, + credentialsLocation, + security, + gatewayResponse +}: Props) => { + const [ selectedIntegrationMethod, setSelectedIntegrationMethod ] = useState(integrationMethod.value) + const [ selectedAuthenticationMethod, setSelectedAuthenticationMethod ] = useState(authenticationMethod.value) + const onChange = (setState) => (_checked, e) => setState(e.currentTarget.value) + const isServiceMesh = selectedIntegrationMethod === SERVICE_MESH_INTEGRATION + const isProxyHosted = selectedIntegrationMethod === PROXY_HOSTED_INTEGRATION + const isProxyUrlsReadOnly = !isProxyCustomUrlActive && isProxyHosted + const customProxyEndpoints = proxyEndpoints.map(endpoint => + ({ ...endpoint, readOnly: isProxyUrlsReadOnly, isDefaultValue: isProxyUrlsReadOnly })) + + return ( + + + { !isServiceMesh && } + + + { !isServiceMesh && + + + + Gateway Response + {gatewayResponse.map(settings => ( + + ))} + + } + + ) +} + +export { + Form +} diff --git a/app/javascript/src/Settings/index.jsx b/app/javascript/src/Settings/index.jsx new file mode 100644 index 0000000000..b5b1f1d842 --- /dev/null +++ b/app/javascript/src/Settings/index.jsx @@ -0,0 +1,21 @@ +// @flow + +import * as React from 'react' +import { createReactWrapper } from 'utilities/createReactWrapper' +import { Form } from 'Settings/components/Form' +import { SETTINGS_DEFAULT } from 'Settings/defaults' +import type { SettingsProps } from 'Settings/types' + +type Props = { + settings: SettingsProps, + elementId: string +} + +const initSettings = ({ + settings = SETTINGS_DEFAULT, + elementId +}: Props) => createReactWrapper(
, elementId) + +export { + initSettings +} diff --git a/spec/javascripts/Settings/components/Form.spec.jsx b/spec/javascripts/Settings/components/Form.spec.jsx new file mode 100644 index 0000000000..4dba25e04d --- /dev/null +++ b/spec/javascripts/Settings/components/Form.spec.jsx @@ -0,0 +1,29 @@ +import React from 'react' +import { shallow } from 'enzyme' +import { Form } from 'Settings/components/Form' +import { + SETTINGS_DEFAULT, + INTEGRATION_METHOD_DEFAULTS +} from 'Settings/defaults' + +function setup (customProps = {}) { + const props = { + ...SETTINGS_DEFAULT, + ...customProps + } + + const view = shallow() + + return { view, props } +} + +it('should render correctly', () => { + const { view } = setup() + expect(view).toMatchSnapshot() +}) + +it('should not render Auth Settings, Security, Credential Locations and API Gateway when Istio is selected', () => { + const customProps = { integrationMethod: {...INTEGRATION_METHOD_DEFAULTS, value: 'service_mesh_istio'} } + const { view } = setup(customProps) + expect(view).toMatchSnapshot() +}) diff --git a/spec/javascripts/Settings/components/__snapshots__/Form.spec.jsx.snap b/spec/javascripts/Settings/components/__snapshots__/Form.spec.jsx.snap new file mode 100644 index 0000000000..42bec4b42c --- /dev/null +++ b/spec/javascripts/Settings/components/__snapshots__/Form.spec.jsx.snap @@ -0,0 +1,424 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should not render Auth Settings, Security, Credential Locations and API Gateway when Istio is selected 1`] = ` + + + + + +`; + +exports[`should render correctly 1`] = ` + + + + + + + + + + Gateway Response + + + + + + + +`;