@@ -15,26 +15,49 @@ describe('GeneratedCommands', () => {
1515 mockOnCopy . mockClear ( ) ;
1616 } ) ;
1717
18- it ( 'renders both commands ' , ( ) => {
18+ it ( 'renders only curl command by default ' , ( ) => {
1919 render ( < GeneratedCommands commands = { mockCommands } /> ) ;
2020
21- // Use a more specific selector for the command headers
21+ expect ( screen . getByRole ( 'heading' , { name : / g e n e r a t e d .* c u r l .* c o m m a n d / i } ) ) . toBeInTheDocument ( ) ;
22+ expect ( screen . getByText ( mockCommands . curl ) ) . toBeInTheDocument ( ) ;
23+
24+ // doctl command should not be visible
25+ expect ( screen . queryByRole ( 'heading' , { name : / g e n e r a t e d .* d o c t l .* c o m m a n d / i } ) ) . not . toBeInTheDocument ( ) ;
26+ expect ( screen . queryByText ( mockCommands . doctl ) ) . not . toBeInTheDocument ( ) ;
27+ } ) ;
28+
29+ it ( 'renders both commands when showDoctlCommand is true' , ( ) => {
30+ render ( < GeneratedCommands commands = { mockCommands } showDoctlCommand = { true } /> ) ;
31+
2232 expect ( screen . getByRole ( 'heading' , { name : / g e n e r a t e d .* c u r l .* c o m m a n d / i } ) ) . toBeInTheDocument ( ) ;
2333 expect ( screen . getByRole ( 'heading' , { name : / g e n e r a t e d .* d o c t l .* c o m m a n d / i } ) ) . toBeInTheDocument ( ) ;
2434 expect ( screen . getByText ( mockCommands . curl ) ) . toBeInTheDocument ( ) ;
2535 expect ( screen . getByText ( mockCommands . doctl ) ) . toBeInTheDocument ( ) ;
2636 } ) ;
2737
28- it ( 'copies commands to clipboard when clicking copy button' , async ( ) => {
38+ it ( 'copies curl command to clipboard when clicking copy button' , async ( ) => {
2939 render ( < GeneratedCommands commands = { mockCommands } onCopy = { mockOnCopy } /> ) ;
3040
41+ const copyButton = screen . getByRole ( 'button' , { name : / c o p y / i } ) ;
42+
43+ // Test copying curl command
44+ await fireEvent . click ( copyButton ) ;
45+ expect ( navigator . clipboard . writeText ) . toHaveBeenCalledWith ( mockCommands . curl ) ;
46+ expect ( mockOnCopy ) . toHaveBeenCalled ( ) ;
47+ } ) ;
48+
49+ it ( 'copies both commands when showDoctlCommand is true' , async ( ) => {
50+ render ( < GeneratedCommands commands = { mockCommands } onCopy = { mockOnCopy } showDoctlCommand = { true } /> ) ;
51+
3152 const copyButtons = screen . getAllByRole ( 'button' , { name : / c o p y / i } ) ;
3253
3354 // Test copying curl command
3455 await fireEvent . click ( copyButtons [ 0 ] ) ;
3556 expect ( navigator . clipboard . writeText ) . toHaveBeenCalledWith ( mockCommands . curl ) ;
3657 expect ( mockOnCopy ) . toHaveBeenCalled ( ) ;
3758
59+ mockOnCopy . mockClear ( ) ;
60+
3861 // Test copying doctl command
3962 await fireEvent . click ( copyButtons [ 1 ] ) ;
4063 expect ( navigator . clipboard . writeText ) . toHaveBeenCalledWith ( mockCommands . doctl ) ;
@@ -44,8 +67,8 @@ describe('GeneratedCommands', () => {
4467 it ( 'shows "Copied!" text after copying' , async ( ) => {
4568 render ( < GeneratedCommands commands = { mockCommands } /> ) ;
4669
47- const copyButtons = screen . getAllByRole ( 'button' , { name : / c o p y / i } ) ;
48- await fireEvent . click ( copyButtons [ 0 ] ) ;
70+ const copyButton = screen . getByRole ( 'button' , { name : / c o p y / i } ) ;
71+ await fireEvent . click ( copyButton ) ;
4972
5073 // Wait for the "Copied!" text to appear
5174 await waitFor ( ( ) => {
0 commit comments