@@ -3,7 +3,6 @@ const origin = "http://localhost:3011/web-component.html";
3
3
beforeEach ( ( ) => {
4
4
cy . intercept ( "*" , ( req ) => {
5
5
req . headers [ "Origin" ] = origin ;
6
- req . continue ( ) ;
7
6
} ) ;
8
7
} ) ;
9
8
@@ -13,12 +12,22 @@ const runCode = (code) => {
13
12
. shadow ( )
14
13
. find ( "div[class=cm-content]" )
15
14
. invoke ( "text" , `${ code } \n` ) ;
16
- cy . get ( "editor-wc" ) . shadow ( ) . find ( ".btn--run" ) . click ( ) ;
15
+ cy . get ( "editor-wc" )
16
+ . shadow ( )
17
+ . find ( ".btn--run" )
18
+ . should ( "not.be.disabled" )
19
+ . click ( ) ;
17
20
} ;
18
21
19
22
describe ( "Running the code with pyodide" , ( ) => {
20
23
beforeEach ( ( ) => {
21
- cy . visit ( origin ) ;
24
+ cy . visit ( {
25
+ url : origin ,
26
+ headers : {
27
+ "Cross-Origin-Opener-Policy" : "same-origin" ,
28
+ "Cross-Origin-Embedder-Policy" : "require-corp" ,
29
+ } ,
30
+ } ) ;
22
31
cy . window ( ) . then ( ( win ) => {
23
32
Object . defineProperty ( win , "crossOriginIsolated" , {
24
33
value : true ,
@@ -29,6 +38,16 @@ describe("Running the code with pyodide", () => {
29
38
30
39
it ( "runs a simple program" , ( ) => {
31
40
runCode ( 'print("Hello world")' ) ;
41
+ cy . get ( "editor-wc" )
42
+ . shadow ( )
43
+ . find ( ".pyodiderunner" )
44
+ . contains ( ".react-tabs__tab" , "Visual output" )
45
+ . should ( "not.exist" ) ;
46
+ cy . get ( "editor-wc" )
47
+ . shadow ( )
48
+ . find ( ".pyodiderunner" )
49
+ . find ( ".react-tabs__tab--selected" )
50
+ . should ( "contain" , "Text output" ) ;
32
51
cy . get ( "editor-wc" )
33
52
. shadow ( )
34
53
. find ( ".pythonrunner-console-output-line" )
@@ -39,21 +58,33 @@ describe("Running the code with pyodide", () => {
39
58
runCode (
40
59
"from time import sleep\nfor i in range(100):\n\tprint(i)\n\tsleep(1)" ,
41
60
) ;
42
- cy . get ( "editor-wc" ) . shadow ( ) . find ( ".btn--stop" ) . click ( ) ;
61
+ cy . get ( "editor-wc" )
62
+ . shadow ( )
63
+ . find ( ".pythonrunner-console-output-line" )
64
+ . should ( "contain" , "3" ) ;
65
+ cy . get ( "editor-wc" )
66
+ . shadow ( )
67
+ . find ( ".btn--stop" )
68
+ . should ( "be.visible" )
69
+ . click ( ) ;
43
70
cy . get ( "editor-wc" )
44
71
. shadow ( )
45
72
. find ( ".error-message__content" )
46
73
. should ( "contain" , "Execution interrupted" ) ;
47
74
} ) ;
48
75
49
- // skip this test for now until we get the headers set up
50
- it . skip ( "runs a simple program with an input" , ( ) => {
76
+ it ( "runs a simple program with an input" , ( ) => {
51
77
runCode ( 'name = input("What is your name?")\nprint("Hello", name)' ) ;
78
+ cy . get ( "editor-wc" ) . shadow ( ) . find ( ".btn--stop" ) . should ( "be.visible" ) ;
52
79
cy . get ( "editor-wc" )
53
80
. shadow ( )
54
81
. find ( ".pythonrunner-console-output-line" )
55
82
. should ( "contain" , "What is your name?" ) ;
56
- cy . get ( "editor-wc" ) . shadow ( ) . find ( "#input" ) . invoke ( "text" , "Lois{enter}" ) ;
83
+ cy . get ( "editor-wc" )
84
+ . shadow ( )
85
+ . find ( "#input" )
86
+ . should ( "be.visible" )
87
+ . type ( "Lois{enter}" ) ;
57
88
cy . get ( "editor-wc" )
58
89
. shadow ( )
59
90
. find ( ".pythonrunner-console-output-line" )
@@ -133,6 +164,34 @@ describe("Running the code with pyodide", () => {
133
164
. should ( "contain" , "4" ) ;
134
165
} ) ;
135
166
167
+ it ( "runs a simple program with the py-enigma library" , ( ) => {
168
+ runCode (
169
+ `
170
+ from enigma.machine import EnigmaMachine
171
+ # Sheet settings
172
+ ROTORS = "IV I V"
173
+ RINGS = "20 5 10"
174
+ PLUGBOARD = "KT AJ IV US NY HL GD XF PB CQ"
175
+ def use_enigma_machine(msg, rotor_start):
176
+ # Set up the Enigma machine
177
+ machine = EnigmaMachine.from_key_sheet(rotors=ROTORS, reflector="B", ring_settings=RINGS, plugboard_settings=PLUGBOARD)
178
+ # Set the initial position of the rotors
179
+ machine.set_display(rotor_start)
180
+ # Encrypt or decrypt the message
181
+ transformed_msg = machine.process_text(msg)
182
+ return(transformed_msg)
183
+ text_in = "This is a test message"
184
+ rotor_start = "FNZ"
185
+ text_out = use_enigma_machine(text_in, rotor_start)
186
+ print(text_out)
187
+ ` ,
188
+ ) ;
189
+ cy . get ( "editor-wc" )
190
+ . shadow ( )
191
+ . find ( ".pythonrunner-console-output-line" )
192
+ . should ( "contain" , "ULRYQJMVHLFQKBEFUGEOFL" ) ;
193
+ } ) ;
194
+
136
195
it ( "errors when importing a non-existent module" , ( ) => {
137
196
runCode ( "import i_do_not_exist" ) ;
138
197
cy . get ( "editor-wc" )
0 commit comments