diff --git a/awx/ui/src/screens/Template/Survey/SurveyListItem.js b/awx/ui/src/screens/Template/Survey/SurveyListItem.js index 387db59e..f586836c 100644 --- a/awx/ui/src/screens/Template/Survey/SurveyListItem.js +++ b/awx/ui/src/screens/Template/Survey/SurveyListItem.js @@ -44,7 +44,7 @@ function SurveyListItem({ canEdit, question, isChecked, onSelect, rowIndex }) { > <> @@ -98,7 +98,7 @@ function SurveyListItem({ canEdit, question, isChecked, onSelect, rowIndex }) { ouiaId={`edit-survey-${question.variable}`} variant="plain" component={Link} - to={`survey/edit?question_variable=${encodeURIComponent( + to={`edit?question_variable=${encodeURIComponent( question.variable )}`} /> diff --git a/awx/ui/src/screens/Template/Survey/SurveyListItem.test.js b/awx/ui/src/screens/Template/Survey/SurveyListItem.test.js index ee4b3f14..b6ed30ba 100644 --- a/awx/ui/src/screens/Template/Survey/SurveyListItem.test.js +++ b/awx/ui/src/screens/Template/Survey/SurveyListItem.test.js @@ -1,5 +1,7 @@ import React from 'react'; import { screen } from '@testing-library/react'; +import { Routes, Route } from 'react-router'; +import { createMemoryHistory } from 'history'; import { renderWithContexts } from '../../../../testUtils/rtlContexts'; import SurveyListItem from './SurveyListItem'; @@ -10,6 +12,40 @@ const renderInTable = (ui) => ); +// Mirrors how the app mounts the list: Template.js routes "survey/*" to +// TemplateSurvey, which renders SurveyList from its own index route. Relative +// link targets resolve against that route path, so hrefs are only meaningful +// when the item is mounted at the same depth. +const renderAtSurveyRoute = (ui) => + renderWithContexts( + + + + {ui} + + } + /> + + } + /> + , + { + context: { + router: { + history: createMemoryHistory({ + initialEntries: ['/templates/job_template/59/survey'], + }), + }, + }, + } + ); + describe('', () => { const item = { question_name: 'Foo', @@ -145,7 +181,7 @@ describe('', () => { }); test('edit button shown to users with edit capabilities', () => { - renderInTable( + renderAtSurveyRoute( ', () => { expect(editLink).toBeInTheDocument(); expect(editLink).toHaveAttribute( 'href', - '/survey/edit?question_variable=buzz' + '/templates/job_template/59/survey/edit?question_variable=buzz' + ); + }); + + test('question name links to the edit form for that question', () => { + renderAtSurveyRoute( + + ); + + expect(screen.getByRole('link', { name: 'Foo' })).toHaveAttribute( + 'href', + '/templates/job_template/59/survey/edit?question_variable=buzz' ); }); });