@@ -25,11 +25,6 @@ export const EndpointAccordion: React.FC<IEndpointAccordionProps> = ({
2525 addTestTab
2626 } ) => {
2727
28- const [ selectedCode , setSelectedCode ] = useState < number | string > ( 0 ) ;
29- const [ isFault , setIsFault ] = useState ( false ) ;
30-
31- const selectedTestCases = status_codes . find ( ( code ) => code . code === selectedCode ) ?. test_cases || [ ] ;
32- const selectedFaultTestCases = faults . find ( ( code ) => code . code === selectedCode ) ?. test_cases || [ ] ;
3328
3429 const sortedStatusCodes = status_codes . sort ( ( a , b ) =>
3530 {
@@ -42,6 +37,12 @@ export const EndpointAccordion: React.FC<IEndpointAccordionProps> = ({
4237 }
4338 ) ;
4439
40+ const [ selectedCode , setSelectedCode ] = useState < number | string > ( sortedStatusCodes [ 0 ] ?. code || 0 ) ;
41+ const [ isFault , setIsFault ] = useState ( false ) ;
42+
43+ const selectedTestCases = status_codes . find ( ( code ) => code . code === selectedCode ) ?. test_cases || [ ] ;
44+ const selectedFaultTestCases = faults . find ( ( code ) => code . code === selectedCode ) ?. test_cases || [ ] ;
45+
4546 const sortedFaults = faults . sort ( ( a , b ) => {
4647 const codeA = Number ( a . code ) ;
4748 const codeB = Number ( b . code ) ;
@@ -50,6 +51,12 @@ export const EndpointAccordion: React.FC<IEndpointAccordionProps> = ({
5051 }
5152 return codeA - codeB ;
5253 } ) ;
54+ const getSelectedStyle = ( code : number | string , fault : boolean ) => {
55+
56+ const isSelected = selectedCode === code && isFault === fault ;
57+ return isSelected ? "ring-2 ring-offset-2 ring-offset-white ring-blue-400 shadow-md" : "" ;
58+
59+ }
5360
5461 const faultColors = [ "bg-red-300" , "bg-red-500" , "bg-red-700" ] ;
5562 return (
@@ -79,7 +86,7 @@ export const EndpointAccordion: React.FC<IEndpointAccordionProps> = ({
7986 setSelectedCode ( code . code ) ;
8087 setIsFault ( false ) ;
8188 } }
82- className = { `${ getColor ( code . code , true , false ) } hover:bg-green-600 cursor-pointer text-white px-4 py-2 text-base font-bold border-2 border-black shadow-[2px_2px_0px_0px_rgba(0,0,0,1)]` } >
89+ className = { `${ getColor ( code . code , true , false ) } ${ getSelectedStyle ( code . code , false ) } hover:bg-green-600 cursor-pointer text-white px-4 py-2 text-base font-bold border-2 border-black shadow-[2px_2px_0px_0px_rgba(0,0,0,1)]` } >
8390 { code . code }
8491 </ Badge >
8592 ) )
@@ -100,7 +107,7 @@ export const EndpointAccordion: React.FC<IEndpointAccordionProps> = ({
100107 setSelectedCode ( fault . code )
101108 setIsFault ( true ) ;
102109 } }
103- className = { `${ faultColors [ index % faultColors . length ] } hover:bg-red-400 cursor-pointer text-white px-4 py-2 text-base font-bold border-2 border-black shadow-[2px_2px_0px_0px_rgba(0,0,0,1)]` } >
110+ className = { `${ faultColors [ index % faultColors . length ] } ${ getSelectedStyle ( fault . code , true ) } hover:bg-red-400 cursor-pointer text-white px-4 py-2 text-base font-bold border-2 border-black shadow-[2px_2px_0px_0px_rgba(0,0,0,1)]` } >
104111 { fault . code }
105112 </ Badge >
106113 ) )
@@ -111,6 +118,7 @@ export const EndpointAccordion: React.FC<IEndpointAccordionProps> = ({
111118 }
112119 </ div >
113120 </ div >
121+ < div className = "text-xs text-gray-500 mt-1" > Click to show test cases.</ div >
114122
115123 {
116124 ( selectedTestCases . length > 0 || selectedFaultTestCases . length > 0 ) &&
0 commit comments