mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 11:20:39 -03:30
toggles WFJT survey on and off
This commit is contained in:
parent
48ecd2400c
commit
a1fa21d5a9
@ -68,11 +68,17 @@ function TemplateSurvey({ template, canEdit, i18n }) {
|
||||
|
||||
const { request: toggleSurvey, error: toggleError } = useRequest(
|
||||
useCallback(async () => {
|
||||
await JobTemplatesAPI.update(template.id, {
|
||||
survey_enabled: !surveyEnabled,
|
||||
});
|
||||
if (templateType === 'workflow_job_template') {
|
||||
await WorkflowJobTemplatesAPI.update(template.id, {
|
||||
survey_enabled: !surveyEnabled,
|
||||
});
|
||||
} else {
|
||||
await JobTemplatesAPI.update(template.id, {
|
||||
survey_enabled: !surveyEnabled,
|
||||
});
|
||||
}
|
||||
setSurveyEnabled(!surveyEnabled);
|
||||
}, [template.id, surveyEnabled])
|
||||
}, [template.id, templateType, surveyEnabled])
|
||||
);
|
||||
|
||||
const { error, dismissError } = useDismissableError(
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
import React from 'react';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { Route } from 'react-router-dom';
|
||||
import { createMemoryHistory } from 'history';
|
||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||
import TemplateSurvey from './TemplateSurvey';
|
||||
import { JobTemplatesAPI } from '../../api';
|
||||
import { JobTemplatesAPI, WorkflowJobTemplatesAPI } from '../../api';
|
||||
import mockJobTemplateData from './shared/data.job_template.json';
|
||||
|
||||
jest.mock('../../api/models/JobTemplates');
|
||||
jest.mock('../../api/models/WorkflowJobTemplates');
|
||||
|
||||
const surveyData = {
|
||||
name: 'Survey',
|
||||
@ -86,4 +88,64 @@ describe('<TemplateSurvey />', () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test('should toggle jt survery on', async () => {
|
||||
const history = createMemoryHistory({
|
||||
initialEntries: ['/templates/job_template/1/survey'],
|
||||
});
|
||||
let wrapper;
|
||||
await act(async () => {
|
||||
wrapper = mountWithContexts(
|
||||
<TemplateSurvey template={mockJobTemplateData} canEdit />,
|
||||
{
|
||||
context: { router: { history } },
|
||||
}
|
||||
);
|
||||
});
|
||||
wrapper.update();
|
||||
await act(() =>
|
||||
wrapper.find('Switch[aria-label="Survey Toggle"]').prop('onChange')()
|
||||
);
|
||||
wrapper.update();
|
||||
|
||||
expect(JobTemplatesAPI.update).toBeCalledWith(7, { survey_enabled: false });
|
||||
});
|
||||
|
||||
test('should toggle wfjt survey on', async () => {
|
||||
const history = createMemoryHistory({
|
||||
initialEntries: ['/templates/workflow_job_template/1/survey'],
|
||||
});
|
||||
|
||||
WorkflowJobTemplatesAPI.readSurvey.mockResolvedValueOnce({
|
||||
data: surveyData,
|
||||
});
|
||||
|
||||
let wrapper;
|
||||
await act(async () => {
|
||||
wrapper = mountWithContexts(
|
||||
<Route path="/templates/:templateType/:id/survey">
|
||||
<TemplateSurvey template={mockJobTemplateData} canEdit />
|
||||
</Route>,
|
||||
{
|
||||
context: {
|
||||
router: {
|
||||
history,
|
||||
route: {
|
||||
location: history.location,
|
||||
match: { params: { templateType: 'workflow_job_template' } },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
wrapper.update();
|
||||
await act(() =>
|
||||
wrapper.find('Switch[aria-label="Survey Toggle"]').prop('onChange')()
|
||||
);
|
||||
wrapper.update();
|
||||
expect(WorkflowJobTemplatesAPI.update).toBeCalledWith(7, {
|
||||
survey_enabled: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user