diff --git a/awx/ui_next/src/screens/Template/TemplateSurvey.jsx b/awx/ui_next/src/screens/Template/TemplateSurvey.jsx
index 3f8381c129..23b57f43ea 100644
--- a/awx/ui_next/src/screens/Template/TemplateSurvey.jsx
+++ b/awx/ui_next/src/screens/Template/TemplateSurvey.jsx
@@ -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(
diff --git a/awx/ui_next/src/screens/Template/TemplateSurvey.test.jsx b/awx/ui_next/src/screens/Template/TemplateSurvey.test.jsx
index 9b4d622f78..0d21bc15e0 100644
--- a/awx/ui_next/src/screens/Template/TemplateSurvey.test.jsx
+++ b/awx/ui_next/src/screens/Template/TemplateSurvey.test.jsx
@@ -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('', () => {
],
});
});
+
+ test('should toggle jt survery on', async () => {
+ const history = createMemoryHistory({
+ initialEntries: ['/templates/job_template/1/survey'],
+ });
+ let wrapper;
+ await act(async () => {
+ wrapper = mountWithContexts(
+ ,
+ {
+ 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(
+
+
+ ,
+ {
+ 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,
+ });
+ });
});