mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
Merge pull request #9995 from mabashian/7670-delete-workflow-survey
Fixes bug deleting the last workflow survey question SUMMARY link #7670 ISSUE TYPE Bugfix Pull Request COMPONENT NAME UI Reviewed-by: Alex Corey <Alex.swansboro@gmail.com> Reviewed-by: Tiago Góes <tiago.goes2009@gmail.com>
This commit is contained in:
commit
fa02fd8563
@ -61,9 +61,13 @@ function TemplateSurvey({ template, canEdit, i18n }) {
|
||||
|
||||
const { request: deleteSurvey, error: deleteError } = useRequest(
|
||||
useCallback(async () => {
|
||||
await JobTemplatesAPI.destroySurvey(templateId);
|
||||
if (templateType === 'workflow_job_template') {
|
||||
await WorkflowJobTemplatesAPI.destroySurvey(templateId);
|
||||
} else {
|
||||
await JobTemplatesAPI.destroySurvey(templateId);
|
||||
}
|
||||
setSurvey(null);
|
||||
}, [templateId, setSurvey])
|
||||
}, [templateId, setSurvey, templateType])
|
||||
);
|
||||
|
||||
const { request: toggleSurvey, error: toggleError } = useRequest(
|
||||
|
||||
@ -27,6 +27,10 @@ describe('<TemplateSurvey />', () => {
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
test('should fetch survey from API', async () => {
|
||||
const history = createMemoryHistory({
|
||||
initialEntries: ['/templates/job_template/7/survey'],
|
||||
@ -209,4 +213,90 @@ describe('<TemplateSurvey />', () => {
|
||||
survey_enabled: false,
|
||||
});
|
||||
});
|
||||
|
||||
test('should successfully delete jt survey', async () => {
|
||||
const history = createMemoryHistory({
|
||||
initialEntries: ['/templates/job_template/15/survey'],
|
||||
});
|
||||
|
||||
JobTemplatesAPI.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: 'job_template', id: 15 },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
wrapper.update();
|
||||
act(() => wrapper.find('Checkbox#select-all').invoke('onChange')(true));
|
||||
wrapper.update();
|
||||
wrapper.find('Button[ouiaId="survey-delete-button"]').simulate('click');
|
||||
wrapper.update();
|
||||
await act(async () =>
|
||||
wrapper.find('Button[ouiaId="delete-confirm-button"]').simulate('click')
|
||||
);
|
||||
wrapper.update();
|
||||
expect(JobTemplatesAPI.destroySurvey).toBeCalledWith('15');
|
||||
expect(WorkflowJobTemplatesAPI.destroySurvey).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test('should successfully delete wfjt survey', async () => {
|
||||
const history = createMemoryHistory({
|
||||
initialEntries: ['/templates/workflow_job_template/15/survey'],
|
||||
});
|
||||
|
||||
WorkflowJobTemplatesAPI.readSurvey.mockResolvedValueOnce({
|
||||
data: surveyData,
|
||||
});
|
||||
|
||||
let wrapper;
|
||||
await act(async () => {
|
||||
wrapper = mountWithContexts(
|
||||
<Route path="/templates/:templateType/:id/survey">
|
||||
<TemplateSurvey template={mockWorkflowJobTemplateData} canEdit />
|
||||
</Route>,
|
||||
{
|
||||
context: {
|
||||
router: {
|
||||
history,
|
||||
route: {
|
||||
location: history.location,
|
||||
match: {
|
||||
params: { templateType: 'workflow_job_template', id: 15 },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
wrapper.update();
|
||||
act(() => wrapper.find('Checkbox#select-all').invoke('onChange')(true));
|
||||
wrapper.update();
|
||||
wrapper.find('Button[ouiaId="survey-delete-button"]').simulate('click');
|
||||
wrapper.update();
|
||||
await act(async () =>
|
||||
wrapper.find('Button[ouiaId="delete-confirm-button"]').simulate('click')
|
||||
);
|
||||
wrapper.update();
|
||||
expect(WorkflowJobTemplatesAPI.destroySurvey).toBeCalledWith('15');
|
||||
expect(JobTemplatesAPI.destroySurvey).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user