@@ -1024,23 +1024,21 @@ async fn test_client_updates_core(
10241024 driver_ref : & WebDriver ,
10251025 test_dir : & Path ,
10261026) -> Result < ( ) , WebDriverError > {
1027- let ide_version = 0.0 ;
1028- let server_id = perform_loadfile (
1027+ let mut ide_version = 0.0 ;
1028+ let orig_text = indoc ! (
1029+ "
1030+ # Test updates in the client that modify the client after appending to a line.
1031+ def foo():
1032+ A comment
1033+ print()
1034+ "
1035+ )
1036+ . to_string ( ) ;
1037+ let mut server_id = perform_loadfile (
10291038 & codechat_server,
10301039 test_dir,
10311040 "test.py" ,
1032- Some ( (
1033- indoc ! (
1034- "
1035- # Test updates in the client that modify the client after appending to a line.
1036- def foo():
1037- A comment
1038- print()
1039- "
1040- )
1041- . to_string ( ) ,
1042- ide_version,
1043- ) ) ,
1041+ Some ( ( orig_text. clone ( ) , ide_version) ) ,
10441042 true ,
10451043 6.0 ,
10461044 )
@@ -1102,6 +1100,7 @@ async fn test_client_updates_core(
11021100 message: EditorMessageContents :: Result ( Ok ( ResultOkTypes :: Void ) )
11031101 }
11041102 ) ;
1103+ server_id += MESSAGE_ID_INCREMENT ;
11051104
11061105 goto_line ( & codechat_server, driver_ref, & mut client_id, & path_str, 4 )
11071106 . await
@@ -1142,6 +1141,72 @@ async fn test_client_updates_core(
11421141 }
11431142 ) ;
11441143 codechat_server. send_result ( client_id, None ) . await . unwrap ( ) ;
1144+ client_id += MESSAGE_ID_INCREMENT ;
1145+
1146+ // The Server sends the Client a re-translated version of the text with the new doc block; the Client
1147+ // replies with a Result(Ok).
1148+ assert_eq ! (
1149+ codechat_server. get_message_timeout( TIMEOUT ) . await . unwrap( ) ,
1150+ EditorMessage {
1151+ id: server_id,
1152+ message: EditorMessageContents :: Result ( Ok ( ResultOkTypes :: Void ) )
1153+ }
1154+ ) ;
1155+ //server_id += MESSAGE_ID_INCREMENT;
1156+
1157+ // Send the original text back, to ensure the re-translation correctly updated the Client.
1158+ ide_version = 1.0 ;
1159+ let ide_id = codechat_server
1160+ . send_message_update_plain (
1161+ path_str. clone ( ) ,
1162+ Some ( ( orig_text, ide_version) ) ,
1163+ Some ( 1 ) ,
1164+ None ,
1165+ )
1166+ . await
1167+ . unwrap ( ) ;
1168+ assert_eq ! (
1169+ codechat_server. get_message_timeout( TIMEOUT ) . await . unwrap( ) ,
1170+ EditorMessage {
1171+ id: ide_id,
1172+ message: EditorMessageContents :: Result ( Ok ( ResultOkTypes :: Void ) )
1173+ }
1174+ ) ;
1175+ sleep ( Duration :: from_secs ( 1000 ) ) . await ;
1176+
1177+ // Trigger a client edit to send the Client contents back.
1178+ let code_line = driver_ref. find ( By :: Css ( code_line_css) ) . await . unwrap ( ) ;
1179+ code_line. send_keys ( " " ) . await . unwrap ( ) ;
1180+
1181+ let msg = codechat_server. get_message_timeout ( TIMEOUT ) . await . unwrap ( ) ;
1182+ let new_client_version = get_version ( & msg) ;
1183+ assert_eq ! (
1184+ msg,
1185+ EditorMessage {
1186+ id: client_id,
1187+ message: EditorMessageContents :: Update ( UpdateMessageContents {
1188+ file_path: path_str. clone( ) ,
1189+ contents: Some ( CodeChatForWeb {
1190+ metadata: SourceFileMetadata {
1191+ mode: "python" . to_string( ) ,
1192+ } ,
1193+ source: CodeMirrorDiffable :: Diff ( CodeMirrorDiff {
1194+ doc: vec![ StringDiff {
1195+ from: 79 ,
1196+ to: Some ( 90 ) ,
1197+ insert: "def foo(): \n " . to_string( )
1198+ } ] ,
1199+ doc_blocks: vec![ ] ,
1200+ version: ide_version,
1201+ } ) ,
1202+ version: new_client_version,
1203+ } ) ,
1204+ cursor_position: Some ( 2 ) ,
1205+ scroll_position: Some ( 1.0 )
1206+ } )
1207+ }
1208+ ) ;
1209+ codechat_server. send_result ( client_id, None ) . await . unwrap ( ) ;
11451210
11461211 Ok ( ( ) )
11471212}
@@ -1236,6 +1301,7 @@ async fn test_4_core(
12361301
12371302make_test ! ( test_5, test_5_core) ;
12381303
1304+ // Verify that newlines in Mermaid and Graphviz diagrams aren't removed.
12391305async fn test_5_core (
12401306 codechat_server : CodeChatEditorServer ,
12411307 driver_ref : & WebDriver ,
@@ -1250,12 +1316,14 @@ async fn test_5_core(
12501316 #
12511317 # ```graphviz
12521318 # digraph g {
1253- # A -> B
1319+ # A -> B
12541320 # }
12551321 # ```
12561322 #
1257- # Test.
1258- test()
1323+ # ```mermaid
1324+ # graph TD
1325+ # A --> B
1326+ # ```
12591327 "
12601328 )
12611329 . to_string ( ) ;
@@ -1410,5 +1478,16 @@ async fn test_5_core(
14101478 codechat_server. send_result ( client_id, None ) . await . unwrap ( ) ;
14111479 //client_id += MESSAGE_ID_INCREMENT;
14121480
1481+ // The Server sends the Client a wrapped version of the text; the Client
1482+ // replies with a Result(Ok).
1483+ assert_eq ! (
1484+ codechat_server. get_message_timeout( TIMEOUT ) . await . unwrap( ) ,
1485+ EditorMessage {
1486+ id: server_id,
1487+ message: EditorMessageContents :: Result ( Ok ( ResultOkTypes :: Void ) )
1488+ }
1489+ ) ;
1490+ //server_id += MESSAGE_ID_INCREMENT;
1491+
14131492 Ok ( ( ) )
14141493}
0 commit comments