@@ -38,6 +38,22 @@ describe("default behaviour", () => {
38
38
. should ( "contain" , "Hello world" ) ;
39
39
} ) ;
40
40
41
+ it ( "interrupts the code when the stop button is clicked" , ( ) => {
42
+ cy . get ( "editor-wc" )
43
+ . shadow ( )
44
+ . find ( "div[class=cm-content]" )
45
+ . invoke (
46
+ "text" ,
47
+ "from time import sleep\nfor i in range(100):\n\tprint(i)\n\tsleep(1)" ,
48
+ ) ;
49
+ cy . get ( "editor-wc" ) . shadow ( ) . find ( ".btn--run" ) . click ( ) ;
50
+ cy . get ( "editor-wc" ) . shadow ( ) . find ( ".btn--stop" ) . click ( ) ;
51
+ cy . get ( "editor-wc" )
52
+ . shadow ( )
53
+ . find ( ".error-message__content" )
54
+ . should ( "contain" , "Execution interrupted" ) ;
55
+ } ) ;
56
+
41
57
it ( "runs p5 code" , ( ) => {
42
58
const code = `from p5 import *\n\ndef setup():\n size(400, 400) # width and height of screen\n\ndef draw():\n fill('cyan') # Set the fill color for the sky to cyan\n rect(0, 0, 400, 250) # Draw a rectangle for the sky with these values for x, y, width, height \n \nrun(frame_rate=2)\n` ;
43
59
cy . get ( "editor-wc" )
@@ -61,7 +77,10 @@ describe("default behaviour", () => {
61
77
. find ( "div[class=cm-content]" )
62
78
. invoke ( "text" , "import sense_hat" ) ;
63
79
cy . get ( "editor-wc" ) . shadow ( ) . find ( ".btn--run" ) . click ( ) ;
64
- cy . get ( "editor-wc" ) . shadow ( ) . find ( "#root" ) . should ( "contain" , "Visual output" ) ;
80
+ cy . get ( "editor-wc" )
81
+ . shadow ( )
82
+ . find ( "#root" )
83
+ . should ( "contain" , "Visual output" ) ;
65
84
} ) ;
66
85
67
86
it ( "does not render astro pi component on page load" , ( ) => {
@@ -84,7 +103,10 @@ describe("default behaviour", () => {
84
103
. find ( "div[class=cm-content]" )
85
104
. invoke ( "text" , "import sense_hat" ) ;
86
105
cy . get ( "editor-wc" ) . shadow ( ) . find ( ".btn--run" ) . click ( ) ;
87
- cy . get ( "editor-wc" ) . shadow ( ) . find ( "div[class=cm-content]" ) . invoke ( "text" , "" ) ;
106
+ cy . get ( "editor-wc" )
107
+ . shadow ( )
108
+ . find ( "div[class=cm-content]" )
109
+ . invoke ( "text" , "" ) ;
88
110
cy . get ( "editor-wc" ) . shadow ( ) . find ( ".btn--run" ) . click ( ) ;
89
111
cy . get ( "editor-wc" ) . shadow ( ) . contains ( "Visual output" ) . click ( ) ;
90
112
cy . get ( "editor-wc" ) . shadow ( ) . find ( "#root" ) . should ( "not.contain" , "yaw" ) ;
@@ -106,7 +128,7 @@ describe("when load_remix_disabled is true, e.g. in editor-standalone", () => {
106
128
} ;
107
129
108
130
beforeEach ( ( ) => {
109
- cy . on ( ' window:before:load' , ( win ) => {
131
+ cy . on ( " window:before:load" , ( win ) => {
110
132
win . localStorage . setItem ( authKey , JSON . stringify ( user ) ) ;
111
133
} ) ;
112
134
} ) ;
@@ -124,22 +146,33 @@ describe("when load_remix_disabled is true, e.g. in editor-standalone", () => {
124
146
125
147
// Check receipt of an event to trigger a redirect to the remixed project URL
126
148
cy . get ( "#project-identifier" ) . should ( "not.have.text" , originalIdentifier ) ;
127
- cy . get ( "#project-identifier" ) . invoke ( "text" ) . then ( ( remixIdentifier ) => {
128
- // Check we're still seeing the changed code
129
- cy . get ( "editor-wc" ) . shadow ( ) . find ( "[contenteditable]" ) . should ( "have.text" , "# remixed!" ) ;
130
-
131
- // Visit the original project again
132
- cy . visit ( urlFor ( originalIdentifier ) ) ;
133
-
134
- // Check we no longer see the changed code, i.e. `load_remix_disabled=true` is respected
135
- cy . get ( "editor-wc" ) . shadow ( ) . find ( "[contenteditable]" ) . should ( "not.have.text" , "# remixed!" ) ;
136
-
137
- // View the remixed project
138
- cy . visit ( urlFor ( remixIdentifier ) ) ;
139
-
140
- // Check we're still seeing the changed code
141
- cy . get ( "editor-wc" ) . shadow ( ) . find ( "[contenteditable]" ) . should ( "have.text" , "# remixed!" ) ;
142
- } ) ;
149
+ cy . get ( "#project-identifier" )
150
+ . invoke ( "text" )
151
+ . then ( ( remixIdentifier ) => {
152
+ // Check we're still seeing the changed code
153
+ cy . get ( "editor-wc" )
154
+ . shadow ( )
155
+ . find ( "[contenteditable]" )
156
+ . should ( "have.text" , "# remixed!" ) ;
157
+
158
+ // Visit the original project again
159
+ cy . visit ( urlFor ( originalIdentifier ) ) ;
160
+
161
+ // Check we no longer see the changed code, i.e. `load_remix_disabled=true` is respected
162
+ cy . get ( "editor-wc" )
163
+ . shadow ( )
164
+ . find ( "[contenteditable]" )
165
+ . should ( "not.have.text" , "# remixed!" ) ;
166
+
167
+ // View the remixed project
168
+ cy . visit ( urlFor ( remixIdentifier ) ) ;
169
+
170
+ // Check we're still seeing the changed code
171
+ cy . get ( "editor-wc" )
172
+ . shadow ( )
173
+ . find ( "[contenteditable]" )
174
+ . should ( "have.text" , "# remixed!" ) ;
175
+ } ) ;
143
176
} ) ;
144
177
} ) ;
145
178
@@ -160,41 +193,73 @@ describe("when embedded, output_only & output_split_view are true", () => {
160
193
// Check text output panel is visible and has a run button
161
194
// Important to wait for this before making the negative assertions that follow
162
195
cy . get ( "editor-wc" ) . shadow ( ) . contains ( "Text output" ) . should ( "be.visible" ) ;
163
- cy . get ( "editor-wc" ) . shadow ( ) . find ( "button" ) . contains ( "Run" ) . should ( "be.visible" ) ;
196
+ cy . get ( "editor-wc" )
197
+ . shadow ( )
198
+ . find ( "button" )
199
+ . contains ( "Run" )
200
+ . should ( "be.visible" ) ;
164
201
165
202
// Check that the side bar is not displayed
166
203
cy . get ( "editor-wc" ) . shadow ( ) . contains ( "Project files" ) . should ( "not.exist" ) ;
167
204
// Check that the project bar is not displayed
168
- cy . get ( "editor-wc" ) . shadow ( ) . contains ( "Don't Collide: Clean Car" ) . should ( "not.exist" ) ;
205
+ cy . get ( "editor-wc" )
206
+ . shadow ( )
207
+ . contains ( "Don't Collide: Clean Car" )
208
+ . should ( "not.exist" ) ;
169
209
// Check that the editor input containing the code is not displayed
170
- cy . get ( "editor-wc" ) . shadow ( ) . contains ( "# The draw_obstacle function goes here" ) . should ( "not.exist" ) ;
210
+ cy . get ( "editor-wc" )
211
+ . shadow ( )
212
+ . contains ( "# The draw_obstacle function goes here" )
213
+ . should ( "not.exist" ) ;
171
214
172
215
// Run the code and check it executed without error
173
216
cy . get ( "editor-wc" ) . shadow ( ) . find ( "button" ) . contains ( "Run" ) . click ( ) ;
174
217
cy . get ( "#results" ) . should ( "contain" , '{"errorDetails":{}}' ) ;
175
218
176
219
// Check that the visual output panel is displayed in split view mode (vs tabbed view)
177
220
cy . get ( "editor-wc" ) . shadow ( ) . contains ( "Visual output" ) . should ( "be.visible" ) ;
178
- cy . get ( "editor-wc" ) . shadow ( ) . contains ( "Visual output" ) . parents ( "ul" ) . children ( ) . should ( "have.length" , 1 ) ;
221
+ cy . get ( "editor-wc" )
222
+ . shadow ( )
223
+ . contains ( "Visual output" )
224
+ . parents ( "ul" )
225
+ . children ( )
226
+ . should ( "have.length" , 1 ) ;
179
227
} ) ;
180
228
181
229
it ( "displays the embedded view for an HTML project" , ( ) => {
182
230
cy . visit ( urlFor ( "anime-expressions-solution" ) ) ;
183
231
184
232
// Check HTML preview output panel is visible and has a run button
185
233
// Important to wait for this before making the negative assertions that follow
186
- cy . get ( "editor-wc" ) . shadow ( ) . contains ( "index.html preview" ) . should ( "be.visible" ) ;
187
- cy . get ( "editor-wc" ) . shadow ( ) . find ( "button" ) . contains ( "Run" ) . should ( "be.visible" ) ;
234
+ cy . get ( "editor-wc" )
235
+ . shadow ( )
236
+ . contains ( "index.html preview" )
237
+ . should ( "be.visible" ) ;
238
+ cy . get ( "editor-wc" )
239
+ . shadow ( )
240
+ . find ( "button" )
241
+ . contains ( "Run" )
242
+ . should ( "be.visible" ) ;
188
243
189
244
// Check that the code has automatically run i.e. the HTML has been rendered
190
- cy . get ( "editor-wc" ) . shadow ( ) . find ( "iframe#output-frame" ) . its ( "0.contentDocument.body" ) . should ( "contain" , "Draw anime with me" ) ;
245
+ cy . get ( "editor-wc" )
246
+ . shadow ( )
247
+ . find ( "iframe#output-frame" )
248
+ . its ( "0.contentDocument.body" )
249
+ . should ( "contain" , "Draw anime with me" ) ;
191
250
192
251
// Check that the side bar is not displayed
193
252
cy . get ( "editor-wc" ) . shadow ( ) . contains ( "Project files" ) . should ( "not.exist" ) ;
194
253
// Check that the project bar is not displayed
195
- cy . get ( "editor-wc" ) . shadow ( ) . contains ( "Anime expressions solution" ) . should ( "not.exist" ) ;
254
+ cy . get ( "editor-wc" )
255
+ . shadow ( )
256
+ . contains ( "Anime expressions solution" )
257
+ . should ( "not.exist" ) ;
196
258
// Check that the editor input containing the code is not displayed
197
- cy . get ( "editor-wc" ) . shadow ( ) . contains ( "<h1>Draw anime with me</h1>" ) . should ( "not.exist" ) ;
259
+ cy . get ( "editor-wc" )
260
+ . shadow ( )
261
+ . contains ( "<h1>Draw anime with me</h1>" )
262
+ . should ( "not.exist" ) ;
198
263
199
264
// Run the code and check it executed without error
200
265
cy . get ( "editor-wc" ) . shadow ( ) . find ( "button" ) . contains ( "Run" ) . click ( ) ;
0 commit comments