-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
166beae
commit a850df1
Showing
4 changed files
with
532 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<React.Fragment> | ||
<RadioFieldset {...integrationMethod} onChange={onChange(setSelectedIntegrationMethod)} value={selectedIntegrationMethod} legend='Integration' /> | ||
{ !isServiceMesh && <FormCollection collection={customProxyEndpoints} ItemComponent={TextInputGroup} legend='API gateway' /> } | ||
<RadioFieldset {...authenticationMethod} onChange={onChange(setSelectedAuthenticationMethod)} value={selectedAuthenticationMethod} legend='Authentication' /> | ||
<AuthenticationSettingsFieldset | ||
isServiceMesh={isServiceMesh} | ||
authenticationMethod={selectedAuthenticationMethod} | ||
{...authenticationSettings} | ||
/> | ||
{ !isServiceMesh && <React.Fragment> | ||
<RadioFieldset {...credentialsLocation} legend='Credentials Location' /> | ||
<FormCollection collection={security} ItemComponent={TextInputGroup} legend='Security' /> | ||
<FormFieldset id='fieldset-GatewayResponse'> | ||
<FormLegend>Gateway Response</FormLegend> | ||
{gatewayResponse.map(settings => ( | ||
<FormCollection key={settings.legend} collection={settings.collection} ItemComponent={TextInputGroup} legend={settings.legend} /> | ||
))} | ||
</FormFieldset> | ||
</React.Fragment> } | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
export { | ||
Form | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(<Form {...settings} />, elementId) | ||
|
||
export { | ||
initSettings | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(<Form {...props} />) | ||
|
||
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() | ||
}) |
Oops, something went wrong.