Add support for launching job templates from the templates list (#277)

Add support for launching job templates from the templates list
This commit is contained in:
Michael Abashian
2019-06-20 15:21:57 -04:00
committed by GitHub
parent cd672baa13
commit cb50cdce0d
6 changed files with 210 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ import {
import styled from 'styled-components';
import VerticalSeparator from '@components/VerticalSeparator';
import LaunchButton from '@components/LaunchButton';
import { toTitleCase } from '@util/strings';
const DataListCell = styled(PFDataListCell)`
@@ -17,6 +18,7 @@ const DataListCell = styled(PFDataListCell)`
align-items: center;
@media screen and (min-width: 768px) {
padding-bottom: 0;
justify-content: ${props => (props.lastcolumn ? 'flex-end' : 'inherit')};
}
`;
@@ -27,6 +29,7 @@ class TemplateListItem extends Component {
isSelected,
onSelect,
} = this.props;
const canLaunch = template.summary_fields.user_capabilities.start;
return (
<DataListItem
@@ -49,7 +52,14 @@ class TemplateListItem extends Component {
</Link>
</span>
</DataListCell>,
<DataListCell key="type">{toTitleCase(template.type)}</DataListCell>
<DataListCell key="type">{toTitleCase(template.type)}</DataListCell>,
<DataListCell lastcolumn="true" key="launch">
{canLaunch && template.type === 'job_template' && (
<LaunchButton
templateId={template.id}
/>
)}
</DataListCell>
]}
/>
</DataListItemRow>

View File

@@ -5,14 +5,36 @@ import { mountWithContexts } from '@testUtils/enzymeHelpers';
import TemplatesListItem from './TemplateListItem';
describe('<TemplatesListItem />', () => {
test('initially render successfully', () => {
mountWithContexts(<TemplatesListItem
test('launch button shown to users with start capabilities', () => {
const wrapper = mountWithContexts(<TemplatesListItem
template={{
id: 1,
name: 'Template 1',
url: '/templates/job_template/1',
type: 'job_template'
type: 'job_template',
summary_fields: {
user_capabilities: {
start: true
}
}
}}
/>);
expect(wrapper.find('LaunchButton').exists()).toBeTruthy();
});
test('launch button hidden from users without start capabilities', () => {
const wrapper = mountWithContexts(<TemplatesListItem
template={{
id: 1,
name: 'Template 1',
url: '/templates/job_template/1',
type: 'job_template',
summary_fields: {
user_capabilities: {
start: false
}
}
}}
/>);
expect(wrapper.find('LaunchButton').exists()).toBeFalsy();
});
});