From 43994d8be3129f71ec1f694228769d455e283d6a Mon Sep 17 00:00:00 2001
From: Aurelio <19254254+Aureliolo@users.noreply.github.com>
Date: Fri, 7 Aug 2026 17:29:18 +0200
Subject: [PATCH] fix: survey question edit link resolves to a doubled survey/
segment
SurveyListItem built its link target as `survey/edit?...`, which was correct
under react-router v5: relative resolution dropped the last path segment, so
from /templates/job_template/1/survey the target became .../survey/edit.
v6 resolves a relative target against the current route path treated as a
directory, so the same string now appends and produces .../survey/survey/edit.
TemplateSurvey registers only add, edit and an index route with no "*"
fallback, so the unmatched remainder renders nothing and the survey screen
comes up blank with no error.
The list renders from the index route of survey/*, so dropping the prefix
resolves correctly.
The existing href assertion mounted the item at the router root, where
relative resolution had nothing to append to, and so passed against the broken
component. Mount it inside the same survey/* parent plus index child the app
uses, and cover the question-name link, which had no test at all.
---
.../screens/Template/Survey/SurveyListItem.js | 4 +-
.../Template/Survey/SurveyListItem.test.js | 57 ++++++++++++++++++-
2 files changed, 57 insertions(+), 4 deletions(-)
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'
);
});
});