use actix_web::{http::StatusCode, test}; use sqlpage::{ AppState, webserver::{self, make_placeholder}, }; use sqlx::executor::Executor as _; use crate::common::{make_app_data_from_config, req_path, req_path_with_app_data, test_config}; #[actix_web::test] async fn test_concurrent_requests() { let components = [ "table", "form", "card", "datagrid", "hero", "list", "timeline", ]; let app_data = make_app_data_from_config(test_config()).await; let reqs = (0..64) .map(|i| { let component = components[i % components.len()]; req_path_with_app_data( format!("/tests/components/any_component.sql?component={component}"), app_data.clone(), ) }) .collect::>(); let results = futures_util::future::join_all(reqs).await; for result in results { let resp = result.unwrap(); assert_eq!(resp.status(), StatusCode::OK); let body = test::read_body(resp).await; assert!( body.starts_with(b""), "Expected html doctype" ); let body = String::from_utf8(body.to_vec()).unwrap(); assert!( body.contains("It works !"), "Expected to contain: It works !, but got: {body}" ); assert!(!body.contains("error")); } } #[actix_web::test] async fn test_datagrid_description_presence_controls_placeholder() { let resp = req_path("/tests/components/datagrid_icon_only.sql") .await .unwrap(); assert_eq!(resp.status(), StatusCode::OK); let body = String::from_utf8(test::read_body(resp).await.to_vec()).unwrap(); assert!(body.contains("Facebook"), "{body}"); assert!(body.contains("Empty"), "{body}"); assert!(body.contains("Missing"), "{body}"); assert!(body.contains("