mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 18:07:33 -02:30
toggles WFJT survey on and off
This commit is contained in:
@@ -68,11 +68,17 @@ function TemplateSurvey({ template, canEdit, i18n }) {
|
|||||||
|
|
||||||
const { request: toggleSurvey, error: toggleError } = useRequest(
|
const { request: toggleSurvey, error: toggleError } = useRequest(
|
||||||
useCallback(async () => {
|
useCallback(async () => {
|
||||||
await JobTemplatesAPI.update(template.id, {
|
if (templateType === 'workflow_job_template') {
|
||||||
survey_enabled: !surveyEnabled,
|
await WorkflowJobTemplatesAPI.update(template.id, {
|
||||||
});
|
survey_enabled: !surveyEnabled,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await JobTemplatesAPI.update(template.id, {
|
||||||
|
survey_enabled: !surveyEnabled,
|
||||||
|
});
|
||||||
|
}
|
||||||
setSurveyEnabled(!surveyEnabled);
|
setSurveyEnabled(!surveyEnabled);
|
||||||
}, [template.id, surveyEnabled])
|
}, [template.id, templateType, surveyEnabled])
|
||||||
);
|
);
|
||||||
|
|
||||||
const { error, dismissError } = useDismissableError(
|
const { error, dismissError } = useDismissableError(
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { act } from 'react-dom/test-utils';
|
import { act } from 'react-dom/test-utils';
|
||||||
|
import { Route } from 'react-router-dom';
|
||||||
import { createMemoryHistory } from 'history';
|
import { createMemoryHistory } from 'history';
|
||||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||||
import TemplateSurvey from './TemplateSurvey';
|
import TemplateSurvey from './TemplateSurvey';
|
||||||
import { JobTemplatesAPI } from '../../api';
|
import { JobTemplatesAPI, WorkflowJobTemplatesAPI } from '../../api';
|
||||||
import mockJobTemplateData from './shared/data.job_template.json';
|
import mockJobTemplateData from './shared/data.job_template.json';
|
||||||
|
|
||||||
jest.mock('../../api/models/JobTemplates');
|
jest.mock('../../api/models/JobTemplates');
|
||||||
|
jest.mock('../../api/models/WorkflowJobTemplates');
|
||||||
|
|
||||||
const surveyData = {
|
const surveyData = {
|
||||||
name: 'Survey',
|
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,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user