diff --git a/frontend/src/component/playground/Playground/AdvancedPlayground.tsx b/frontend/src/component/playground/Playground/AdvancedPlayground.tsx index b46231015e15..573a02aa4902 100644 --- a/frontend/src/component/playground/Playground/AdvancedPlayground.tsx +++ b/frontend/src/component/playground/Playground/AdvancedPlayground.tsx @@ -113,7 +113,12 @@ export const AdvancedPlayground: FC<{ const { setToastData } = useToast(); const [searchParams, setSearchParams] = useSearchParams(); const [changeRequest, setChangeRequest] = useState(); - const { evaluateAdvancedPlayground, loading, errors } = usePlaygroundApi(); + const { + evaluateAdvancedPlayground, + evaluateChangeRequestPlayground, + loading, + errors, + } = usePlaygroundApi(); const [hasFormBeenSubmitted, setHasFormBeenSubmitted] = useState(false); useEffect(() => { @@ -203,15 +208,22 @@ export const AdvancedPlayground: FC<{ ) => { try { setConfigurationError(undefined); - const parsedContext = JSON.parse(context || '{}'); - const response = await evaluateAdvancedPlayground({ - environments: resolveEnvironments(environments), - projects: resolveProjects(projects), - context: { - appName: 'playground', - ...parsedContext, - }, - }); + const parsedContext = { + appName: 'playground', + ...JSON.parse(context || '{}'), + }; + + const response = changeRequest + ? await evaluateChangeRequestPlayground(changeRequest, { + context: parsedContext, + projects: [], + environments: [], + }) + : await evaluateAdvancedPlayground({ + environments: resolveEnvironments(environments), + projects: resolveProjects(projects), + context: parsedContext, + }); if (action && typeof action === 'function') { action(); diff --git a/frontend/src/component/playground/Playground/PlaygroundForm/PlaygroundConnectionFieldset/PlaygroundConnectionFieldset.test.tsx b/frontend/src/component/playground/Playground/PlaygroundForm/PlaygroundConnectionFieldset/PlaygroundConnectionFieldset.test.tsx index b673edecca15..b7b7c16ec705 100644 --- a/frontend/src/component/playground/Playground/PlaygroundForm/PlaygroundConnectionFieldset/PlaygroundConnectionFieldset.test.tsx +++ b/frontend/src/component/playground/Playground/PlaygroundForm/PlaygroundConnectionFieldset/PlaygroundConnectionFieldset.test.tsx @@ -213,7 +213,7 @@ test('should show change request and disable other fields until removed', async const [environments, setEnvironments] = useState([]); const [projects, setProjects] = useState(['test-project']); const [token, setToken] = useState(); - const [changeRequest, setChangeRequest] = useState('CR #1'); + const [changeRequest, setChangeRequest] = useState('1'); const availableEnvironments = ['development', 'production']; @@ -233,14 +233,15 @@ test('should show change request and disable other fields until removed', async }; render(); - const changeRequestInput = await screen.findByDisplayValue('CR #1'); - // expect(changeRequestInput).toHaveValue('CR #1'); + const changeRequestInput = + await screen.findByDisplayValue('Change request #1'); const viewButton = await screen.findByText(/View change request/); expect(viewButton).toHaveProperty( 'href', - 'http://localhost:3000/projects/test-project/change-requests/CR%20#1', + 'http://localhost:3000/projects/test-project/change-requests/1', ); - // TODO: check if other fields are disabled + const tokenInput = await screen.findByLabelText('API token'); + expect(tokenInput).toBeDisabled(); const clearButton = await screen.findByLabelText(/clear change request/i); diff --git a/frontend/src/component/playground/Playground/PlaygroundForm/PlaygroundConnectionFieldset/PlaygroundConnectionFieldset.tsx b/frontend/src/component/playground/Playground/PlaygroundForm/PlaygroundConnectionFieldset/PlaygroundConnectionFieldset.tsx index 6520d587c478..1ae3008cffdb 100644 --- a/frontend/src/component/playground/Playground/PlaygroundForm/PlaygroundConnectionFieldset/PlaygroundConnectionFieldset.tsx +++ b/frontend/src/component/playground/Playground/PlaygroundForm/PlaygroundConnectionFieldset/PlaygroundConnectionFieldset.tsx @@ -277,20 +277,17 @@ export const PlaygroundConnectionFieldset: FC< {}} type={'text'} - // error={Boolean(changeRequestError)} - // errorText={changeRequestError)}} - placeholder={'Enter your API token'} - data-testid={'PLAYGROUND_TOKEN_INPUT'} disabled InputProps={{ endAdornment: ( - + { return res.json(); }; + const evaluateChangeRequestPlayground = async ( + changeRequestId: string, + payload: AdvancedPlaygroundRequestSchema, // FIXME: type + ): Promise => { + const path = `${URI}/change-request/${changeRequestId}`; + const req = createRequest(path, { + method: 'POST', + body: JSON.stringify(payload), + }); + + const res = await makeRequest(req.caller, req.id); + return res.json(); + }; + return { evaluateAdvancedPlayground, + evaluateChangeRequestPlayground, errors, loading, };