mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 02:19:58 -03:30
Removes code from serializer in favor to api call of Project.readDetails
Adds necessary tests.
This commit is contained in:
parent
46a7ca4dc3
commit
2daefcd94e
@ -196,12 +196,7 @@ class JobTemplateDetail extends Component {
|
||||
) : (
|
||||
renderMissingDataDetail(i18n._(t`Project`))
|
||||
)}
|
||||
{template.scm_branch && (
|
||||
<Detail
|
||||
label={i18n._(t`SCM Branch`)}
|
||||
value={template.scm_branch}
|
||||
/>
|
||||
)}
|
||||
<Detail label={i18n._(t`SCM Branch`)} value={template.scm_branch} />
|
||||
<Detail label={i18n._(t`Playbook`)} value={playbook} />
|
||||
<Detail label={i18n._(t`Forks`)} value={forks || '0'} />
|
||||
<Detail label={i18n._(t`Limit`)} value={limit} />
|
||||
|
||||
@ -161,6 +161,11 @@ describe('<JobTemplateEdit />', () => {
|
||||
JobTemplatesAPI.readInstanceGroups.mockReturnValue({
|
||||
data: { results: mockInstanceGroups },
|
||||
});
|
||||
ProjectsAPI.readDetail.mockReturnValue({
|
||||
id: 1,
|
||||
allow_override: true,
|
||||
name: 'foo',
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -28,7 +28,7 @@ import {
|
||||
ProjectLookup,
|
||||
MultiCredentialsLookup,
|
||||
} from '@components/Lookup';
|
||||
import { JobTemplatesAPI } from '@api';
|
||||
import { JobTemplatesAPI, ProjectsAPI } from '@api';
|
||||
import LabelSelect from './LabelSelect';
|
||||
import PlaybookSelect from './PlaybookSelect';
|
||||
|
||||
@ -81,16 +81,31 @@ class JobTemplateForm extends Component {
|
||||
this.loadRelatedInstanceGroups = this.loadRelatedInstanceGroups.bind(this);
|
||||
this.handleProjectUpdate = this.handleProjectUpdate.bind(this);
|
||||
this.setContentError = this.setContentError.bind(this);
|
||||
this.fetchProject = this.fetchProject.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { validateField } = this.props;
|
||||
this.setState({ contentError: null, hasContentLoading: true });
|
||||
// TODO: determine when LabelSelect has finished loading labels
|
||||
Promise.all([this.loadRelatedInstanceGroups()]).then(() => {
|
||||
this.setState({ hasContentLoading: false });
|
||||
validateField('project');
|
||||
});
|
||||
Promise.all([this.loadRelatedInstanceGroups(), this.fetchProject()]).then(
|
||||
() => {
|
||||
this.setState({ hasContentLoading: false });
|
||||
validateField('project');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async fetchProject() {
|
||||
const { project } = this.state;
|
||||
if (project && project.id) {
|
||||
try {
|
||||
const { data } = await ProjectsAPI.readDetail(project.id);
|
||||
this.setState({ project: data });
|
||||
} catch (err) {
|
||||
this.setState({ contentError: err });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async loadRelatedInstanceGroups() {
|
||||
|
||||
@ -27,7 +27,6 @@ describe('<JobTemplateForm />', () => {
|
||||
project: {
|
||||
id: 3,
|
||||
name: 'qux',
|
||||
allow_override: true,
|
||||
},
|
||||
labels: { results: [{ name: 'Sushi', id: 1 }, { name: 'Major', id: 2 }] },
|
||||
credentials: [
|
||||
@ -90,6 +89,11 @@ describe('<JobTemplateForm />', () => {
|
||||
ProjectsAPI.readPlaybooks.mockReturnValue({
|
||||
data: ['debug.yml'],
|
||||
});
|
||||
ProjectsAPI.readDetail.mockReturnValue({
|
||||
name: 'foo',
|
||||
id: 1,
|
||||
allow_override: true,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user