@@ -15,26 +15,49 @@ describe('GeneratedCommands', () => {
15
15
mockOnCopy . mockClear ( ) ;
16
16
} ) ;
17
17
18
- it ( 'renders both commands ' , ( ) => {
18
+ it ( 'renders only curl command by default ' , ( ) => {
19
19
render ( < GeneratedCommands commands = { mockCommands } /> ) ;
20
20
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
+
22
32
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 ( ) ;
23
33
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 ( ) ;
24
34
expect ( screen . getByText ( mockCommands . curl ) ) . toBeInTheDocument ( ) ;
25
35
expect ( screen . getByText ( mockCommands . doctl ) ) . toBeInTheDocument ( ) ;
26
36
} ) ;
27
37
28
- it ( 'copies commands to clipboard when clicking copy button' , async ( ) => {
38
+ it ( 'copies curl command to clipboard when clicking copy button' , async ( ) => {
29
39
render ( < GeneratedCommands commands = { mockCommands } onCopy = { mockOnCopy } /> ) ;
30
40
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
+
31
52
const copyButtons = screen . getAllByRole ( 'button' , { name : / c o p y / i } ) ;
32
53
33
54
// Test copying curl command
34
55
await fireEvent . click ( copyButtons [ 0 ] ) ;
35
56
expect ( navigator . clipboard . writeText ) . toHaveBeenCalledWith ( mockCommands . curl ) ;
36
57
expect ( mockOnCopy ) . toHaveBeenCalled ( ) ;
37
58
59
+ mockOnCopy . mockClear ( ) ;
60
+
38
61
// Test copying doctl command
39
62
await fireEvent . click ( copyButtons [ 1 ] ) ;
40
63
expect ( navigator . clipboard . writeText ) . toHaveBeenCalledWith ( mockCommands . doctl ) ;
@@ -44,8 +67,8 @@ describe('GeneratedCommands', () => {
44
67
it ( 'shows "Copied!" text after copying' , async ( ) => {
45
68
render ( < GeneratedCommands commands = { mockCommands } /> ) ;
46
69
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 ) ;
49
72
50
73
// Wait for the "Copied!" text to appear
51
74
await waitFor ( ( ) => {
0 commit comments