fix(dashboard): enhance live activity formatting, add empty state placeholder, and add API unit tests
This commit is contained in:
1 parent
19f9c7ace7
commit
da3700d1d5
3 files changed
+164
-21
No files matched your search
@@ -713,6 +713,42 @@ mod tests {
|
||||
assert!(js_str.contains("refreshActiveTab"));
|
||||
assert!(js_str.contains("parseActivityPayload"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_activity_feed_and_empty_state() {
|
||||
let (_app, app_state, _dir) = setup_app().await;
|
||||
|
||||
// 1. Initial GET /api/activity should return empty array []
|
||||
let app_act = create_router(app_state.clone());
|
||||
let req_act = Request::builder().uri("/api/activity").body(Body::empty()).unwrap();
|
||||
let resp_act = app_act.oneshot(req_act).await.unwrap();
|
||||
assert_eq!(resp_act.status(), StatusCode::OK);
|
||||
let body_bytes = axum::body::to_bytes(resp_act.into_body(), usize::MAX).await.unwrap();
|
||||
let json_str = String::from_utf8(body_bytes.to_vec()).unwrap();
|
||||
assert_eq!(json_str.trim(), "[]");
|
||||
|
||||
// 2. Record an activity
|
||||
app_state.handler.state.record_activity("code_change", "Refactored live activity UI", Some("Added empty state placeholder"));
|
||||
|
||||
// 3. GET /api/activity should now return recorded item
|
||||
let app_act2 = create_router(app_state.clone());
|
||||
let req_act2 = Request::builder().uri("/api/activity").body(Body::empty()).unwrap();
|
||||
let resp_act2 = app_act2.oneshot(req_act2).await.unwrap();
|
||||
assert_eq!(resp_act2.status(), StatusCode::OK);
|
||||
let body_bytes2 = axum::body::to_bytes(resp_act2.into_body(), usize::MAX).await.unwrap();
|
||||
let json_str2 = String::from_utf8(body_bytes2.to_vec()).unwrap();
|
||||
assert!(json_str2.contains("CODE_CHANGE"));
|
||||
assert!(json_str2.contains("Refactored live activity UI"));
|
||||
|
||||
// 4. Verify /dashboard.js contains empty state text
|
||||
let app_js = create_router(app_state.clone());
|
||||
let req_js = Request::builder().uri("/dashboard.js").body(Body::empty()).unwrap();
|
||||
let resp_js = app_js.oneshot(req_js).await.unwrap();
|
||||
assert_eq!(resp_js.status(), StatusCode::OK);
|
||||
let js_bytes = axum::body::to_bytes(resp_js.into_body(), usize::MAX).await.unwrap();
|
||||
let js_str = String::from_utf8(js_bytes.to_vec()).unwrap();
|
||||
assert!(js_str.contains("No recent activity recorded yet."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user