-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes cloning of recurring runs (#1712)
* Fixes cloning of recurring runs Simplifies NewRun a little Creates NewRunParameters component * Fixes all NewRun tests * All tests pass * Adds tests for NewRunParameters * Adds clone test to RecurringRunDetails * Clean up
- Loading branch information
1 parent
351f456
commit 66883b0
Showing
11 changed files
with
614 additions
and
1,379 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,55 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import NewRunParameters, { NewRunParametersProps } from './NewRunParameters'; | ||
|
||
describe('NewRunParameters', () => { | ||
it('shows parameters', () => { | ||
const props = { | ||
handleParamChange: jest.fn(), | ||
initialParams: [{ name: 'testParam', value: 'testVal' }], | ||
titleMessage: 'Specify parameters required by the pipeline', | ||
} as NewRunParametersProps; | ||
expect(shallow(<NewRunParameters {...props} />)).toMatchSnapshot(); | ||
}); | ||
|
||
it('does not display any text fields if there are parameters', () => { | ||
const props = { | ||
handleParamChange: jest.fn(), | ||
initialParams: [], | ||
titleMessage: 'This pipeline has no parameters', | ||
} as NewRunParametersProps; | ||
expect(shallow(<NewRunParameters {...props} />)).toMatchSnapshot(); | ||
}); | ||
|
||
it('fires handleParamChange callback on change', () => { | ||
const handleParamChange = jest.fn(); | ||
const props = { | ||
handleParamChange, | ||
initialParams: [ | ||
{ name: 'testParam1', value: 'testVal1' }, | ||
{ name: 'testParam2', value: 'testVal2' } | ||
], | ||
titleMessage: 'Specify parameters required by the pipeline', | ||
} as NewRunParametersProps; | ||
const tree = shallow(<NewRunParameters {...props} />); | ||
tree.find('#newRunPipelineParam1').simulate('change', { target: { value: 'test param value' } }); | ||
expect(handleParamChange).toHaveBeenCalledTimes(1); | ||
expect(handleParamChange).toHaveBeenLastCalledWith(1, 'test param value'); | ||
}); | ||
}); |
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,54 @@ | ||
/* | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import { commonCss } from '../Css'; | ||
import TextField from '@material-ui/core/TextField'; | ||
import { ApiParameter } from '../apis/pipeline'; | ||
|
||
export interface NewRunParametersProps { | ||
initialParams: ApiParameter[]; | ||
titleMessage: string; | ||
handleParamChange: (index: number, value: string) => void; | ||
} | ||
|
||
class NewRunParameters extends React.Component<NewRunParametersProps> { | ||
constructor(props: any) { | ||
super(props); | ||
} | ||
|
||
public render(): JSX.Element | null { | ||
const { handleParamChange, initialParams, titleMessage } = this.props; | ||
|
||
return ( | ||
<div> | ||
<div className={commonCss.header}>Run parameters</div> | ||
<div>{titleMessage}</div> | ||
{!!initialParams.length && ( | ||
<div> | ||
{initialParams.map((param, i) => | ||
<TextField id={`newRunPipelineParam${i}`} key={i} variant='outlined' | ||
label={param.name} value={param.value || ''} | ||
onChange={(ev) => handleParamChange(i, ev.target.value || '')} | ||
style={{ maxWidth: 600 }} className={commonCss.textField}/>)} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default NewRunParameters; |
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
45 changes: 45 additions & 0 deletions
45
frontend/src/components/__snapshots__/NewRunParameters.test.tsx.snap
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,45 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`NewRunParameters does not display any text fields if there are parameters 1`] = ` | ||
<div> | ||
<div | ||
className="header" | ||
> | ||
Run parameters | ||
</div> | ||
<div> | ||
This pipeline has no parameters | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`NewRunParameters shows parameters 1`] = ` | ||
<div> | ||
<div | ||
className="header" | ||
> | ||
Run parameters | ||
</div> | ||
<div> | ||
Specify parameters required by the pipeline | ||
</div> | ||
<div> | ||
<TextField | ||
className="textField" | ||
id="newRunPipelineParam0" | ||
key="0" | ||
label="testParam" | ||
onChange={[Function]} | ||
required={false} | ||
select={false} | ||
style={ | ||
Object { | ||
"maxWidth": 600, | ||
} | ||
} | ||
value="testVal" | ||
variant="outlined" | ||
/> | ||
</div> | ||
</div> | ||
`; |
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
Oops, something went wrong.