diff --git a/frontend/__tests__/components/modals/configure-update-strategy-modal.spec.tsx b/frontend/__tests__/components/modals/configure-update-strategy-modal.spec.tsx new file mode 100644 index 00000000000..aba3e03edd3 --- /dev/null +++ b/frontend/__tests__/components/modals/configure-update-strategy-modal.spec.tsx @@ -0,0 +1,37 @@ +import * as React from 'react'; +import { shallow, ShallowWrapper } from 'enzyme'; +import Spy = jasmine.Spy; + +import { ConfigureUpdateStrategy, ConfigureUpdateStrategyProps } from '@console/internal/components/modals/configure-update-strategy-modal'; +import { RadioInput } from '@console/internal/components/radio'; + +describe(ConfigureUpdateStrategy.displayName, () => { + let wrapper: ShallowWrapper; + let onChangeStrategyType: Spy; + let onChangeMaxSurge: Spy; + let onChangeMaxUnavailable: Spy; + + beforeEach(() => { + onChangeStrategyType = jasmine.createSpy('onChangeStrategyType'); + onChangeMaxSurge = jasmine.createSpy('onChangeMaxSurge'); + onChangeMaxUnavailable = jasmine.createSpy('onChangeMaxUnavailable'); + + wrapper = shallow(); + }); + + it('renders two choices for different update strategy types', () => { + expect(wrapper.find(RadioInput).at(0).props().value).toEqual('RollingUpdate'); + expect(wrapper.find(RadioInput).at(1).props().value).toEqual('Recreate'); + expect(wrapper.find(RadioInput).at(1).props().checked).toBe(true); + }); + + it('is a controlled component', () => { + wrapper.find(RadioInput).at(0).dive().find('input[type="radio"]').simulate('change', {target: {value: 'RollingUpdate'}}); + wrapper.find('#input-max-unavailable').simulate('change', {target: {value: '25%'}}); + wrapper.find('#input-max-surge').simulate('change', {target: {value: '50%'}}); + + expect(onChangeStrategyType.calls.argsFor(0)[0]).toEqual('RollingUpdate'); + expect(onChangeMaxUnavailable.calls.argsFor(0)[0]).toEqual('25%'); + expect(onChangeMaxSurge.calls.argsFor(0)[0]).toEqual('50%'); + }); +}); diff --git a/frontend/public/components/modals/configure-update-strategy-modal.tsx b/frontend/public/components/modals/configure-update-strategy-modal.tsx index 3c7148cff65..9ed43bee8ad 100644 --- a/frontend/public/components/modals/configure-update-strategy-modal.tsx +++ b/frontend/public/components/modals/configure-update-strategy-modal.tsx @@ -53,7 +53,8 @@ export const ConfigureUpdateStrategy: React.FC = ( props.onChangeMaxUnavailable(e.target.value)} aria-describedby="input-max-unavailable-help" /> { props.replicas && of { pluralize(props.replicas, 'pod')} @@ -77,7 +78,8 @@ export const ConfigureUpdateStrategy: React.FC = ( type="text" className="pf-c-form-control" id="input-max-surge" - defaultValue={props.maxSurge as string} + value={props.maxSurge} + onChange={e => props.onChangeMaxSurge(e.target.value)} aria-describedby="input-max-surge-help" /> greater than { pluralize(props.replicas, 'pod')} diff --git a/frontend/public/components/operator-lifecycle-manager/descriptors/spec/index.tsx b/frontend/public/components/operator-lifecycle-manager/descriptors/spec/index.tsx index ae2dc108a4e..b9af52f82fc 100644 --- a/frontend/public/components/operator-lifecycle-manager/descriptors/spec/index.tsx +++ b/frontend/public/components/operator-lifecycle-manager/descriptors/spec/index.tsx @@ -89,6 +89,8 @@ const Secret: React.FC = (props) => { ; }; +const UpdateStrategy: React.FC = (props) =>
{_.get(props.value, 'type', 'None')}
; + const capabilityComponents = ImmutableMap>() .set(SpecCapability.podCount, PodCount) .set(SpecCapability.endpointList, Endpoints) @@ -98,7 +100,8 @@ const capabilityComponents = ImmutableMap { if (_.isEmpty(specCapability)) {