@@ -3,7 +3,6 @@ const origin = "http://localhost:3011/web-component.html";
33beforeEach ( ( ) => {
44 cy . intercept ( "*" , ( req ) => {
55 req . headers [ "Origin" ] = origin ;
6- req . continue ( ) ;
76 } ) ;
87} ) ;
98
@@ -13,12 +12,22 @@ const runCode = (code) => {
1312 . shadow ( )
1413 . find ( "div[class=cm-content]" )
1514 . 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 ( ) ;
1720} ;
1821
1922describe ( "Running the code with pyodide" , ( ) => {
2023 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+ } ) ;
2231 cy . window ( ) . then ( ( win ) => {
2332 Object . defineProperty ( win , "crossOriginIsolated" , {
2433 value : true ,
@@ -29,6 +38,16 @@ describe("Running the code with pyodide", () => {
2938
3039 it ( "runs a simple program" , ( ) => {
3140 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" ) ;
3251 cy . get ( "editor-wc" )
3352 . shadow ( )
3453 . find ( ".pythonrunner-console-output-line" )
@@ -39,21 +58,33 @@ describe("Running the code with pyodide", () => {
3958 runCode (
4059 "from time import sleep\nfor i in range(100):\n\tprint(i)\n\tsleep(1)" ,
4160 ) ;
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 ( ) ;
4370 cy . get ( "editor-wc" )
4471 . shadow ( )
4572 . find ( ".error-message__content" )
4673 . should ( "contain" , "Execution interrupted" ) ;
4774 } ) ;
4875
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" , ( ) => {
5177 runCode ( 'name = input("What is your name?")\nprint("Hello", name)' ) ;
78+ cy . get ( "editor-wc" ) . shadow ( ) . find ( ".btn--stop" ) . should ( "be.visible" ) ;
5279 cy . get ( "editor-wc" )
5380 . shadow ( )
5481 . find ( ".pythonrunner-console-output-line" )
5582 . 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}" ) ;
5788 cy . get ( "editor-wc" )
5889 . shadow ( )
5990 . find ( ".pythonrunner-console-output-line" )
@@ -133,6 +164,34 @@ describe("Running the code with pyodide", () => {
133164 . should ( "contain" , "4" ) ;
134165 } ) ;
135166
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+
136195 it ( "errors when importing a non-existent module" , ( ) => {
137196 runCode ( "import i_do_not_exist" ) ;
138197 cy . get ( "editor-wc" )
0 commit comments