@@ -22,11 +22,11 @@ vi.mock("../../common/CodeBlock", () => ({
2222} ) )
2323
2424vi . mock ( "../CommandPatternSelector" , ( ) => ( {
25- CommandPatternSelector : ( { command, onAllowCommandChange , onDenyCommandChange } : any ) => (
25+ CommandPatternSelector : ( { command, onAllowPatternChange , onDenyPatternChange } : any ) => (
2626 < div data-testid = "command-pattern-selector" >
2727 < span > { command } </ span >
28- < button onClick = { ( ) => onAllowCommandChange ( command ) } > Allow { command } </ button >
29- < button onClick = { ( ) => onDenyCommandChange ( command ) } > Deny { command } </ button >
28+ < button onClick = { ( ) => onAllowPatternChange ( command ) } > Allow { command } </ button >
29+ < button onClick = { ( ) => onDenyPatternChange ( command ) } > Deny { command } </ button >
3030 </ div >
3131 ) ,
3232} ) )
@@ -92,7 +92,9 @@ describe("CommandExecution", () => {
9292 )
9393
9494 expect ( screen . getByTestId ( "command-pattern-selector" ) ) . toBeInTheDocument ( )
95- expect ( screen . getByText ( "npm install express" ) ) . toBeInTheDocument ( )
95+ // Check that the command is shown in the pattern selector
96+ const selector = screen . getByTestId ( "command-pattern-selector" )
97+ expect ( selector ) . toHaveTextContent ( "npm install express" )
9698 } )
9799
98100 it ( "should handle allow command change" , ( ) => {
@@ -206,9 +208,10 @@ Suggested patterns: npm, npm install, npm run`
206208 expect ( codeBlocks [ 0 ] ) . toHaveTextContent ( "npm install" )
207209 expect ( codeBlocks [ 1 ] ) . toHaveTextContent ( "Suggested patterns: npm, npm install, npm run" )
208210
209- expect ( screen . getByTestId ( "command-pattern-selector" ) ) . toBeInTheDocument ( )
210- // Should show the full command
211- expect ( screen . getByText ( "npm install" ) ) . toBeInTheDocument ( )
211+ const selector = screen . getByTestId ( "command-pattern-selector" )
212+ expect ( selector ) . toBeInTheDocument ( )
213+ // Should show the full command in the selector
214+ expect ( selector ) . toHaveTextContent ( "npm install" )
212215 } )
213216
214217 it ( "should handle commands with pipes" , ( ) => {
@@ -218,8 +221,9 @@ Suggested patterns: npm, npm install, npm run`
218221 </ ExtensionStateWrapper > ,
219222 )
220223
221- expect ( screen . getByTestId ( "command-pattern-selector" ) ) . toBeInTheDocument ( )
222- expect ( screen . getByText ( "ls -la | grep test" ) ) . toBeInTheDocument ( )
224+ const selector = screen . getByTestId ( "command-pattern-selector" )
225+ expect ( selector ) . toBeInTheDocument ( )
226+ expect ( selector ) . toHaveTextContent ( "ls -la | grep test" )
223227 } )
224228
225229 it ( "should handle commands with && operator" , ( ) => {
@@ -229,8 +233,9 @@ Suggested patterns: npm, npm install, npm run`
229233 </ ExtensionStateWrapper > ,
230234 )
231235
232- expect ( screen . getByTestId ( "command-pattern-selector" ) ) . toBeInTheDocument ( )
233- expect ( screen . getByText ( "npm install && npm test" ) ) . toBeInTheDocument ( )
236+ const selector = screen . getByTestId ( "command-pattern-selector" )
237+ expect ( selector ) . toBeInTheDocument ( )
238+ expect ( selector ) . toHaveTextContent ( "npm install && npm test" )
234239 } )
235240
236241 it ( "should not show pattern selector for empty commands" , ( ) => {
@@ -316,7 +321,7 @@ Output here`
316321
317322 const selector = screen . getByTestId ( "command-pattern-selector" )
318323 expect ( selector ) . toBeInTheDocument ( )
319- expect ( screen . getByText ( "npm install && npm test || echo 'failed'" ) ) . toBeInTheDocument ( )
324+ expect ( selector ) . toHaveTextContent ( "npm install && npm test || echo 'failed'" )
320325 } )
321326
322327 it ( "should handle commands with output" , ( ) => {
@@ -338,8 +343,8 @@ Other output here`
338343
339344 const selector = screen . getByTestId ( "command-pattern-selector" )
340345 expect ( selector ) . toBeInTheDocument ( )
341- // Should show the command
342- expect ( screen . getByText ( "npm install" ) ) . toBeInTheDocument ( )
346+ // Should show the command in the selector
347+ expect ( selector ) . toHaveTextContent ( "npm install" )
343348 } )
344349
345350 it ( "should handle commands with subshells" , ( ) => {
@@ -351,7 +356,7 @@ Other output here`
351356
352357 const selector = screen . getByTestId ( "command-pattern-selector" )
353358 expect ( selector ) . toBeInTheDocument ( )
354- expect ( screen . getByText ( "echo $(whoami) && git status" ) ) . toBeInTheDocument ( )
359+ expect ( selector ) . toHaveTextContent ( "echo $(whoami) && git status" )
355360 } )
356361
357362 it ( "should handle commands with backtick subshells" , ( ) => {
@@ -363,7 +368,7 @@ Other output here`
363368
364369 const selector = screen . getByTestId ( "command-pattern-selector" )
365370 expect ( selector ) . toBeInTheDocument ( )
366- expect ( screen . getByText ( "git commit -m `date`" ) ) . toBeInTheDocument ( )
371+ expect ( selector ) . toHaveTextContent ( "git commit -m `date`" )
367372 } )
368373
369374 it ( "should handle commands with special characters" , ( ) => {
@@ -375,7 +380,7 @@ Other output here`
375380
376381 const selector = screen . getByTestId ( "command-pattern-selector" )
377382 expect ( selector ) . toBeInTheDocument ( )
378- expect ( screen . getByText ( "cd ~/projects && npm start" ) ) . toBeInTheDocument ( )
383+ expect ( selector ) . toHaveTextContent ( "cd ~/projects && npm start" )
379384 } )
380385
381386 it ( "should handle commands with mixed content including output" , ( ) => {
@@ -398,8 +403,8 @@ Running tests...
398403
399404 const selector = screen . getByTestId ( "command-pattern-selector" )
400405 expect ( selector ) . toBeInTheDocument ( )
401- // Should show the command
402- expect ( screen . getByText ( "npm test" ) ) . toBeInTheDocument ( )
406+ // Should show the command in the selector
407+ expect ( selector ) . toHaveTextContent ( "npm test" )
403408 } )
404409
405410 it ( "should update both allowed and denied lists when commands conflict" , ( ) => {
@@ -438,8 +443,9 @@ Running tests...
438443 expect ( screen . getByTestId ( "code-block" ) ) . toHaveTextContent ( "echo 'test with unclosed quote" )
439444
440445 // Should show pattern selector with the full command
441- expect ( screen . getByTestId ( "command-pattern-selector" ) ) . toBeInTheDocument ( )
442- expect ( screen . getByText ( "echo 'test with unclosed quote" ) ) . toBeInTheDocument ( )
446+ const selector = screen . getByTestId ( "command-pattern-selector" )
447+ expect ( selector ) . toBeInTheDocument ( )
448+ expect ( selector ) . toHaveTextContent ( "echo 'test with unclosed quote" )
443449 } )
444450
445451 it ( "should handle empty or whitespace-only commands" , ( ) => {
@@ -488,8 +494,9 @@ Without any command prefix`
488494 expect ( screen . getByTestId ( "code-block" ) ) . toHaveTextContent ( "docker build ." )
489495
490496 // Should show pattern selector with the full command
491- expect ( screen . getByTestId ( "command-pattern-selector" ) ) . toBeInTheDocument ( )
492- expect ( screen . getByText ( "docker build ." ) ) . toBeInTheDocument ( )
497+ const selector = screen . getByTestId ( "command-pattern-selector" )
498+ expect ( selector ) . toBeInTheDocument ( )
499+ expect ( selector ) . toHaveTextContent ( "docker build ." )
493500
494501 // Verify no output is shown (since there's no Output: separator)
495502 const codeBlocks = screen . getAllByTestId ( "code-block" )
@@ -518,8 +525,8 @@ Output:
518525 const selector = screen . getByTestId ( "command-pattern-selector" )
519526 expect ( selector ) . toBeInTheDocument ( )
520527
521- // Should show the full command
522- expect ( screen . getByText ( "wc -l *.go *.java" ) ) . toBeInTheDocument ( )
528+ // Should show the full command in the selector
529+ expect ( selector ) . toHaveTextContent ( "wc -l *.go *.java" )
523530
524531 // The output should still be displayed in the code block
525532 expect ( codeBlocks . length ) . toBeGreaterThan ( 1 )
@@ -541,8 +548,8 @@ Output:
541548 const selector = screen . getByTestId ( "command-pattern-selector" )
542549 expect ( selector ) . toBeInTheDocument ( )
543550
544- // Should show the full command
545- expect ( screen . getByText ( "wc -l *.go *.java" ) ) . toBeInTheDocument ( )
551+ // Should show the full command in the selector
552+ expect ( selector ) . toHaveTextContent ( "wc -l *.go *.java" )
546553
547554 // The output should still be displayed in the code block
548555 const codeBlocks = screen . getAllByTestId ( "code-block" )
0 commit comments