Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 8 additions & 77 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,10 @@ fn template_env() -> &'static Environment<'static> {
})
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "type")]
enum ClientMessage {
Ping,
RequestRefresh,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(tag = "type")]
enum ServerMessage {
Reload,
Pong,
}

use std::collections::HashMap;
Expand Down Expand Up @@ -682,13 +674,7 @@ async fn handle_websocket(socket: WebSocket, state: SharedMarkdownState) {
let recv_task = tokio::spawn(async move {
while let Some(msg) = receiver.next().await {
match msg {
Ok(Message::Text(text)) => {
if let Ok(client_msg) = serde_json::from_str::<ClientMessage>(&text) {
match client_msg {
ClientMessage::Ping | ClientMessage::RequestRefresh => {}
}
}
}
Ok(Message::Text(_)) => {}
Ok(Message::Close(_)) => break,
_ => {}
}
Expand Down Expand Up @@ -1017,18 +1003,7 @@ mod tests {
)
.await;

match update_result {
Ok(update_message) => {
if let ServerMessage::Reload = update_message {
// Success
} else {
panic!("Expected Reload message after file modification");
}
}
Err(_) => {
panic!("Timeout waiting for WebSocket update after file modification");
}
}
update_result.expect("Timeout waiting for WebSocket update after file modification");
}

#[tokio::test]
Expand Down Expand Up @@ -1459,18 +1434,7 @@ classDiagram
)
.await;

match update_result {
Ok(update_message) => {
if let ServerMessage::Reload = update_message {
// Success
} else {
panic!("Expected Reload message after file modification");
}
}
Err(_) => {
panic!("Timeout waiting for WebSocket update after file modification");
}
}
update_result.expect("Timeout waiting for WebSocket update after file modification");
}

#[tokio::test]
Expand All @@ -1490,18 +1454,7 @@ classDiagram
)
.await;

match update_result {
Ok(update_message) => {
if let ServerMessage::Reload = update_message {
// Success
} else {
panic!("Expected Reload message after new file creation");
}
}
Err(_) => {
panic!("Timeout waiting for WebSocket update after new file creation");
}
}
update_result.expect("Timeout waiting for WebSocket update after new file creation");

let response = server.get("/test1.md").await;
assert_eq!(response.status_code(), 200);
Expand Down Expand Up @@ -1701,18 +1654,7 @@ classDiagram
)
.await;

match update_result {
Ok(update_message) => {
if let ServerMessage::Reload = update_message {
// Success
} else {
panic!("Expected Reload message after temp file rename");
}
}
Err(_) => {
panic!("Timeout waiting for WebSocket update after temp file rename");
}
}
update_result.expect("Timeout waiting for WebSocket update after temp file rename");

let final_response = server.get("/").await;
assert_eq!(final_response.status_code(), 200);
Expand Down Expand Up @@ -1761,20 +1703,9 @@ classDiagram
)
.await;

match update_result {
Ok(update_message) => {
if let ServerMessage::Reload = update_message {
// Success
} else {
panic!("Expected Reload message after temp file rename in directory mode");
}
}
Err(_) => {
panic!(
"Timeout waiting for WebSocket update after temp file rename in directory mode"
);
}
}
update_result.expect(
"Timeout waiting for WebSocket update after temp file rename in directory mode",
);

let final_response = server.get("/test1.md").await;
assert_eq!(final_response.status_code(), 200);
Expand Down
Loading