forked from stolostron/console
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ACM-9268 KubeVirt hosted cluster creation wizard (stolostron#3274)
* ACM-9268 KubeVirt hosted cluster creation wizard Signed-off-by: zlayne <[email protected]> * fix lint errors Signed-off-by: zlayne <[email protected]> * fix credentials test Signed-off-by: zlayne <[email protected]> * Update controlDataKubeVirt test Signed-off-by: zlayne <[email protected]> * fix lint Signed-off-by: zlayne <[email protected]> * add tests Signed-off-by: zlayne <[email protected]> --------- Signed-off-by: zlayne <[email protected]>
- Loading branch information
Showing
22 changed files
with
1,864 additions
and
102 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
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
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
76 changes: 76 additions & 0 deletions
76
frontend/src/components/TemplateEditor/controls/ControlPanelBoolean.js
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,76 @@ | ||
/* Copyright Contributors to the Open Cluster Management project */ | ||
'use strict' | ||
|
||
import { Radio } from '@patternfly/react-core' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import ControlPanelFormGroup from './ControlPanelFormGroup' | ||
|
||
class ControlPanelBoolean extends React.Component { | ||
static propTypes = { | ||
control: PropTypes.object, | ||
controlId: PropTypes.string, | ||
handleChange: PropTypes.func, | ||
i18n: PropTypes.func, | ||
} | ||
|
||
constructor(props) { | ||
super(props) | ||
this.state = {} | ||
} | ||
|
||
setControlRef = (control, ref) => { | ||
control.ref = ref | ||
} | ||
|
||
render() { | ||
const { controlId, control, controlData, handleChange, i18n } = this.props | ||
const { tip, isTrue } = control | ||
|
||
const onChange = () => { | ||
control.isTrue = !isTrue | ||
control.active = !isTrue | ||
handleChange() | ||
} | ||
|
||
return ( | ||
<React.Fragment> | ||
<div | ||
style={{ flexDirection: 'column', alignItems: 'flex-start' }} | ||
className="creation-view-controls-number" | ||
ref={this.setControlRef.bind(this, control)} | ||
> | ||
<ControlPanelFormGroup i18n={i18n} controlId={controlId} control={control} controlData={controlData}> | ||
<div style={{ display: 'flex' }}> | ||
<div style={{ marginRight: '40px' }}> | ||
<Radio | ||
aria-label={`${controlId}-true`} | ||
id={`${controlId}-true`} | ||
label={'True'} | ||
isChecked={isTrue} | ||
onChange={onChange} | ||
data-testid={`radio-${controlId}`} | ||
style={{ marginRight: 0 }} | ||
/> | ||
</div> | ||
<div> | ||
<Radio | ||
aria-label={`${controlId}-false`} | ||
id={`${controlId}-false`} | ||
label={'False'} | ||
isChecked={!isTrue} | ||
onChange={onChange} | ||
data-testid={`radio-${controlId}`} | ||
style={{ marginRight: 0 }} | ||
/> | ||
</div> | ||
</div> | ||
</ControlPanelFormGroup> | ||
</div> | ||
<div style={{ fontSize: '14px', fontWeight: 'normal' }}>{tip}</div> | ||
</React.Fragment> | ||
) | ||
} | ||
} | ||
|
||
export default ControlPanelBoolean |
43 changes: 43 additions & 0 deletions
43
frontend/src/components/TemplateEditor/controls/ControlPanelBoolean.test.js
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,43 @@ | ||
/* Copyright Contributors to the Open Cluster Management project */ | ||
'use strict' | ||
|
||
import { render } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import ControlPanelBoolean from './ControlPanelBoolean' | ||
|
||
import i18n from 'i18next' | ||
|
||
const t = i18n.t.bind(i18n) | ||
|
||
export const control = { | ||
active: false, | ||
name: 'Name', | ||
tooltip: 'Application name', | ||
controlData: [], | ||
id: 'boolean', | ||
type: 'boolean', | ||
isTrue: false, | ||
} | ||
|
||
const fn = jest.fn() | ||
|
||
describe('ControlPanelBoolean component', () => { | ||
it('renders as expected', () => { | ||
const Component = () => { | ||
return <ControlPanelBoolean key={'key'} control={control} controlId={'controlId'} handleChange={fn} i18n={t} /> | ||
} | ||
|
||
const { getByTestId, asFragment, rerender } = render(<Component />) | ||
expect(asFragment()).toMatchSnapshot() | ||
|
||
userEvent.click(getByTestId('controlId-true')) | ||
expect(control.active).toBe(true) | ||
expect(control.isTrue).toBe(true) | ||
|
||
// control.active = 'true' | ||
rerender(<Component />) | ||
userEvent.click(getByTestId('controlId-false')) | ||
expect(control.active).toBe(false) | ||
expect(control.isTrue).toBe(false) | ||
}) | ||
}) |
Oops, something went wrong.