mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 00:38:45 -03:30
Merge pull request #6482 from AlexSCorey/5901-SupportForWFJTSurvey
Adds Survey Functionality to WFJT Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -75,7 +75,7 @@ class JobTemplates extends SchedulesMixin(
|
|||||||
return this.http.get(`${this.baseUrl}${id}/survey_spec/`);
|
return this.http.get(`${this.baseUrl}${id}/survey_spec/`);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSurvey(id, survey = null) {
|
updateSurvey(id, survey) {
|
||||||
return this.http.post(`${this.baseUrl}${id}/survey_spec/`, survey);
|
return this.http.post(`${this.baseUrl}${id}/survey_spec/`, survey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,21 @@ class WorkflowJobTemplates extends SchedulesMixin(NotificationsMixin(Base)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
readAccessList(id, params) {
|
readAccessList(id, params) {
|
||||||
return this.http.get(`${this.baseUrl}${id}/access_list/`, { params });
|
return this.http.get(`${this.baseUrl}${id}/access_list/`, {
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
readSurvey(id) {
|
||||||
|
return this.http.get(`${this.baseUrl}${id}/survey_spec/`);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSurvey(id, survey) {
|
||||||
|
return this.http.post(`${this.baseUrl}${id}/survey_spec/`, survey);
|
||||||
|
}
|
||||||
|
|
||||||
|
destroySurvey(id) {
|
||||||
|
return this.http.delete(`${this.baseUrl}${id}/survey_spec/`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import React, { useState, useEffect, useCallback } from 'react';
|
import React, { useState, useEffect, useCallback } from 'react';
|
||||||
import { Switch, Route } from 'react-router-dom';
|
import { Switch, Route, useParams } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { JobTemplatesAPI } from '@api';
|
import { JobTemplatesAPI, WorkflowJobTemplatesAPI } from '@api';
|
||||||
import ContentError from '@components/ContentError';
|
import ContentError from '@components/ContentError';
|
||||||
import AlertModal from '@components/AlertModal';
|
import AlertModal from '@components/AlertModal';
|
||||||
import ErrorDetail from '@components/ErrorDetail';
|
import ErrorDetail from '@components/ErrorDetail';
|
||||||
@@ -12,6 +12,7 @@ import { SurveyList, SurveyQuestionAdd, SurveyQuestionEdit } from './Survey';
|
|||||||
function TemplateSurvey({ template, i18n }) {
|
function TemplateSurvey({ template, i18n }) {
|
||||||
const [surveyEnabled, setSurveyEnabled] = useState(template.survey_enabled);
|
const [surveyEnabled, setSurveyEnabled] = useState(template.survey_enabled);
|
||||||
|
|
||||||
|
const { templateType } = useParams();
|
||||||
const {
|
const {
|
||||||
result: survey,
|
result: survey,
|
||||||
request: fetchSurvey,
|
request: fetchSurvey,
|
||||||
@@ -20,9 +21,12 @@ function TemplateSurvey({ template, i18n }) {
|
|||||||
setValue: setSurvey,
|
setValue: setSurvey,
|
||||||
} = useRequest(
|
} = useRequest(
|
||||||
useCallback(async () => {
|
useCallback(async () => {
|
||||||
const { data } = await JobTemplatesAPI.readSurvey(template.id);
|
const { data } =
|
||||||
|
templateType === 'workflow_job_template'
|
||||||
|
? await WorkflowJobTemplatesAPI.readSurvey(template.id)
|
||||||
|
: await JobTemplatesAPI.readSurvey(template.id);
|
||||||
return data;
|
return data;
|
||||||
}, [template.id])
|
}, [template.id, templateType])
|
||||||
);
|
);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchSurvey();
|
fetchSurvey();
|
||||||
@@ -31,10 +35,17 @@ function TemplateSurvey({ template, i18n }) {
|
|||||||
const { request: updateSurvey, error: updateError } = useRequest(
|
const { request: updateSurvey, error: updateError } = useRequest(
|
||||||
useCallback(
|
useCallback(
|
||||||
async updatedSurvey => {
|
async updatedSurvey => {
|
||||||
await JobTemplatesAPI.updateSurvey(template.id, updatedSurvey);
|
if (templateType === 'workflow_job_template') {
|
||||||
|
await WorkflowJobTemplatesAPI.updateSurvey(
|
||||||
|
template.id,
|
||||||
|
updatedSurvey
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await JobTemplatesAPI.updateSurvey(template.id, updatedSurvey);
|
||||||
|
}
|
||||||
setSurvey(updatedSurvey);
|
setSurvey(updatedSurvey);
|
||||||
},
|
},
|
||||||
[template.id, setSurvey]
|
[template.id, setSurvey, templateType]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
const updateSurveySpec = spec => {
|
const updateSurveySpec = spec => {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
import WorkflowJobTemplateDetail from './WorkflowJobTemplateDetail';
|
import WorkflowJobTemplateDetail from './WorkflowJobTemplateDetail';
|
||||||
import WorkflowJobTemplateEdit from './WorkflowJobTemplateEdit';
|
import WorkflowJobTemplateEdit from './WorkflowJobTemplateEdit';
|
||||||
import { Visualizer } from './WorkflowJobTemplateVisualizer';
|
import { Visualizer } from './WorkflowJobTemplateVisualizer';
|
||||||
|
import TemplateSurvey from './TemplateSurvey';
|
||||||
|
|
||||||
class WorkflowJobTemplate extends Component {
|
class WorkflowJobTemplate extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -147,6 +148,10 @@ class WorkflowJobTemplate extends Component {
|
|||||||
name: i18n._(t`Completed Jobs`),
|
name: i18n._(t`Completed Jobs`),
|
||||||
link: `${match.url}/completed_jobs`,
|
link: `${match.url}/completed_jobs`,
|
||||||
});
|
});
|
||||||
|
tabsArray.push({
|
||||||
|
name: i18n._(t`Survey`),
|
||||||
|
link: `${match.url}/survey`,
|
||||||
|
});
|
||||||
|
|
||||||
tabsArray.forEach((tab, n) => {
|
tabsArray.forEach((tab, n) => {
|
||||||
tab.id = n;
|
tab.id = n;
|
||||||
@@ -284,6 +289,11 @@ class WorkflowJobTemplate extends Component {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{template && (
|
||||||
|
<Route path="/templates/:templateType/:id/survey">
|
||||||
|
<TemplateSurvey template={template} />
|
||||||
|
</Route>
|
||||||
|
)}
|
||||||
<Route
|
<Route
|
||||||
key="not-found"
|
key="not-found"
|
||||||
path="*"
|
path="*"
|
||||||
|
|||||||
@@ -3,19 +3,26 @@ import { Route } from 'react-router-dom';
|
|||||||
import { createMemoryHistory } from 'history';
|
import { createMemoryHistory } from 'history';
|
||||||
import { act } from 'react-dom/test-utils';
|
import { act } from 'react-dom/test-utils';
|
||||||
|
|
||||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers';
|
||||||
import WorkflowJobTemplate from './WorkflowJobTemplate';
|
import WorkflowJobTemplate from './WorkflowJobTemplate';
|
||||||
import { sleep } from '@testUtils/testUtils';
|
import { sleep } from '@testUtils/testUtils';
|
||||||
import { WorkflowJobTemplatesAPI, CredentialsAPI } from '@api';
|
import {
|
||||||
|
WorkflowJobTemplatesAPI,
|
||||||
|
CredentialsAPI,
|
||||||
|
OrganizationsAPI,
|
||||||
|
} from '@api';
|
||||||
|
|
||||||
jest.mock('@api/models/WorkflowJobTemplates');
|
jest.mock('@api/models/WorkflowJobTemplates');
|
||||||
jest.mock('@api/models/Credentials');
|
jest.mock('@api/models/Credentials');
|
||||||
|
jest.mock('@api/models/Organizations');
|
||||||
|
|
||||||
describe('<WorkflowJobTemplate/>', () => {
|
describe('<WorkflowJobTemplate/>', () => {
|
||||||
const mockMe = {
|
const mockMe = {
|
||||||
is_super_user: true,
|
is_super_user: true,
|
||||||
is_system_auditor: false,
|
is_system_auditor: false,
|
||||||
};
|
};
|
||||||
|
let wrapper;
|
||||||
|
let history;
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
WorkflowJobTemplatesAPI.readDetail.mockResolvedValue({
|
WorkflowJobTemplatesAPI.readDetail.mockResolvedValue({
|
||||||
data: {
|
data: {
|
||||||
@@ -57,16 +64,18 @@ describe('<WorkflowJobTemplate/>', () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
OrganizationsAPI.read.mockResolvedValue({
|
||||||
test('calls api to get workflow job template data', async () => {
|
data: { results: [{ id: 1, name: 'Org Foo' }] },
|
||||||
const history = createMemoryHistory({
|
});
|
||||||
initialEntries: ['/templates/workflow_job_template/1'],
|
});
|
||||||
|
beforeEach(() => {
|
||||||
|
history = createMemoryHistory({
|
||||||
|
initialEntries: ['/templates/workflow_job_template/1/details'],
|
||||||
});
|
});
|
||||||
let wrapper;
|
|
||||||
act(() => {
|
act(() => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<Route
|
<Route
|
||||||
path="/templates/workflow_job_template/:id"
|
path="/templates/workflow_job_template/:id/details"
|
||||||
component={() => (
|
component={() => (
|
||||||
<WorkflowJobTemplate setBreadcrumb={() => {}} me={mockMe} />
|
<WorkflowJobTemplate setBreadcrumb={() => {}} me={mockMe} />
|
||||||
)}
|
)}
|
||||||
@@ -75,22 +84,59 @@ describe('<WorkflowJobTemplate/>', () => {
|
|||||||
context: {
|
context: {
|
||||||
router: {
|
router: {
|
||||||
history,
|
history,
|
||||||
route: {
|
|
||||||
location: history.location,
|
|
||||||
match: {
|
|
||||||
params: { id: 1 },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('calls api to get workflow job template data', async () => {
|
||||||
expect(wrapper.find('WorkflowJobTemplate').length).toBe(1);
|
expect(wrapper.find('WorkflowJobTemplate').length).toBe(1);
|
||||||
expect(WorkflowJobTemplatesAPI.readDetail).toBeCalledWith('1');
|
expect(WorkflowJobTemplatesAPI.readDetail).toBeCalledWith('1');
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
await sleep(0);
|
await sleep(0);
|
||||||
expect(WorkflowJobTemplatesAPI.readWebhookKey).toBeCalledWith('1');
|
expect(WorkflowJobTemplatesAPI.readWebhookKey).toBeCalledWith('1');
|
||||||
expect(CredentialsAPI.readDetail).toBeCalledWith(1234567);
|
expect(CredentialsAPI.readDetail).toBeCalledWith(1234567);
|
||||||
|
expect(OrganizationsAPI.read).toBeCalledWith({
|
||||||
|
page_size: 1,
|
||||||
|
role_level: 'notification_admin_role',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('renders proper tabs', async () => {
|
||||||
|
const tabs = [
|
||||||
|
'Details',
|
||||||
|
'Access',
|
||||||
|
'Notifications',
|
||||||
|
'Schedules',
|
||||||
|
'Visualizer',
|
||||||
|
'Completed Jobs',
|
||||||
|
'Survey',
|
||||||
|
];
|
||||||
|
waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0);
|
||||||
|
wrapper.update();
|
||||||
|
wrapper.find('TabContainer').forEach(tc => {
|
||||||
|
tabs.forEach(t => expect(tc.prop(`aria-label=[${t}]`)));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Does not render Notifications tab', async () => {
|
||||||
|
OrganizationsAPI.read.mockResolvedValue({
|
||||||
|
data: { results: [] },
|
||||||
|
});
|
||||||
|
const tabs = [
|
||||||
|
'Details',
|
||||||
|
'Access',
|
||||||
|
'Schedules',
|
||||||
|
'Visualizer',
|
||||||
|
'Completed Jobs',
|
||||||
|
'Survey',
|
||||||
|
];
|
||||||
|
waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0);
|
||||||
|
wrapper.update();
|
||||||
|
wrapper.find('TabContainer').forEach(tc => {
|
||||||
|
tabs.forEach(t => expect(tc.prop(`aria-label=[${t}]`)));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user