@@ -137,13 +137,24 @@ describe("AppsTab", () => {
137137 expect ( screen . getByText ( errorMessage ) ) . toBeInTheDocument ( ) ;
138138 } ) ;
139139
140- it ( "should open app renderer when an app card is clicked and Open App button is clicked" , ( ) => {
140+ it ( "should open app renderer when an app card is clicked and Open App button is clicked if fields exist" , ( ) => {
141+ const toolWithFields : Tool = {
142+ name : "fieldsApp" ,
143+ inputSchema : {
144+ type : "object" ,
145+ properties : {
146+ field1 : { type : "string" } ,
147+ } ,
148+ } ,
149+ _meta : { ui : { resourceUri : "ui://fields" } } ,
150+ } as Tool & { _meta ?: { ui ?: { resourceUri ?: string } } } ;
151+
141152 renderAppsTab ( {
142- tools : [ mockAppTool ] ,
143- resourceContentMap : { "ui://weather-app " : "<html>test</html>" } ,
153+ tools : [ toolWithFields ] ,
154+ resourceContentMap : { "ui://fields " : "<html>test</html>" } ,
144155 } ) ;
145156
146- const appCard = screen . getByText ( "weatherApp " ) . closest ( "div" ) ;
157+ const appCard = screen . getByText ( "fieldsApp " ) . closest ( "div" ) ;
147158 expect ( appCard ) . toBeTruthy ( ) ;
148159 fireEvent . click ( appCard ! ) ;
149160
@@ -157,7 +168,7 @@ describe("AppsTab", () => {
157168
158169 // AppRenderer should be rendered
159170 expect ( screen . getByTestId ( "app-renderer" ) ) . toBeInTheDocument ( ) ;
160- expect ( screen . getByText ( "Tool: weatherApp " ) ) . toBeInTheDocument ( ) ;
171+ expect ( screen . getByText ( "Tool: fieldsApp " ) ) . toBeInTheDocument ( ) ;
161172 } ) ;
162173
163174 it ( "should close app renderer when close button is clicked" , ( ) => {
@@ -169,7 +180,7 @@ describe("AppsTab", () => {
169180 // Open the app
170181 const appCard = screen . getByText ( "weatherApp" ) . closest ( "div" ) ;
171182 fireEvent . click ( appCard ! ) ;
172- fireEvent . click ( screen . getByRole ( "button" , { name : / o p e n a p p / i } ) ) ;
183+ // weatherApp has no properties in mockAppTool, so it should be open immediately
173184 expect ( screen . getByTestId ( "app-renderer" ) ) . toBeInTheDocument ( ) ;
174185
175186 // Close the app (Deselect tool)
@@ -190,7 +201,7 @@ describe("AppsTab", () => {
190201 // Open the app
191202 const appCard = screen . getByText ( "weatherApp" ) . closest ( "div" ) ;
192203 fireEvent . click ( appCard ! ) ;
193- fireEvent . click ( screen . getByRole ( "button" , { name : / o p e n a p p / i } ) ) ;
204+ // weatherApp has no properties in mockAppTool, so it should be open immediately
194205
195206 expect ( screen . getByTestId ( "app-renderer" ) ) . toBeInTheDocument ( ) ;
196207 expect ( screen . getByText ( `Content: ${ resourceContent } ` ) ) . toBeInTheDocument ( ) ;
@@ -227,7 +238,7 @@ describe("AppsTab", () => {
227238 // Select the app
228239 const appCard = screen . getByText ( "weatherApp" ) . closest ( "div" ) ;
229240 fireEvent . click ( appCard ! ) ;
230- fireEvent . click ( screen . getByRole ( "button" , { name : / o p e n a p p / i } ) ) ;
241+ // weatherApp has no properties in mockAppTool, so it should be open immediately
231242 expect ( screen . getByTestId ( "app-renderer" ) ) . toBeInTheDocument ( ) ;
232243
233244 // Update tools list to remove the selected tool
@@ -254,7 +265,7 @@ describe("AppsTab", () => {
254265 // Select the app
255266 const appCard = screen . getByText ( "weatherApp" ) . closest ( "div" ) ;
256267 fireEvent . click ( appCard ! ) ;
257- fireEvent . click ( screen . getByRole ( "button" , { name : / o p e n a p p / i } ) ) ;
268+ // weatherApp has no properties in mockAppTool, so it should be open immediately
258269 expect ( screen . getByTestId ( "app-renderer" ) ) . toBeInTheDocument ( ) ;
259270
260271 // Update tools list with the same tool
@@ -280,14 +291,7 @@ describe("AppsTab", () => {
280291 // Select the app
281292 const appCard = screen . getByText ( "weatherApp" ) . closest ( "div" ) ;
282293 fireEvent . click ( appCard ! ) ;
283-
284- // Initially, Maximize button should not be visible (app not open)
285- expect (
286- screen . queryByRole ( "button" , { name : / m a x i m i z e / i } ) ,
287- ) . not . toBeInTheDocument ( ) ;
288-
289- // Open the app
290- fireEvent . click ( screen . getByRole ( "button" , { name : / o p e n a p p / i } ) ) ;
294+ // weatherApp has no properties in mockAppTool, so it should be open immediately
291295
292296 // Now Maximize button should be visible
293297 expect (
@@ -320,9 +324,7 @@ describe("AppsTab", () => {
320324 // Select the app
321325 const appCard = screen . getByText ( "weatherApp" ) . closest ( "div" ) ;
322326 fireEvent . click ( appCard ! ) ;
323-
324- // Open the app
325- fireEvent . click ( screen . getByRole ( "button" , { name : / o p e n a p p / i } ) ) ;
327+ // weatherApp has no properties in mockAppTool, so it should be open immediately
326328
327329 // Maximize
328330 fireEvent . click ( screen . getByRole ( "button" , { name : / m a x i m i z e / i } ) ) ;
@@ -353,7 +355,7 @@ describe("AppsTab", () => {
353355 // Open the app
354356 const appCard = screen . getByText ( "weatherApp" ) . closest ( "div" ) ;
355357 fireEvent . click ( appCard ! ) ;
356- fireEvent . click ( screen . getByRole ( "button" , { name : / o p e n a p p / i } ) ) ;
358+ // weatherApp has no properties in mockAppTool, so it should be open immediately
357359
358360 // AppRenderer should still be rendered but with no content
359361 expect ( screen . getByTestId ( "app-renderer" ) ) . toBeInTheDocument ( ) ;
@@ -433,11 +435,76 @@ describe("AppsTab", () => {
433435 } ) ;
434436
435437 it ( "should allow going back to input form from app renderer" , ( ) => {
438+ const toolWithFields : Tool = {
439+ name : "fieldsApp" ,
440+ inputSchema : {
441+ type : "object" ,
442+ properties : {
443+ field1 : { type : "string" } ,
444+ } ,
445+ } ,
446+ _meta : { ui : { resourceUri : "ui://fields" } } ,
447+ } as Tool & { _meta ?: { ui ?: { resourceUri ?: string } } } ;
448+
436449 renderAppsTab ( {
437- tools : [ mockAppTool ] ,
450+ tools : [ toolWithFields ] ,
451+ } ) ;
452+
453+ fireEvent . click ( screen . getByText ( "fieldsApp" ) ) ;
454+ fireEvent . click ( screen . getByRole ( "button" , { name : / o p e n a p p / i } ) ) ;
455+
456+ expect ( screen . getByTestId ( "app-renderer" ) ) . toBeInTheDocument ( ) ;
457+
458+ const backButton = screen . queryByRole ( "button" , { name : / b a c k t o i n p u t / i } ) ;
459+ expect ( backButton ) . toBeInTheDocument ( ) ;
460+ } ) ;
461+
462+ it ( "should skip input form if tool has no input fields" , ( ) => {
463+ const toolNoFields : Tool = {
464+ name : "noFieldsApp" ,
465+ inputSchema : {
466+ type : "object" ,
467+ properties : { } ,
468+ } ,
469+ _meta : { ui : { resourceUri : "ui://no-fields" } } ,
470+ } as Tool & { _meta ?: { ui ?: { resourceUri ?: string } } } ;
471+
472+ renderAppsTab ( {
473+ tools : [ toolNoFields ] ,
438474 } ) ;
439475
440- fireEvent . click ( screen . getByText ( "weatherApp" ) ) ;
476+ fireEvent . click ( screen . getByText ( "noFieldsApp" ) ) ;
477+
478+ // Should see the renderer immediately
479+ expect ( screen . getByTestId ( "app-renderer" ) ) . toBeInTheDocument ( ) ;
480+ expect ( screen . getByText ( "Tool: noFieldsApp" ) ) . toBeInTheDocument ( ) ;
481+
482+ // Should NOT see the back button
483+ expect (
484+ screen . queryByRole ( "button" , { name : / b a c k t o i n p u t / i } ) ,
485+ ) . not . toBeInTheDocument ( ) ;
486+ } ) ;
487+
488+ it ( "should allow going back to input form from app renderer if fields exist" , ( ) => {
489+ const toolWithFields : Tool = {
490+ name : "fieldsApp" ,
491+ inputSchema : {
492+ type : "object" ,
493+ properties : {
494+ field1 : { type : "string" } ,
495+ } ,
496+ } ,
497+ _meta : { ui : { resourceUri : "ui://fields" } } ,
498+ } as Tool & { _meta ?: { ui ?: { resourceUri ?: string } } } ;
499+
500+ renderAppsTab ( {
501+ tools : [ toolWithFields ] ,
502+ } ) ;
503+
504+ fireEvent . click ( screen . getByText ( "fieldsApp" ) ) ;
505+
506+ // Should see input form first
507+ expect ( screen . getByText ( "App Input" ) ) . toBeInTheDocument ( ) ;
441508 fireEvent . click ( screen . getByRole ( "button" , { name : / o p e n a p p / i } ) ) ;
442509
443510 expect ( screen . getByTestId ( "app-renderer" ) ) . toBeInTheDocument ( ) ;
0 commit comments